example.scannable.FooServiceImpl Java Examples

The following examples show how to use example.scannable.FooServiceImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 7 votes vote down vote up
@Test
public void testWithComponentAnnotationOnly() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example #2
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("thoreau"));
	assertTrue(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent"));
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertTrue(context.isPrototype("thoreau"));
}
 
Example #3
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testWithComponentAnnotationOnly() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(3, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example #4
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.scan(BASE_PACKAGE);
	scanner.scan("org.springframework.context.annotation5");
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("otherFooDao"));
	context.refresh();

	assertFalse(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertFalse(context.getBeanFactory().containsSingleton("fooServiceImpl"));
	FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertEquals("other", fooService.foo(123));
	assertEquals("other", fooService.lookupFoo(123));
}
 
Example #5
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("thoreau"));
	assertTrue(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent"));
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertTrue(context.isPrototype("thoreau"));
}
 
Example #6
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	int beanCount = scanner.scan(BASE_PACKAGE);
	assertEquals(12, beanCount);
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("thoreau"));
	assertTrue(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
	assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
	context.refresh();
	FooServiceImpl service = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent"));
	assertEquals("bar", service.foo(1));
	assertTrue(context.isPrototype("thoreau"));
}
 
Example #7
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.scan(BASE_PACKAGE);
	scanner.scan("org.springframework.context.annotation5");
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("otherFooDao"));
	context.refresh();
	assertFalse(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertFalse(context.getBeanFactory().containsSingleton("fooServiceImpl"));
	FooServiceImpl service = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertEquals("other", service.foo(1));
}
 
Example #8
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testSimpleScanWithDefaultFiltersAndPrimaryLazyBean() {
	GenericApplicationContext context = new GenericApplicationContext();
	ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
	scanner.scan(BASE_PACKAGE);
	scanner.scan("org.springframework.context.annotation5");
	assertTrue(context.containsBean("serviceInvocationCounter"));
	assertTrue(context.containsBean("fooServiceImpl"));
	assertTrue(context.containsBean("stubFooDao"));
	assertTrue(context.containsBean("myNamedComponent"));
	assertTrue(context.containsBean("myNamedDao"));
	assertTrue(context.containsBean("otherFooDao"));
	context.refresh();

	assertFalse(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertFalse(context.getBeanFactory().containsSingleton("fooServiceImpl"));
	FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
	assertTrue(context.getBeanFactory().containsSingleton("otherFooDao"));
	assertEquals("other", fooService.foo(123));
	assertEquals("other", fooService.lookupFoo(123));
}
 
Example #9
Source File: ClassPathBeanDefinitionScannerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}
 
Example #10
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithDefaults() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(6, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, StubFooDao.class));
	assertTrue(containsBeanClass(candidates, NamedStubDao.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
 
Example #11
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithComponentAnnotationOnly() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
	provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(2, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
	assertFalse(containsBeanClass(candidates, StubFooDao.class));
	assertFalse(containsBeanClass(candidates, NamedStubDao.class));
}
 
Example #12
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithMultipleMatchingFilters() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(6, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
}
 
Example #13
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testExcludeTakesPrecedence() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(6, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
 
Example #14
Source File: EnableAspectJAutoProxyTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Bean
public FooService fooServiceImpl(final ApplicationContext context) {
	return new FooServiceImpl() {
		@Override
		public String foo(int id) {
			assertNotNull(AopContext.currentProxy());
			return super.foo(id);
		}
		@Override
		protected FooDao fooDao() {
			return context.getBean(FooDao.class);
		}
	};
}
 
Example #15
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testWithMultipleMatchingFilters() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(7, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
}
 
Example #16
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testExcludeTakesPrecedence() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(5, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
 
Example #17
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testExclude(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, StubFooDao.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertEquals(4, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #18
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testCustomAssignableTypeIncludeFilter(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	provider.addIncludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	// Interfaces/Abstract class are filtered out automatically.
	assertTrue(containsBeanClass(candidates, AutowiredQualifierFooService.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, ScopedProxyTestBean.class));
	assertEquals(3, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #19
Source File: ClassPathScanningCandidateComponentProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void testDefault(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertTrue(containsBeanClass(candidates, DefaultNamedComponent.class));
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, StubFooDao.class));
	assertTrue(containsBeanClass(candidates, NamedStubDao.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertEquals(7, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #20
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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");
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
}
 
Example #21
Source File: ClassPathBeanDefinitionScannerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}
 
Example #22
Source File: EnableAspectJAutoProxyTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public FooService fooServiceImpl(final ApplicationContext context) {
	return new FooServiceImpl() {
		@Override
		public String foo(int id) {
			assertNotNull(AopContext.currentProxy());
			return super.foo(id);
		}
		@Override
		protected FooDao fooDao() {
			return context.getBean(FooDao.class);
		}
	};
}
 
Example #23
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testExcludeTakesPrecedence() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(6, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
 
Example #24
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithMultipleMatchingFilters() {
	ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
	provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
	provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertEquals(7, candidates.size());
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
}
 
Example #25
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testExclude(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, StubFooDao.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertEquals(4, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #26
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testCustomAssignableTypeIncludeFilter(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	provider.addIncludeFilter(new AssignableTypeFilter(FooService.class));
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	// Interfaces/Abstract class are filtered out automatically.
	assertTrue(containsBeanClass(candidates, AutowiredQualifierFooService.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, ScopedProxyTestBean.class));
	assertEquals(3, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #27
Source File: ClassPathScanningCandidateComponentProviderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void testDefault(ClassPathScanningCandidateComponentProvider provider,
		Class<? extends BeanDefinition> expectedBeanDefinitionType) {
	Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
	assertTrue(containsBeanClass(candidates, DefaultNamedComponent.class));
	assertTrue(containsBeanClass(candidates, NamedComponent.class));
	assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
	assertTrue(containsBeanClass(candidates, StubFooDao.class));
	assertTrue(containsBeanClass(candidates, NamedStubDao.class));
	assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
	assertTrue(containsBeanClass(candidates, BarComponent.class));
	assertEquals(7, candidates.size());
	assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
 
Example #28
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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");
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
}
 
Example #29
Source File: ClassPathBeanDefinitionScannerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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);
	assertEquals(12, beanCount);
	context.refresh();

	FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
	StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
	MessageSource ms = (MessageSource) context.getBean("messageSource");
	assertTrue(fooService.isInitCalled());
	assertEquals("bar", fooService.foo(123));
	assertEquals("bar", fooService.lookupFoo(123));
	assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
	assertEquals(2, fooService.listableBeanFactory.size());
	assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
	assertSame(myBf, fooService.listableBeanFactory.get(1));
	assertSame(context, fooService.resourceLoader);
	assertSame(context, fooService.resourcePatternResolver);
	assertSame(context, fooService.eventPublisher);
	assertSame(ms, fooService.messageSource);
	assertSame(context, fooService.context);
	assertEquals(1, fooService.configurableContext.length);
	assertSame(context, fooService.configurableContext[0]);
	assertSame(context, fooService.genericContext);
}