List of usage examples for org.springframework.context.support GenericXmlApplicationContext getEnvironment
@Override
public ConfigurableEnvironment getEnvironment()
From source file:com.home.ln_spring.ch5.profile.ProfileXmlConfigExample.java
public static void main(String[] args) { GenericXmlApplicationContext context = new GenericXmlApplicationContext(); context.getEnvironment().setActiveProfiles("highschool"); context.load("classpath:profile/*-config.xml"); context.refresh();//from w w w. jav a 2s .c om FoodProviderService foodProviderService = context.getBean("foodProviderService", FoodProviderService.class); List<Food> lunchSet = foodProviderService.provideLunchSet(); for (Food food : lunchSet) { System.out.println("Food: " + food.getName()); } }
From source file:com.home.ln_spring.ch5.env.EnvironmentSample.java
public static void main(String[] args) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.refresh();//ww w. jav a2s . c om ConfigurableEnvironment env = ctx.getEnvironment(); MutablePropertySources propertySources = env.getPropertySources(); Map appMap = new HashMap(); appMap.put("user.home", "/home/vitaliy/NetBeansProjects/Ln_Spring"); propertySources.addFirst(new MapPropertySource("SPRING3_MAP", appMap)); System.out.println("user.home: " + System.getProperty("user.home")); System.out.println("JAVA_HOME: " + System.getProperty("JAVA_HOME")); System.out.println("user.home: " + env.getProperty("user.home")); System.out.println("JAVA_HOME: " + env.getProperty("JAVA_HOME")); }
From source file:org.bitcoinrt.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w ww. j ava2 s. c o m */ public static void main(final String... args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration Bitcoin-rt Sample! " + "\n " + "\n========================================================="); System.out.println("Which WebSocket Client would you like to use? <enter>: "); System.out.println("\t1. Use Sonatype's Async HTTP Client implementation"); System.out.println("\t2. Use Jetty's WebSocket client implementation"); System.out.println("\t3. Use a Dummy client"); System.out.println("\tq. Quit the application"); System.out.print("Enter you choice: "); final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); while (true) { final String input = scanner.nextLine(); if ("1".equals(input.trim())) { context.getEnvironment().setActiveProfiles("default"); break; } else if ("2".equals(input.trim())) { context.getEnvironment().setActiveProfiles("jetty"); break; } else if ("3".equals(input.trim())) { context.getEnvironment().setActiveProfiles("dummy"); break; } else if ("q".equals(input.trim())) { System.out.println("Exiting application...bye."); System.exit(0); } else { System.out.println("Invalid choice\n\n"); System.out.print("Enter you choice: "); } } context.load("classpath:META-INF/spring/integration/*-context.xml"); context.registerShutdownHook(); context.refresh(); final ConnectionBroker connectionBroker = context.getBean(ConnectionBroker.class); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n For statistical information press 'i + Enter'. " + "\n " + "\n In your browser open: " + "\n file:///.../src/main/webapp/index.html " + "\n========================================================="); } while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } else if ("i".equals(input.trim())) { LOGGER.info("\n=========================================================" + "\n " + "\n Number of connected clients: " + connectionBroker.connectedClients() + "\n " + "\n========================================================="); } } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } context.close(); System.exit(0); }
From source file:com.bitsofproof.supernode.main.Main.java
public static void main(String[] args) throws Exception { log.info("bitsofproof supernode (c) 2013 bits of proof zrt."); log.trace("Spring context setup"); if (args.length == 0) { System.err.println(//w w w. ja va 2 s . com "Usage: java com.bitsofproof.main.Main profile [profile...] -- [args...] [options...]"); return; } GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); List<String> a = new ArrayList<String>(); boolean profiles = true; for (String s : args) { if (s.equals("--")) { profiles = false; } else { if (profiles) { log.info("Loading profile: " + s); ctx.getEnvironment().addActiveProfile(s); } else { a.add(s); } } } ctx.load("classpath:context/server.xml"); ctx.load("classpath:context/*-profile.xml"); ctx.refresh(); ctx.getBean(App.class).start(a.toArray(new String[0])); }
From source file:com.richard.memorystore.udp.UDPServer.java
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableServerSocket(11111); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); context.load("classpath:udpServer.xml"); context.registerShutdownHook();/*w w w .j ava2s.co m*/ context.refresh(); return context; }
From source file:org.musa.tcpserver.Main.java
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableServerSocket(5678); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); context.load("classpath:META-INF/spring/integration/serverContext.xml"); context.registerShutdownHook();/*from w w w . j av a2 s. c om*/ context.refresh(); return context; }
From source file:com.richard.memorystore.tcp.TcpServer.java
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableServerSocket(5678); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); context.load("classpath:tcpClientServerDemo-context.xml"); context.registerShutdownHook();// ww w . j ava 2 s . c o m context.refresh(); return context; }
From source file:com.haythem.integration.Main.java
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableServerSocket(5678); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml"); context.registerShutdownHook();/*w w w. j a v a2 s .c o m*/ context.refresh(); return context; }
From source file:org.musa.tcpclients.Main.java
public static GenericXmlApplicationContext setupContext() { final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.print("Detect open server socket..."); int availableServerSocket = SocketUtils.findAvailableServerSocket(5683); final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); System.out.println("using port " + context.getEnvironment().getProperty("availableServerSocket")); context.load("classpath:META-INF/spring/integration/clientContext.xml"); //context.registerShutdownHook(); context.refresh();/*from w w w .j a v a2 s . co m*/ return context; }
From source file:com.tcp.client.Main.java
public static GenericXmlApplicationContext setupContext() throws InterruptedException, IOException { int availableServerSocket = 5682; final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); System.out.println("===== Player 2 ====="); while (true) { try {/*from w w w. j ava2 s . c o m*/ ServerSocket s = new ServerSocket(availableServerSocket); s.close(); System.out.println("Player 1 is unavailable.. trying again!!"); Thread.sleep(2000); } catch (IOException e) { System.out.println("Found player 1!!"); break; } } final Map<String, Object> sockets = new HashMap<String, Object>(); sockets.put("availableServerSocket", availableServerSocket); final MapPropertySource propertySource = new MapPropertySource("sockets", sockets); context.getEnvironment().getPropertySources().addLast(propertySource); context.load("classpath:META-INF/context.xml"); context.registerShutdownHook(); context.refresh(); return context; }