use of example.scannable.FooServiceImpl in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testSimpleScanWithDefaultFiltersAndPrimaryLazyBean.
@Test
public void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.scan(BASE_PACKAGE);
scanner.scan("org.springframework.context.annotation5");
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean("otherFooDao")).isTrue();
context.refresh();
assertThat(context.getBeanFactory().containsSingleton("otherFooDao")).isFalse();
assertThat(context.getBeanFactory().containsSingleton("fooServiceImpl")).isFalse();
FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
assertThat(context.getBeanFactory().containsSingleton("otherFooDao")).isTrue();
assertThat(fooService.foo(123)).isEqualTo("other");
assertThat(fooService.lookupFoo(123)).isEqualTo("other");
}
use of example.scannable.FooServiceImpl in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testSimpleScanWithDefaultFiltersAndPostProcessors.
@Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertThat(beanCount).isGreaterThanOrEqualTo(12);
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean("thoreau")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
context.refresh();
FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
assertThat(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent")).isTrue();
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
assertThat(context.isPrototype("thoreau")).isTrue();
}
use of example.scannable.FooServiceImpl in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testBeanAutowiredWithAnnotationConfigEnabled.
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertThat(beanCount).isGreaterThanOrEqualTo(12);
context.refresh();
FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
MessageSource ms = (MessageSource) context.getBean("messageSource");
assertThat(fooService.isInitCalled()).isTrue();
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
assertThat(fooService.beanFactory).isSameAs(context.getDefaultListableBeanFactory());
assertThat(fooService.listableBeanFactory.size()).isEqualTo(2);
assertThat(fooService.listableBeanFactory.get(0)).isSameAs(context.getDefaultListableBeanFactory());
assertThat(fooService.listableBeanFactory.get(1)).isSameAs(myBf);
assertThat(fooService.resourceLoader).isSameAs(context);
assertThat(fooService.resourcePatternResolver).isSameAs(context);
assertThat(fooService.eventPublisher).isSameAs(context);
assertThat(fooService.messageSource).isSameAs(ms);
assertThat(fooService.context).isSameAs(context);
assertThat(fooService.configurableContext.length).isEqualTo(1);
assertThat(fooService.configurableContext[0]).isSameAs(context);
assertThat(fooService.genericContext).isSameAs(context);
}
use of example.scannable.FooServiceImpl in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testAutowireCandidatePatternMatches.
@Test
public void testAutowireCandidatePatternMatches() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(true);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
scanner.setAutowireCandidatePatterns("*FooDao");
scanner.scan(BASE_PACKAGE);
context.refresh();
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
}
Aggregations