moving unit tests from .testsuite -> .context

+ created example.scannable package to house scannable components away from .context.annotation package
+ example.scannable will also lend itself to sharing via externals
This commit is contained in:
Chris Beams
2008-12-14 06:32:25 +00:00
parent 57eaf42424
commit e944e2fcc5
48 changed files with 556 additions and 86 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import javax.annotation.PostConstruct;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.scannable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.stereotype.Component;
/**
* @author Juergen Hoeller
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
public @interface CustomStereotype {
String value() default "thoreau";
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.scannable;
/**
* @author Juergen Hoeller
*/
@CustomStereotype
public class DefaultNamedComponent {
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
/**
* @author Mark Fisher

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
/**
* @author Mark Fisher

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import java.util.List;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
/**
* @author Mark Fisher

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import org.springframework.stereotype.Component;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import org.springframework.stereotype.Repository;

View File

@@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import org.springframework.context.annotation.Scope;
/**
* @author Mark Fisher

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@@ -31,7 +31,7 @@ public class ServiceInvocationCounter {
private int useCount;
@Pointcut("execution(* org.springframework.context.annotation.FooService+.*(..))")
@Pointcut("execution(* example.scannable.FooService+.*(..))")
public void serviceExecution() {}
@Before("serviceExecution()")

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.context.annotation;
package example.scannable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

View File

@@ -16,12 +16,13 @@
package org.springframework.context.annotation;
import static org.junit.Assert.*;
import javax.annotation.Resource;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.annotation.Autowired;
@@ -34,12 +35,14 @@ import org.springframework.util.StopWatch;
/**
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.5
*/
public class AnnotationProcessorPerformanceTests extends TestCase {
public class AnnotationProcessorPerformanceTests {
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -65,6 +68,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -91,6 +95,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.
@@ -116,6 +121,7 @@ public class AnnotationProcessorPerformanceTests extends TestCase {
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
// Skip this test: Trace logging blows the time limit.

View File

@@ -1,69 +0,0 @@
package org.springframework.context.annotation;
import junit.framework.TestCase;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.test.AssertThrows;
/**
* Unit tests for the {@link AnnotationScopeMetadataResolver} class.
*
* @author Rick Evans
*/
public final class AnnotationScopeMetadataResolverTests extends TestCase {
private AnnotationScopeMetadataResolver scopeMetadataResolver;
@Override
protected void setUp() throws Exception {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
}
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName());
assertEquals(ScopedProxyMode.NO, scopeMetadata.getScopedProxyMode());
}
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
}
public void testCtorWithNullScopedProxyMode() {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
new AnnotationScopeMetadataResolver(null);
}
}.runTest();
}
public void testSetScopeAnnotationTypeWithNullType() {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
scopeMetadataResolver.setScopeAnnotationType(null);
}
}.runTest();
}
@Scope("singleton")
private static final class AnnotatedWithSingletonScope {
}
@Scope("prototype")
private static final class AnnotatedWithPrototypeScope {
}
}

View File

