use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class JeeNamespaceHandlerTests method setUp.
@Before
public void setUp() throws Exception {
GenericApplicationContext ctx = new GenericApplicationContext();
new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(new ClassPathResource("jeeNamespaceHandlerTests.xml", getClass()));
ctx.refresh();
this.beanFactory = ctx.getBeanFactory();
this.beanFactory.getBeanNamesForType(ITestBean.class);
}
use of org.springframework.context.support.GenericApplicationContext in project camel by apache.
the class CamelSpringTestSupport method getRouteExcludingApplicationContext.
/**
* Create a parent context that initializes a
* {@link org.apache.camel.spi.PackageScanClassResolver} to exclude a set of given classes from
* being resolved. Typically this is used at test time to exclude certain routes,
* which might otherwise be just noisy, from being discovered and initialized.
* <p/>
* To use this filtering mechanism it is necessary to provide the
* {@link ApplicationContext} returned from here as the parent context to
* your test context e.g.
*
* <pre>
* protected AbstractXmlApplicationContext createApplicationContext() {
* return new ClassPathXmlApplicationContext(new String[] {"test-context.xml"}, getRouteExcludingApplicationContext());
* }
* </pre>
*
* This will, in turn, call the template methods <code>excludedRoutes</code>
* and <code>excludedRoute</code> to determine the classes to be excluded from scanning.
*
* @return ApplicationContext a parent {@link ApplicationContext} configured
* to exclude certain classes from package scanning
*/
protected ApplicationContext getRouteExcludingApplicationContext() {
GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
routeExcludingContext.refresh();
ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
List<Class<?>> excluded = Arrays.asList(excludeRoutes());
excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
return routeExcludingContext;
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough.
@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
ctx.registerBeanDefinition("test", rbd);
ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
TestBean spouse = (TestBean) ctx.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough.
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
ctx.registerBeanDefinition("test", rbd);
ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
TestBean spouse = (TestBean) ctx.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithResourcePropertiesIsFastEnough.
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
ctx.registerBeanDefinition("test", rbd);
ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
TestBean spouse = (TestBean) ctx.getBean("spouse");
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
Aggregations