List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext setEnvironment
@Override public void setEnvironment(ConfigurableEnvironment environment)
From source file:piecework.client.LoadTester.java
public static final void main(String[] args) throws Exception { String profile = args.length > 0 ? args[0] : "workstation"; StandardEnvironment environment = new StandardEnvironment(); environment.setActiveProfiles(profile); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.setEnvironment(environment); ctx.register(ClientConfiguration.class); ctx.refresh();//from w ww. j a va 2 s. c om KeyManagerCabinet cabinet = ctx.getBean(KeyManagerCabinet.class); SecuritySettings securitySettings = ctx.getBean(SecuritySettings.class); LoadTester loadTester = new LoadTester(cabinet.getKeystore(), securitySettings); loadTester.retrieveAllTasks(); }
From source file:uk.ac.kcl.Main.java
public static void main(String[] args) { File folder = new File(args[0]); File[] listOfFiles = folder.listFiles(); assert listOfFiles != null; for (File listOfFile : listOfFiles) { if (listOfFile.isFile()) { if (listOfFile.getName().endsWith(".properties")) { System.out.println("Properties sile found:" + listOfFile.getName() + ". Attempting to launch application context"); Properties properties = new Properties(); InputStream input; try { input = new FileInputStream(listOfFile); properties.load(input); if (properties.getProperty("globalSocketTimeout") != null) { TcpHelper.setSocketTimeout( Integer.valueOf(properties.getProperty("globalSocketTimeout"))); }/*www . jav a 2 s . co m*/ Map<String, Object> map = new HashMap<>(); properties.forEach((k, v) -> { map.put(k.toString(), v); }); ConfigurableEnvironment environment = new StandardEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(new MapPropertySource(listOfFile.getName(), map)); @SuppressWarnings("resource") AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.registerShutdownHook(); ctx.setEnvironment(environment); String scheduling; try { scheduling = properties.getProperty("scheduler.useScheduling"); if (scheduling.equalsIgnoreCase("true")) { ctx.register(ScheduledJobLauncher.class); ctx.refresh(); } else if (scheduling.equalsIgnoreCase("false")) { ctx.register(SingleJobLauncher.class); ctx.refresh(); SingleJobLauncher launcher = ctx.getBean(SingleJobLauncher.class); launcher.launchJob(); } else if (scheduling.equalsIgnoreCase("slave")) { ctx.register(JobConfiguration.class); ctx.refresh(); } else { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (NullPointerException ex) { throw new RuntimeException( "useScheduling not configured. Must be true, false or slave"); } } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:io.gravitee.gateway.handlers.api.ApiContextHandlerFactory.java
AbstractApplicationContext createApplicationContext(Api api) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.setParent(gatewayApplicationContext); context.setClassLoader(new ReactorHandlerClassLoader(gatewayApplicationContext.getClassLoader())); context.setEnvironment((ConfigurableEnvironment) gatewayApplicationContext.getEnvironment()); PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setIgnoreUnresolvablePlaceholders(true); configurer.setEnvironment(gatewayApplicationContext.getEnvironment()); context.addBeanFactoryPostProcessor(configurer); context.getBeanFactory().registerSingleton("api", api); context.register(ApiHandlerConfiguration.class); context.setId("context-api-" + api.getName()); context.refresh();//from w ww . j av a 2 s .c o m return context; }