@@ -16,8 +16,10 @@
package org.springframework.context.annotation;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.aspectj.lang.annotation.Aspect;
import org.junit.Test;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException;
@@ -33,21 +35,28 @@ 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
* @author Chris Beams
*/
public class ClassPathBeanDefinitionScannerTests extends TestCase {
public class ClassPathBeanDefinitionScannerTests {
private static final String BASE_PACKAGE = "example.scannable";
private static final String BASE_PACKAGE =
ClassPathBeanDefinitionScannerTests.class.getPackage().getName();
@Test
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(13, beanCount);
assertEquals(10, beanCount);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -59,11 +68,12 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testDoubleScan() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(13, beanCount);
assertEquals(10, beanCount);
scanner.scan(BASE_PACKAGE);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
@@ -73,12 +83,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("thoreau"));
}
@Test
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(9, beanCount);
assertEquals(6, beanCount);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -86,6 +97,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
@Test
public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
@@ -95,6 +107,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
scanner.scan(BASE_PACKAGE);
}
@Test
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -111,14 +124,15 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(8, beanCount);
assertEquals(9, context.getBeanDefinitionCount());
assertEquals(5, beanCount);
assertEquals(6, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -126,6 +140,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
@Test
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
GenericApplicationContext context = new GenericApplicationContext();
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
@@ -134,8 +149,8 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(8, beanCount);
assertEquals(9, context.getBeanDefinitionCount());
assertEquals(5, beanCount);
assertEquals(6, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -143,6 +158,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean("myNamedDao"));
}
@Test
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -152,6 +168,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
scanner.scan(BASE_PACKAGE);
}
@Test
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -168,6 +185,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
@Test
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
@@ -180,6 +198,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
@@ -197,12 +216,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomIncludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(14, beanCount);
assertEquals(11, beanCount);
assertTrue(context.containsBean("messageBean"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
@@ -214,12 +234,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomAnnotationExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertEquals(9, beanCount);
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -230,12 +251,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomAssignableTypeExcludeFilterAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertEquals(9, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -246,13 +268,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.setIncludeAnnotationConfig(false);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(8, beanCount);
assertEquals(5, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -263,13 +286,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertFalse(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testMultipleCustomExcludeFiltersAndDefaults() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(11, beanCount);
assertEquals(8, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
@@ -280,12 +304,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testCustomBeanNameGenerator() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(13, beanCount);
assertEquals(10, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("fooService"));
assertTrue(context.containsBean("serviceInvocationCounter"));
@@ -297,35 +322,37 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@Test
public void testMultipleBasePackagesWithDefaultsOnly() {
GenericApplicationContext singlePackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
assertEquals(13, singlePackageBeanCount);
int multiPackageBeanCount = multiPackageScanner.scan(
BASE_PACKAGE, "org.springframework.dao.annotation");
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
assertEquals(10, singlePackageBeanCount);
multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
}
@Test
public void testMultipleScanCalls() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(13, beanCount);
assertEquals(10, beanCount);
assertEquals(beanCount, context.getBeanDefinitionCount());
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
}
@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(13, beanCount);
assertEquals(10, beanCount);
context.refresh();
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
@@ -347,13 +374,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertSame(context, fooService.genericContext);
}
@Test
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(9, beanCount);
assertEquals(6, beanCount);
context.refresh();
FooService fooService = (FooService) context.getBean("fooService");
assertFalse(fooService.isInitCalled());
@@ -365,6 +393,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
}
}
@Test
public void testAutowireCandidatePatternMatches() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
@@ -377,6 +406,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
assertEquals("bar", fooService.foo(123));
}
@Test
public void testAutowireCandidatePatternDoesNotMatch() {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);

View File

@@ -1,149 +0,0 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.annotation;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;
/**
* @author Mark Fisher
* @author Juergen Hoeller
*/
public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
private static final String TEST_BASE_PACKAGE =
ClassPathScanningCandidateComponentProviderTests.class.getPackage().getName();
public void testWithDefaults() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(9, 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));
}
public void testWithBogusBasePackage() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
assertEquals(0, candidates.size());
}
public void testWithPackageExcludeFilter() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*")));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(0, candidates.size());
}
public void testWithNoFilters() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(0, candidates.size());
}
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(6, 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));
}
@SuppressWarnings("unchecked")
public void testWithAspectAnnotationOnly() throws Exception {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(
ClassUtils.forName("org.aspectj.lang.annotation.Aspect")));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
}
public void testWithInterfaceType() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, StubFooDao.class));
}
public void testWithClassType() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, MessageBean.class));
}
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(9, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
}
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(8, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
}
private boolean containsBeanClass(Set<BeanDefinition> candidates, Class beanClass) {
for (Iterator it = candidates.iterator(); it.hasNext();) {
ScannedGenericBeanDefinition definition = (ScannedGenericBeanDefinition) it.next();
if (beanClass.getName().equals(definition.getBeanClassName())) {
return true;
}
}
return false;
}
}

