List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getEnvironment
@Override
public ConfigurableEnvironment getEnvironment()
From source file:uk.ac.ebi.ep.sitemap.main.SiteMapMain.java
public static void main(String... args) throws Exception { //////////////comment here /////////////////////// // args = new String[4]; // //String dbConfig = "ep-mm-db-enzdev"; // //String dbConfig = "ep-mm-db-enzprel"; // String userHome = System.getProperty("user.home"); // String filename = "SiteMap"; // String testing = "true"; // /*w w w .j a va 2 s .co m*/ // // args[0] = "vezpdev"; // args[1] = userHome; // args[2] = filename; // args[3] = testing; //////////////uncomment for testing parameters only /////////////////////// if (args == null) { System.out.println("Please provide required parameters"); System.exit(0); } AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getEnvironment().setActiveProfiles(args[0]); context.scan("uk.ac.ebi.ep.data.dataconfig"); context.refresh(); UniprotEntryService service = context.getBean(UniprotEntryService.class); SiteMapGenerator siteMapGenerator = new EnzymePortalSiteMap(service); boolean testMode = Boolean.parseBoolean(args[3]); siteMapGenerator.generateSitemap(args[1], args[2], testMode); }
From source file:org.cloudfoundry.workers.stocks.integration.client.Main.java
public static void main(String args[]) throws Throwable { AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.getEnvironment().setActiveProfiles(isCloudFoundry() ? "cloud" : "local"); annotationConfigApplicationContext.scan(ClientConfiguration.class.getPackage().getName()); annotationConfigApplicationContext.refresh(); StockClientGateway clientGateway = annotationConfigApplicationContext.getBean(StockClientGateway.class); Logger log = Logger.getLogger(Main.class.getName()); String symbol = "VMW"; StockSymbolLookup lookup = clientGateway.lookup(symbol); log.info("client: retrieved stock information: " + ToStringBuilder.reflectionToString(lookup)); }
From source file:org.dawnsci.marketplace.MarketplaceApplication.java
public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); // convert the command line argument to properties CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource(args); ctx.getEnvironment().getPropertySources().addFirst(ps); ctx.register(ApplicationConfiguration.class); ctx.refresh();/* www .jav a 2s. c om*/ try { SpringApplication.run(MarketplaceApplication.class, args); } finally { ctx.close(); } }
From source file:com.bank.config.code.IntegrationTests.java
@Test public void transferTenDollars() throws InsufficientFundsException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.getEnvironment().setDefaultProfiles("dev"); ctx.register(TransferServiceConfig.class, StandaloneDataConfig.class, JndiDataConfig.class); ctx.refresh();//w ww. jav a 2s . co m TransferService transferService = ctx.getBean(TransferService.class); AccountRepository accountRepository = ctx.getBean(AccountRepository.class); assertThat(accountRepository.findById("A123").getBalance(), equalTo(100.00)); assertThat(accountRepository.findById("C456").getBalance(), equalTo(0.00)); transferService.transfer(10.00, "A123", "C456"); assertThat(accountRepository.findById("A123").getBalance(), equalTo(90.00)); assertThat(accountRepository.findById("C456").getBalance(), equalTo(10.00)); }
From source file:org.jbr.commons.container.java.JavaSpringContainer.java
/** * Constructs the application context used by this container. * //from w w w. j av a 2 s .co m * @return this container's new application context * @throws SpringContainerException */ @Override protected AbstractApplicationContext createApplicationContext() throws SpringContainerException { final Class<?> contextConfigClass = getContextConfigClass(); final String profile = System.getProperty(JVM_PARM_PROFILE, getDefaultProfile()); log.info("Configuring Java SpringContainer using registered class [" + contextConfigClass + "] under profile [" + profile + "]"); final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.getEnvironment().setActiveProfiles(profile); context.register(contextConfigClass); context.registerShutdownHook(); return context; }
From source file:st.malike.service.storm.LNSBolt.java
@Override public void prepare(Map stormConf, TopologyContext context) { try {/*from www. ja v a 2s . c o m*/ this.config = stormConf; // reinitialize Spring IoC-- a hack AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.getEnvironment().getPropertySources() .addFirst(new ResourcePropertySource("classpath:application.properties")); ctx.scan("st.malike"); ctx.refresh(); demographicSummaryService = ctx.getBean(DemographicSummaryService.class); demographicService = ctx.getBean(DemographicService.class); summaryElasticSearchService = ctx.getBean(SummaryElasticSearchService.class); liveNotificationService = ctx.getBean(LiveNotificationService.class); summaryCalculatorService = ctx.getBean(SummaryCalculatorService.class); } catch (IOException ex) { Logger.getLogger(LNSBolt.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.cisco.cta.taxii.adapter.settings.SettingsConfigurationTest.java
private ConfigurableApplicationContext context(PropertySource<?> source) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(SettingsConfiguration.class); ctx.getEnvironment().getPropertySources().addFirst(source); ctx.refresh();//from w ww .j a va 2 s. c om return ctx; }
From source file:net.ggtools.maven.DDLGeneratorMojo.java
AnnotationConfigApplicationContext createApplicationContext() { final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); final ConfigurableEnvironment environment = applicationContext.getEnvironment(); final MutablePropertySources propertySources = environment.getPropertySources(); final MapPropertySource propertySource = createPropertySource(); propertySources.addFirst(propertySource); applicationContext.register(SpringConfiguration.class); applicationContext.refresh();/* w ww. ja v a 2s . c om*/ return applicationContext; }
From source file:com.acme.ModuleConfigurationTest.java
@Test public void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); Properties properties = new Properties(); properties.put("prefix", "foo"); properties.put("suffix", "bar"); context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties)); context.register(TestConfiguration.class); context.refresh();// www . jav a 2 s. c o m MessageChannel input = context.getBean("input", MessageChannel.class); SubscribableChannel output = context.getBean("output", SubscribableChannel.class); final AtomicBoolean handled = new AtomicBoolean(); output.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { handled.set(true); assertEquals("foohellobar", message.getPayload()); } }); input.send(new GenericMessage<String>("hello")); assertTrue(handled.get()); }
From source file:com.avanza.astrix.integration.tests.GsRemotingTest.java
@Test public void routedServiceInvocationThrowServiceUnavailableWhenProxyIsContextIsClosed() throws Exception { AnnotationConfigApplicationContext pingServer = autoClosables.add(new AnnotationConfigApplicationContext()); pingServer.register(PingAppConfig.class); pingServer.getEnvironment().getPropertySources() .addFirst(new MapPropertySource("props", new HashMap<String, Object>() { {/*from w w w . jav a 2s .c o m*/ put("serviceRegistryUri", serviceRegistry.getServiceUri()); } })); pingServer.refresh(); AstrixContext context = autoClosables.add(new TestAstrixConfigurer().registerApiProvider(PingApi.class) .set(AstrixSettings.SERVICE_REGISTRY_URI, serviceRegistry.getServiceUri()) .set(AstrixSettings.BEAN_BIND_ATTEMPT_INTERVAL, 200).configure()); Ping ping = context.waitForBean(Ping.class, 10000); assertEquals("foo", ping.ping("foo")); context.destroy(); assertThrows(() -> ping.ping("foo"), ServiceUnavailableException.class); }