|
|
|
|
@@ -16,15 +16,10 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.context.annotation;
|
|
|
|
|
|
|
|
|
|
import example.scannable.CustomComponent;
|
|
|
|
|
import example.scannable.FooService;
|
|
|
|
|
import example.scannable.FooServiceImpl;
|
|
|
|
|
import example.scannable.NamedStubDao;
|
|
|
|
|
import example.scannable.StubFooDao;
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.springframework.beans.TestBean;
|
|
|
|
|
import org.springframework.beans.factory.BeanCreationException;
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
@@ -39,6 +34,12 @@ import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
|
|
|
import org.springframework.core.type.filter.AssignableTypeFilter;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import example.scannable.CustomComponent;
|
|
|
|
|
import example.scannable.FooService;
|
|
|
|
|
import example.scannable.FooServiceImpl;
|
|
|
|
|
import example.scannable.NamedStubDao;
|
|
|
|
|
import example.scannable.StubFooDao;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Mark Fisher
|
|
|
|
|
* @author Juergen Hoeller
|
|
|
|
|
@@ -54,7 +55,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("fooServiceImpl"));
|
|
|
|
|
assertTrue(context.containsBean("stubFooDao"));
|
|
|
|
|
@@ -71,7 +72,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("fooServiceImpl"));
|
|
|
|
|
@@ -189,7 +190,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
|
|
|
|
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(4, beanCount);
|
|
|
|
|
assertEquals(5, beanCount);
|
|
|
|
|
assertTrue(context.containsBean("messageBean"));
|
|
|
|
|
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
|
|
|
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
|
|
|
|
@@ -202,7 +203,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
|
|
|
|
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(4, beanCount);
|
|
|
|
|
assertEquals(5, beanCount);
|
|
|
|
|
assertTrue(context.containsBean("messageBean"));
|
|
|
|
|
assertFalse(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertFalse(context.containsBean("fooServiceImpl"));
|
|
|
|
|
@@ -220,7 +221,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
|
|
|
|
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
assertEquals(11, beanCount);
|
|
|
|
|
assertTrue(context.containsBean("messageBean"));
|
|
|
|
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("fooServiceImpl"));
|
|
|
|
|
@@ -238,7 +239,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
|
|
|
|
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(8, beanCount);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertFalse(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("fooServiceImpl"));
|
|
|
|
|
assertTrue(context.containsBean("stubFooDao"));
|
|
|
|
|
@@ -255,7 +256,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
|
|
|
|
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(8, beanCount);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertFalse(context.containsBean("fooServiceImpl"));
|
|
|
|
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("stubFooDao"));
|
|
|
|
|
@@ -291,7 +292,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
|
|
|
|
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(7, beanCount);
|
|
|
|
|
assertEquals(8, beanCount);
|
|
|
|
|
assertFalse(context.containsBean("fooServiceImpl"));
|
|
|
|
|
assertFalse(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
assertTrue(context.containsBean("stubFooDao"));
|
|
|
|
|
@@ -308,7 +309,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
|
|
|
|
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
assertFalse(context.containsBean("fooServiceImpl"));
|
|
|
|
|
assertTrue(context.containsBean("fooService"));
|
|
|
|
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
|
|
|
|
@@ -327,7 +328,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
|
|
|
|
|
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
|
|
|
|
|
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, singlePackageBeanCount);
|
|
|
|
|
assertEquals(10, singlePackageBeanCount);
|
|
|
|
|
multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
|
|
|
|
|
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
|
|
|
|
}
|
|
|
|
|
@@ -337,7 +338,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
GenericApplicationContext context = new GenericApplicationContext();
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
assertEquals(beanCount, context.getBeanDefinitionCount());
|
|
|
|
|
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
|
|
|
|
|
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
|
|
|
|
|
@@ -350,7 +351,7 @@ public class ClassPathBeanDefinitionScannerTests {
|
|
|
|
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
|
|
|
|
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
|
|
|
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
|
|
|
|
assertEquals(9, beanCount);
|
|
|
|
|
assertEquals(10, beanCount);
|
|
|
|
|
context.refresh();
|
|
|
|
|
|
|
|
|
|
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
|
|
|
|
|
|