View File

@@ -23,6 +23,9 @@ import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.config.SimpleMapScope;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import example.scannable.FooService;
import example.scannable.ScopedProxyTestBean;
/**
* @author Mark Fisher
* @author Juergen Hoeller

View File

@@ -30,6 +30,8 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import example.scannable.AutowiredQualifierFooService;
/**
* @author Mark Fisher
* @author Juergen Hoeller

View File

@@ -18,6 +18,9 @@ package org.springframework.context.annotation;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import example.scannable.FooService;
import example.scannable.ServiceInvocationCounter;
/**
* @author Mark Fisher
*/

View File

@@ -18,6 +18,9 @@ package org.springframework.context.annotation;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import example.scannable.FooService;
import example.scannable.ServiceInvocationCounter;
/**
* @author Mark Fisher
* @author Juergen Hoeller

View File

@@ -1,261 +0,0 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.util.ObjectUtils;
/**
* <p>
* JUnit-3.8-based unit test which verifies expected <em>init</em> and
* <em>destroy</em> bean lifecycle behavior as requested in <a
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3775"
* target="_blank">SPR-3775</a>.
* </p>
* <p>
* Specifically, combinations of the following are tested:
* </p>
* <ul>
* <li>{@link InitializingBean} &amp; {@link DisposableBean} interfaces</li>
* <li>Custom {@link RootBeanDefinition#getInitMethodName() init} &amp;
* {@link RootBeanDefinition#getDestroyMethodName() destroy} methods</li>
* <li>JSR 250's {@link javax.annotation.PostConstruct @PostConstruct} &amp;
* {@link javax.annotation.PreDestroy @PreDestroy} annotations</li>
* </ul>
*
* @author Sam Brannen
* @since 2.5
*/
public class Spr3775InitDestroyLifecycleTests extends TestCase {
private static final Log logger = LogFactory.getLog(Spr3775InitDestroyLifecycleTests.class);
/** LIFECYCLE_TEST_BEAN. */
private static final String LIFECYCLE_TEST_BEAN = "lifecycleTestBean";
private void debugMethods(Class<?> clazz, String category, List<String> methodNames) {
if (logger.isDebugEnabled()) {
logger.debug(clazz.getSimpleName() + ": " + category + ": " + methodNames);
}
}
private void assertMethodOrdering(Class<?> clazz, String category, List<String> expectedMethods,
List<String> actualMethods) {
debugMethods(clazz, category, actualMethods);
assertTrue("Verifying " + category + ": expected<" + expectedMethods + "> but got<" + actualMethods + ">.",
ObjectUtils.nullSafeEquals(expectedMethods, actualMethods));
}
private DefaultListableBeanFactory createBeanFactoryAndRegisterBean(final Class<?> beanClass,
final String initMethodName, final String destroyMethodName) {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanClass);
beanDefinition.setInitMethodName(initMethodName);
beanDefinition.setDestroyMethodName(destroyMethodName);
beanFactory.addBeanPostProcessor(new CommonAnnotationBeanPostProcessor());
beanFactory.registerBeanDefinition(LIFECYCLE_TEST_BEAN, beanDefinition);
return beanFactory;
}
public void testInitDestroyMethods() {
final Class<?> beanClass = InitDestroyBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
"afterPropertiesSet", "destroy");
final InitDestroyBean bean = (InitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("afterPropertiesSet"), bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
}
public void testInitializingDisposableInterfaces() {
final Class<?> beanClass = CustomInitializingDisposableBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
"customDestroy");
final CustomInitializingDisposableBean bean = (CustomInitializingDisposableBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("afterPropertiesSet", "customInit"),
bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy", "customDestroy"),
bean.destroyMethods);
}
public void testInitializingDisposableInterfacesWithShadowedMethods() {
final Class<?> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
"afterPropertiesSet", "destroy");
final InitializingDisposableWithShadowedMethodsBean bean = (InitializingDisposableWithShadowedMethodsBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("InitializingBean.afterPropertiesSet"),
bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
}
public void testJsr250Annotations() {
final Class<?> beanClass = CustomAnnotatedInitDestroyBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
"customDestroy");
final CustomAnnotatedInitDestroyBean bean = (CustomAnnotatedInitDestroyBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("postConstruct", "afterPropertiesSet",
"customInit"), bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("preDestroy", "destroy", "customDestroy"),
bean.destroyMethods);
}
public void testJsr250AnnotationsWithShadowedMethods() {
final Class<?> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
"customDestroy");
final CustomAnnotatedInitDestroyWithShadowedMethodsBean bean = (CustomAnnotatedInitDestroyWithShadowedMethodsBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods",
Arrays.asList("@PostConstruct.afterPropertiesSet", "customInit"), bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("@PreDestroy.destroy", "customDestroy"),
bean.destroyMethods);
}
public void testAllLifecycleMechanismsAtOnce() {
final Class<?> beanClass = AllInOneBean.class;
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
"afterPropertiesSet", "destroy");
final AllInOneBean bean = (AllInOneBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
assertMethodOrdering(beanClass, "init-methods", Arrays.asList("afterPropertiesSet"), bean.initMethods);
beanFactory.destroySingletons();
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
}
public static class InitDestroyBean {
final List<String> initMethods = new ArrayList<String>();
final List<String> destroyMethods = new ArrayList<String>();
public void afterPropertiesSet() throws Exception {
this.initMethods.add("afterPropertiesSet");
}
public void destroy() throws Exception {
this.destroyMethods.add("destroy");
}
}
public static class InitializingDisposableWithShadowedMethodsBean extends InitDestroyBean implements
InitializingBean, DisposableBean {
@Override
public void afterPropertiesSet() throws Exception {
this.initMethods.add("InitializingBean.afterPropertiesSet");
}
@Override
public void destroy() throws Exception {
this.destroyMethods.add("DisposableBean.destroy");
}
}
public static class CustomInitDestroyBean {
final List<String> initMethods = new ArrayList<String>();
final List<String> destroyMethods = new ArrayList<String>();
public void customInit() throws Exception {
this.initMethods.add("customInit");
}
public void customDestroy() throws Exception {
this.destroyMethods.add("customDestroy");
}
}
public static class CustomInitializingDisposableBean extends CustomInitDestroyBean
implements InitializingBean, DisposableBean {
public void afterPropertiesSet() throws Exception {
this.initMethods.add("afterPropertiesSet");
}
public void destroy() throws Exception {
this.destroyMethods.add("destroy");
}
}
public static class CustomAnnotatedInitDestroyBean extends CustomInitializingDisposableBean {
@PostConstruct
public void postConstruct() throws Exception {
this.initMethods.add("postConstruct");
}
@PreDestroy
public void preDestroy() throws Exception {
this.destroyMethods.add("preDestroy");
}
}
public static class CustomAnnotatedInitDestroyWithShadowedMethodsBean extends CustomInitializingDisposableBean {
@PostConstruct
@Override
public void afterPropertiesSet() throws Exception {
this.initMethods.add("@PostConstruct.afterPropertiesSet");
}
@PreDestroy
@Override
public void destroy() throws Exception {
this.destroyMethods.add("@PreDestroy.destroy");
}
}
public static class AllInOneBean implements InitializingBean, DisposableBean {
final List<String> initMethods = new ArrayList<String>();
final List<String> destroyMethods = new ArrayList<String>();
@PostConstruct
public void afterPropertiesSet() throws Exception {
this.initMethods.add("afterPropertiesSet");
}
@PreDestroy
public void destroy() throws Exception {
this.destroyMethods.add("destroy");
}
}
}

