List of usage examples for org.springframework.context.annotation AnnotationConfigApplicationContext getEnvironment
@Override
public ConfigurableEnvironment getEnvironment()
From source file:com.avanza.astrix.integration.tests.GsRemotingTest.java
@Test public void broadcastedServiceInvocationThrowServiceUnavailableWhenProxyIsContextIsClosed() 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 ww . ja v a2 s . 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.broadcastPing("foo").get(0)); context.destroy(); assertThrows(() -> ping.broadcastPing("foo"), ServiceUnavailableException.class); }
From source file:org.springsource.investigation.ReproTests.java
@SuppressWarnings("unchecked") @Test/* w w w . ja v a 2 s . c om*/ public void repro() { ConfigurableApplicationContext parent = new GenericApplicationContext(); parent.refresh(); AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.setParent(parent); child.refresh(); ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class); assertThat("UNKNOWN ENV", env, anyOf(sameInstance(parent.getEnvironment()), sameInstance(child.getEnvironment()))); assertThat("EXPECTED CHILD CTX ENV", env, sameInstance(child.getEnvironment())); }
From source file:com.azaptree.services.spring.application.config.SpringApplicationServiceConfig.java
public AnnotationConfigApplicationContext createAnnotationConfigApplicationContext() { final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); if (ArrayUtils.isNotEmpty(springProfiles)) { ctx.getEnvironment().setActiveProfiles(springProfiles); }/*from w w w . j a v a 2 s .co m*/ if (ArrayUtils.isNotEmpty(configurationClasses)) { for (final Class<?> c : configurationClasses) { ctx.register(c); } } ctx.refresh(); ctx.registerShutdownHook(); return ctx; }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void withMultipleResourceLocations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( ConfigWithMultipleResourceLocations.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p3"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p3TestBean")); ctx.close();/*from www. j av a 2 s . c o m*/ }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void withNameAndMultipleResourceLocations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( ConfigWithNameAndMultipleResourceLocations.class); assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true)); assertThat(ctx.getEnvironment().containsProperty("from.p3"), is(true)); // p2 should 'win' as it was registered last assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p3TestBean")); ctx.close();/*from w w w .j av a 2 s . co m*/ }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void orderingWithAndWithoutNameAndMultipleResourceLocations() { // SPR-10820: p2 should 'win' as it was registered last AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext( ConfigWithNameAndMultipleResourceLocations.class); AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext( ConfigWithMultipleResourceLocations.class); assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p3TestBean")); assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p3TestBean")); ctxWithName.close();/*from w ww . j av a 2 s. co m*/ ctxWithoutName.close(); }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void withImplicitName() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithImplicitName.class); ctx.refresh();//from www .j a va 2 s.c om assertTrue("property source p1 was not added", ctx.getEnvironment().getPropertySources() .contains("class path resource [org/jasypt/spring31/annotation/basic-encrypted-p1.properties]")); assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean")); ctx.close(); }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void withExplicitName() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithExplicitName.class); ctx.refresh();/*w w w . j a va 2 s .c o m*/ assertTrue("property source p1 was not added", ctx.getEnvironment().getPropertySources().contains("p1")); assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean")); // assert that the property source was added last to the set of sources String name; MutablePropertySources sources = ctx.getEnvironment().getPropertySources(); Iterator<org.springframework.core.env.PropertySource<?>> iterator = sources.iterator(); do { name = iterator.next().getName(); } while (iterator.hasNext()); assertThat(name, is("p1")); ctx.close(); }