View File

@@ -5,10 +5,10 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation" use-default-filters="false" annotation-config="false">
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.Stub*"/>
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
<context:exclude-filter type="aspectj" expression="org.springframework..Scoped*Test*" />
<context:component-scan base-package="example.scannable" use-default-filters="false" annotation-config="false">
<context:include-filter type="aspectj" expression="example.scannable.Stub*"/>
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
<context:exclude-filter type="aspectj" expression="example..Scoped*Test*" />
</context:component-scan>
</beans>

View File

@@ -7,8 +7,8 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean id="fooService" class="org.springframework.context.annotation.AutowiredQualifierFooService"/>
<bean id="fooService" class="example.scannable.AutowiredQualifierFooService"/>
<context:component-scan base-package="org.springframework.context.annotation"/>
<context:component-scan base-package="example.scannable"/>
</beans>

View File

@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
<context:component-scan base-package="example.scannable"
name-generator="org.springframework.context.annotation.TestBeanNameGenerator"/>
</beans>

View File

@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
<context:component-scan base-package="example.scannable"
scope-resolver="org.springframework.context.annotation.TestScopeMetadataResolver"/>
</beans>

View File

@@ -7,10 +7,10 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"/>
<context:component-scan base-package="example.scannable"/>
<!-- shouldn't cause a conflict -->
<context:component-scan base-package="org.springframework.context.annotation"/>
<context:component-scan base-package="example.scannable"/>
<aop:aspectj-autoproxy/>

View File

@@ -5,11 +5,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework."
resource-pattern="**/annotation/*.class"
<context:component-scan base-package="example."
resource-pattern="**/scannable/*.class"
use-default-filters="false"
annotation-config="false">
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
</context:component-scan>
</beans>

View File

@@ -9,7 +9,7 @@
resource-pattern="**/thispackagedoesnotexist/*.class"
use-default-filters="false"
annotation-config="false">
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
</context:component-scan>
</beans>

View File

@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
use-default-filters="false">
<context:include-filter type="assignable"
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
<context:component-scan base-package="example.scannable" use-default-filters="false">
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
</context:component-scan>
</beans>

View File

@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
use-default-filters="false" scoped-proxy="interfaces">
<context:include-filter type="assignable"
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
<context:component-scan base-package="example.scannable" use-default-filters="false" scoped-proxy="interfaces">
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
</context:component-scan>
</beans>

View File

@@ -5,10 +5,9 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
<context:component-scan base-package="example.scannable"
use-default-filters="false" scoped-proxy="no">
<context:include-filter type="assignable"
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
</context:component-scan>
</beans>

View File

@@ -5,10 +5,8 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"
use-default-filters="false" scoped-proxy="targetClass">
<context:include-filter type="assignable"
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
<context:component-scan base-package="example.scannable" use-default-filters="false" scoped-proxy="targetClass">
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
</context:component-scan>
</beans>

View File

@@ -11,10 +11,10 @@
<aop:aspectj-autoproxy/>
<bean class="org.springframework.context.annotation.FooServiceImpl"/>
<bean class="example.scannable.FooServiceImpl"/>
<bean class="org.springframework.context.annotation.ServiceInvocationCounter"/>
<bean class="example.scannable.ServiceInvocationCounter"/>
<bean class="org.springframework.context.annotation.StubFooDao"/>
<bean class="example.scannable.StubFooDao"/>
</beans>

View File

@@ -7,7 +7,7 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan base-package="org.springframework.context.annotation"/>
<context:component-scan base-package="example.scannable"/>
<aop:aspectj-autoproxy/>

View File

@@ -18,7 +18,8 @@ package org.springframework.context.annotation3;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.context.annotation.FooDao;
import example.scannable.FooDao;
/**
* @author Mark Fisher