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:
parent
57eaf42424
commit
e944e2fcc5
|
@ -12,6 +12,8 @@
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-1.1.0.jar" sourcepath="/IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-sources-1.1.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-1.1.0.jar" sourcepath="/IVY_CACHE/org.jruby/com.springsource.org.jruby/1.1.0/com.springsource.org.jruby-sources-1.1.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-1.5.1.jar" sourcepath="/IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-sources-1.5.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-1.5.1.jar" sourcepath="/IVY_CACHE/org.codehaus.groovy/com.springsource.org.codehaus.groovy/1.5.1/com.springsource.org.codehaus.groovy-sources-1.5.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/org.beanshell/com.springsource.bsh/2.0.0.b4/com.springsource.bsh-2.0.0.b4.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/org.beanshell/com.springsource.bsh/2.0.0.b4/com.springsource.bsh-2.0.0.b4.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm/2.2.3/com.springsource.org.objectweb.asm-2.2.3.jar" sourcepath="/IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm/2.2.3/com.springsource.org.objectweb.asm-sources-2.2.3.jar"/>
|
||||||
|
<classpathentry kind="var" path="IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-2.2.3.jar" sourcepath="/IVY_CACHE/org.objectweb.asm/com.springsource.org.objectweb.asm.commons/2.2.3/com.springsource.org.objectweb.asm.commons-sources-2.2.3.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/com.sun.enterprise/com.springsource.com.sun.enterprise.loader/1.0.0/com.springsource.com.sun.enterprise.loader-1.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/com.sun.enterprise/com.springsource.com.sun.enterprise.loader/1.0.0/com.springsource.com.sun.enterprise.loader-1.0.0.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/com.oracle.oc4j/com.springsource.oracle.classloader/10.1.3.1/com.springsource.oracle.classloader-10.1.3.1.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/com.oracle.oc4j/com.springsource.oracle.classloader/10.1.3.1/com.springsource.oracle.classloader-10.1.3.1.jar"/>
|
||||||
<classpathentry kind="var" path="IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-3.0.0.jar" sourcepath="/IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-sources-3.0.0.jar"/>
|
<classpathentry kind="var" path="IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-3.0.0.jar" sourcepath="/IVY_CACHE/javax.ejb/com.springsource.javax.ejb/3.0.0/com.springsource.javax.ejb-sources-3.0.0.jar"/>
|
||||||
|
|
|
@ -54,6 +54,8 @@
|
||||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/>
|
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="test->runtime"/>
|
||||||
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="test->runtime"/>
|
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="test->runtime"/>
|
||||||
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
|
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
|
||||||
|
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="test->runtime"/>
|
||||||
|
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="test->runtime"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</ivy-module>
|
</ivy-module>
|
||||||
|
|
|
@ -1,27 +1,31 @@
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||||
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.test.AssertThrows;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the {@link AnnotationScopeMetadataResolver} class.
|
* Unit tests for the {@link AnnotationScopeMetadataResolver} class.
|
||||||
*
|
*
|
||||||
* @author Rick Evans
|
* @author Rick Evans
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
public final class AnnotationScopeMetadataResolverTests {
|
||||||
|
|
||||||
private AnnotationScopeMetadataResolver scopeMetadataResolver;
|
private AnnotationScopeMetadataResolver scopeMetadataResolver;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
|
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
|
public void testThatResolveScopeMetadataDoesNotApplyScopedProxyModeToASingleton() {
|
||||||
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
|
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
|
||||||
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
|
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
|
||||||
|
@ -31,6 +35,7 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
|
public void testThatResolveScopeMetadataDoesApplyScopedProxyModeToAPrototype() {
|
||||||
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
|
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(ScopedProxyMode.INTERFACES);
|
||||||
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
|
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
|
||||||
|
@ -40,21 +45,15 @@ public final class AnnotationScopeMetadataResolverTests extends TestCase {
|
||||||
assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
|
assertEquals(ScopedProxyMode.INTERFACES, scopeMetadata.getScopedProxyMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testCtorWithNullScopedProxyMode() {
|
public void testCtorWithNullScopedProxyMode() {
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
|
||||||
public void test() throws Exception {
|
|
||||||
new AnnotationScopeMetadataResolver(null);
|
new AnnotationScopeMetadataResolver(null);
|
||||||
}
|
}
|
||||||
}.runTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Test(expected=IllegalArgumentException.class)
|
||||||
public void testSetScopeAnnotationTypeWithNullType() {
|
public void testSetScopeAnnotationTypeWithNullType() {
|
||||||
new AssertThrows(IllegalArgumentException.class) {
|
|
||||||
public void test() throws Exception {
|
|
||||||
scopeMetadataResolver.setScopeAnnotationType(null);
|
scopeMetadataResolver.setScopeAnnotationType(null);
|
||||||
}
|
}
|
||||||
}.runTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Scope("singleton")
|
@Scope("singleton")
|
|
@ -16,12 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||||
|
@ -35,13 +36,15 @@ import org.springframework.util.ClassUtils;
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
public class ClassPathScanningCandidateComponentProviderTests {
|
||||||
|
|
||||||
private static final String TEST_BASE_PACKAGE =
|
private static final String TEST_BASE_PACKAGE =
|
||||||
ClassPathScanningCandidateComponentProviderTests.class.getPackage().getName();
|
ClassPathScanningCandidateComponentProviderTests.class.getPackage().getName();
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithDefaults() {
|
public void testWithDefaults() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||||
|
@ -53,12 +56,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithBogusBasePackage() {
|
public void testWithBogusBasePackage() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||||
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
|
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
|
||||||
assertEquals(0, candidates.size());
|
assertEquals(0, candidates.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithPackageExcludeFilter() {
|
public void testWithPackageExcludeFilter() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
|
||||||
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*")));
|
provider.addExcludeFilter(new RegexPatternTypeFilter(Pattern.compile(TEST_BASE_PACKAGE + ".*")));
|
||||||
|
@ -66,12 +71,14 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertEquals(0, candidates.size());
|
assertEquals(0, candidates.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithNoFilters() {
|
public void testWithNoFilters() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
|
||||||
assertEquals(0, candidates.size());
|
assertEquals(0, candidates.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithComponentAnnotationOnly() {
|
public void testWithComponentAnnotationOnly() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||||
|
@ -88,6 +95,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
public void testWithAspectAnnotationOnly() throws Exception {
|
public void testWithAspectAnnotationOnly() throws Exception {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AnnotationTypeFilter(
|
provider.addIncludeFilter(new AnnotationTypeFilter(
|
||||||
|
@ -97,6 +105,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithInterfaceType() {
|
public void testWithInterfaceType() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
|
||||||
|
@ -105,6 +114,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertTrue(containsBeanClass(candidates, StubFooDao.class));
|
assertTrue(containsBeanClass(candidates, StubFooDao.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithClassType() {
|
public void testWithClassType() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
|
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
|
||||||
|
@ -113,6 +123,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertTrue(containsBeanClass(candidates, MessageBean.class));
|
assertTrue(containsBeanClass(candidates, MessageBean.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testWithMultipleMatchingFilters() {
|
public void testWithMultipleMatchingFilters() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
||||||
|
@ -124,6 +135,7 @@ public class ClassPathScanningCandidateComponentProviderTests extends TestCase {
|
||||||
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
|
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExcludeTakesPrecedence() {
|
public void testExcludeTakesPrecedence() {
|
||||||
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
|
||||||
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,10 +25,9 @@ import java.util.List;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
@ -54,7 +55,7 @@ import org.springframework.util.ObjectUtils;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
public class Spr3775InitDestroyLifecycleTests {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(Spr3775InitDestroyLifecycleTests.class);
|
private static final Log logger = LogFactory.getLog(Spr3775InitDestroyLifecycleTests.class);
|
||||||
|
|
||||||
|
@ -86,6 +87,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
return beanFactory;
|
return beanFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInitDestroyMethods() {
|
public void testInitDestroyMethods() {
|
||||||
final Class<?> beanClass = InitDestroyBean.class;
|
final Class<?> beanClass = InitDestroyBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
||||||
|
@ -96,6 +98,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
|
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("destroy"), bean.destroyMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInitializingDisposableInterfaces() {
|
public void testInitializingDisposableInterfaces() {
|
||||||
final Class<?> beanClass = CustomInitializingDisposableBean.class;
|
final Class<?> beanClass = CustomInitializingDisposableBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||||
|
@ -108,6 +111,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
bean.destroyMethods);
|
bean.destroyMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testInitializingDisposableInterfacesWithShadowedMethods() {
|
public void testInitializingDisposableInterfacesWithShadowedMethods() {
|
||||||
final Class<?> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
|
final Class<?> beanClass = InitializingDisposableWithShadowedMethodsBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
||||||
|
@ -119,6 +123,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
|
assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("DisposableBean.destroy"), bean.destroyMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJsr250Annotations() {
|
public void testJsr250Annotations() {
|
||||||
final Class<?> beanClass = CustomAnnotatedInitDestroyBean.class;
|
final Class<?> beanClass = CustomAnnotatedInitDestroyBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||||
|
@ -131,6 +136,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
bean.destroyMethods);
|
bean.destroyMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJsr250AnnotationsWithShadowedMethods() {
|
public void testJsr250AnnotationsWithShadowedMethods() {
|
||||||
final Class<?> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
|
final Class<?> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
|
||||||
|
@ -143,6 +149,7 @@ public class Spr3775InitDestroyLifecycleTests extends TestCase {
|
||||||
bean.destroyMethods);
|
bean.destroyMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAllLifecycleMechanismsAtOnce() {
|
public void testAllLifecycleMechanismsAtOnce() {
|
||||||
final Class<?> beanClass = AllInOneBean.class;
|
final Class<?> beanClass = AllInOneBean.class;
|
||||||
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass,
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package example.scannable;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Inherited;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Inherited
|
||||||
|
public @interface CustomComponent {
|
||||||
|
|
||||||
|
}
|
|
@ -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";
|
||||||
|
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
public interface FooDao {
|
||||||
|
|
||||||
|
String findFoo(int id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
public interface FooService {
|
||||||
|
|
||||||
|
String foo(int id);
|
||||||
|
|
||||||
|
boolean isInitCalled();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.MessageSource;
|
||||||
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class FooServiceImpl implements FooService {
|
||||||
|
|
||||||
|
@Autowired private FooDao fooDao;
|
||||||
|
|
||||||
|
@Autowired public BeanFactory beanFactory;
|
||||||
|
|
||||||
|
@Autowired public List<ListableBeanFactory> listableBeanFactory;
|
||||||
|
|
||||||
|
@Autowired public ResourceLoader resourceLoader;
|
||||||
|
|
||||||
|
@Autowired public ResourcePatternResolver resourcePatternResolver;
|
||||||
|
|
||||||
|
@Autowired public ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
@Autowired public MessageSource messageSource;
|
||||||
|
|
||||||
|
@Autowired public ApplicationContext context;
|
||||||
|
|
||||||
|
@Autowired public ConfigurableApplicationContext[] configurableContext;
|
||||||
|
|
||||||
|
@Autowired public AbstractApplicationContext genericContext;
|
||||||
|
|
||||||
|
private boolean initCalled = false;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
if (this.initCalled) {
|
||||||
|
throw new IllegalStateException("Init already called");
|
||||||
|
}
|
||||||
|
this.initCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String foo(int id) {
|
||||||
|
return this.fooDao.findFoo(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitCalled() {
|
||||||
|
return this.initCalled;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
@CustomComponent
|
||||||
|
public class MessageBean {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public MessageBean() {
|
||||||
|
this.message = "DEFAULT MESSAGE";
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageBean(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
@Component("myNamedComponent")
|
||||||
|
public class NamedComponent {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Juergen Hoeller
|
||||||
|
*/
|
||||||
|
@Repository("myNamedDao")
|
||||||
|
public class NamedStubDao {
|
||||||
|
|
||||||
|
public String find(int id) {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,7 +14,9 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package example.scannable;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Scope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Aspect
|
||||||
|
public class ServiceInvocationCounter {
|
||||||
|
|
||||||
|
private int useCount;
|
||||||
|
|
||||||
|
@Pointcut("execution(* example.scannable.FooService+.*(..))")
|
||||||
|
public void serviceExecution() {}
|
||||||
|
|
||||||
|
@Before("serviceExecution()")
|
||||||
|
public void countUse() {
|
||||||
|
this.useCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return this.useCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* 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 example.scannable;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mark Fisher
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
@Qualifier("testing")
|
||||||
|
public class StubFooDao implements FooDao {
|
||||||
|
|
||||||
|
public String findFoo(int id) {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -16,12 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -34,12 +35,14 @@ import org.springframework.util.StopWatch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
public class AnnotationProcessorPerformanceTests extends TestCase {
|
public class AnnotationProcessorPerformanceTests {
|
||||||
|
|
||||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
|
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
|
||||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||||
// Skip this test: Trace logging blows the time limit.
|
// 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);
|
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
|
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
|
||||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||||
// Skip this test: Trace logging blows the time limit.
|
// 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);
|
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
|
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
|
||||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||||
// Skip this test: Trace logging blows the time limit.
|
// 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);
|
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
|
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
|
||||||
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
if (factoryLog.isTraceEnabled() || factoryLog.isDebugEnabled()) {
|
||||||
// Skip this test: Trace logging blows the time limit.
|
// Skip this test: Trace logging blows the time limit.
|
||||||
|
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
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.core.type.filter.AssignableTypeFilter;
|
||||||
import org.springframework.stereotype.Component;
|
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 Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
public class ClassPathBeanDefinitionScannerTests {
|
||||||
|
|
||||||
private static final String BASE_PACKAGE =
|
private static final String BASE_PACKAGE = "example.scannable";
|
||||||
ClassPathBeanDefinitionScannerTests.class.getPackage().getName();
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
|
public void testSimpleScanWithDefaultFiltersAndPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, beanCount);
|
assertEquals(10, beanCount);
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -59,11 +68,12 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDoubleScan() {
|
public void testDoubleScan() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, beanCount);
|
assertEquals(10, beanCount);
|
||||||
scanner.scan(BASE_PACKAGE);
|
scanner.scan(BASE_PACKAGE);
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
|
@ -73,12 +83,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean("thoreau"));
|
assertTrue(context.containsBean("thoreau"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
|
public void testSimpleScanWithDefaultFiltersAndNoPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(9, beanCount);
|
assertEquals(6, beanCount);
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -86,6 +97,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean("myNamedDao"));
|
assertTrue(context.containsBean("myNamedDao"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
|
public void testSimpleScanWithDefaultFiltersAndOverridingBean() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
|
context.registerBeanDefinition("stubFooDao", new RootBeanDefinition(TestBean.class));
|
||||||
|
@ -95,6 +107,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
scanner.scan(BASE_PACKAGE);
|
scanner.scan(BASE_PACKAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
|
public void testSimpleScanWithDefaultFiltersAndDefaultBeanNameClash() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
|
@ -111,14 +124,15 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
|
public void testSimpleScanWithDefaultFiltersAndOverriddenEqualNamedBean() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
|
context.registerBeanDefinition("myNamedDao", new RootBeanDefinition(NamedStubDao.class));
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(8, beanCount);
|
assertEquals(5, beanCount);
|
||||||
assertEquals(9, context.getBeanDefinitionCount());
|
assertEquals(6, context.getBeanDefinitionCount());
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -126,6 +140,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean("myNamedDao"));
|
assertTrue(context.containsBean("myNamedDao"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
|
public void testSimpleScanWithDefaultFiltersAndOverriddenCompatibleNamedBean() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
|
RootBeanDefinition bd = new RootBeanDefinition(NamedStubDao.class);
|
||||||
|
@ -134,8 +149,8 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(8, beanCount);
|
assertEquals(5, beanCount);
|
||||||
assertEquals(9, context.getBeanDefinitionCount());
|
assertEquals(6, context.getBeanDefinitionCount());
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -143,6 +158,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean("myNamedDao"));
|
assertTrue(context.containsBean("myNamedDao"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
|
public void testSimpleScanWithDefaultFiltersAndSameBeanTwice() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
|
@ -152,6 +168,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
scanner.scan(BASE_PACKAGE);
|
scanner.scan(BASE_PACKAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
|
public void testSimpleScanWithDefaultFiltersAndSpecifiedBeanNameClash() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
|
@ -168,6 +185,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
|
public void testCustomIncludeFilterWithoutDefaultsButIncludingPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||||
|
@ -180,6 +198,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
|
public void testCustomIncludeFilterWithoutDefaultsAndNoPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||||
|
@ -197,12 +216,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomIncludeFilterAndDefaults() {
|
public void testCustomIncludeFilterAndDefaults() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||||
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(14, beanCount);
|
assertEquals(11, beanCount);
|
||||||
assertTrue(context.containsBean("messageBean"));
|
assertTrue(context.containsBean("messageBean"));
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
|
@ -214,12 +234,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomAnnotationExcludeFilterAndDefaults() {
|
public void testCustomAnnotationExcludeFilterAndDefaults() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||||
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(12, beanCount);
|
assertEquals(9, beanCount);
|
||||||
assertFalse(context.containsBean("serviceInvocationCounter"));
|
assertFalse(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("fooServiceImpl"));
|
assertTrue(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -230,12 +251,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomAssignableTypeExcludeFilterAndDefaults() {
|
public void testCustomAssignableTypeExcludeFilterAndDefaults() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(12, beanCount);
|
assertEquals(9, beanCount);
|
||||||
assertFalse(context.containsBean("fooServiceImpl"));
|
assertFalse(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -246,13 +268,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
|
public void testCustomAssignableTypeExcludeFilterAndDefaultsWithoutPostProcessors() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(8, beanCount);
|
assertEquals(5, beanCount);
|
||||||
assertFalse(context.containsBean("fooServiceImpl"));
|
assertFalse(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -263,13 +286,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertFalse(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertFalse(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleCustomExcludeFiltersAndDefaults() {
|
public void testMultipleCustomExcludeFiltersAndDefaults() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, true);
|
||||||
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
|
||||||
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(11, beanCount);
|
assertEquals(8, beanCount);
|
||||||
assertFalse(context.containsBean("fooServiceImpl"));
|
assertFalse(context.containsBean("fooServiceImpl"));
|
||||||
assertFalse(context.containsBean("serviceInvocationCounter"));
|
assertFalse(context.containsBean("serviceInvocationCounter"));
|
||||||
assertTrue(context.containsBean("stubFooDao"));
|
assertTrue(context.containsBean("stubFooDao"));
|
||||||
|
@ -280,12 +304,13 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomBeanNameGenerator() {
|
public void testCustomBeanNameGenerator() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, beanCount);
|
assertEquals(10, beanCount);
|
||||||
assertFalse(context.containsBean("fooServiceImpl"));
|
assertFalse(context.containsBean("fooServiceImpl"));
|
||||||
assertTrue(context.containsBean("fooService"));
|
assertTrue(context.containsBean("fooService"));
|
||||||
assertTrue(context.containsBean("serviceInvocationCounter"));
|
assertTrue(context.containsBean("serviceInvocationCounter"));
|
||||||
|
@ -297,35 +322,37 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
assertTrue(context.containsBean(AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleBasePackagesWithDefaultsOnly() {
|
public void testMultipleBasePackagesWithDefaultsOnly() {
|
||||||
GenericApplicationContext singlePackageContext = new GenericApplicationContext();
|
GenericApplicationContext singlePackageContext = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
|
ClassPathBeanDefinitionScanner singlePackageScanner = new ClassPathBeanDefinitionScanner(singlePackageContext);
|
||||||
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
|
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
|
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
|
||||||
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
|
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, singlePackageBeanCount);
|
assertEquals(10, singlePackageBeanCount);
|
||||||
int multiPackageBeanCount = multiPackageScanner.scan(
|
multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
|
||||||
BASE_PACKAGE, "org.springframework.dao.annotation");
|
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
||||||
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testMultipleScanCalls() {
|
public void testMultipleScanCalls() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, beanCount);
|
assertEquals(10, beanCount);
|
||||||
assertEquals(beanCount, context.getBeanDefinitionCount());
|
assertEquals(beanCount, context.getBeanDefinitionCount());
|
||||||
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
|
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
|
||||||
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
|
assertEquals(beanCount + addedBeanCount, context.getBeanDefinitionCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeanAutowiredWithAnnotationConfigEnabled() {
|
public void testBeanAutowiredWithAnnotationConfigEnabled() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
|
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(13, beanCount);
|
assertEquals(10, beanCount);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
|
|
||||||
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
|
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
|
||||||
|
@ -347,13 +374,14 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertSame(context, fooService.genericContext);
|
assertSame(context, fooService.genericContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
|
public void testBeanNotAutowiredWithAnnotationConfigDisabled() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
scanner.setIncludeAnnotationConfig(false);
|
scanner.setIncludeAnnotationConfig(false);
|
||||||
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
|
||||||
int beanCount = scanner.scan(BASE_PACKAGE);
|
int beanCount = scanner.scan(BASE_PACKAGE);
|
||||||
assertEquals(9, beanCount);
|
assertEquals(6, beanCount);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
FooService fooService = (FooService) context.getBean("fooService");
|
FooService fooService = (FooService) context.getBean("fooService");
|
||||||
assertFalse(fooService.isInitCalled());
|
assertFalse(fooService.isInitCalled());
|
||||||
|
@ -365,6 +393,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowireCandidatePatternMatches() {
|
public void testAutowireCandidatePatternMatches() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
|
@ -377,6 +406,7 @@ public class ClassPathBeanDefinitionScannerTests extends TestCase {
|
||||||
assertEquals("bar", fooService.foo(123));
|
assertEquals("bar", fooService.foo(123));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAutowireCandidatePatternDoesNotMatch() {
|
public void testAutowireCandidatePatternDoesNotMatch() {
|
||||||
GenericApplicationContext context = new GenericApplicationContext();
|
GenericApplicationContext context = new GenericApplicationContext();
|
||||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
|
||||||
|
|
|
@ -23,6 +23,9 @@ import org.springframework.beans.FatalBeanException;
|
||||||
import org.springframework.beans.factory.config.SimpleMapScope;
|
import org.springframework.beans.factory.config.SimpleMapScope;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
|
import example.scannable.FooService;
|
||||||
|
import example.scannable.ScopedProxyTestBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.springframework.core.type.classreading.MetadataReader;
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||||
import org.springframework.core.type.filter.TypeFilter;
|
import org.springframework.core.type.filter.TypeFilter;
|
||||||
|
|
||||||
|
import example.scannable.AutowiredQualifierFooService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.context.annotation;
|
||||||
|
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||||
|
|
||||||
|
import example.scannable.FooService;
|
||||||
|
import example.scannable.ServiceInvocationCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -18,6 +18,9 @@ package org.springframework.context.annotation;
|
||||||
|
|
||||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||||
|
|
||||||
|
import example.scannable.FooService;
|
||||||
|
import example.scannable.ServiceInvocationCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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:component-scan base-package="example.scannable" use-default-filters="false" annotation-config="false">
|
||||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.Stub*"/>
|
<context:include-filter type="aspectj" expression="example.scannable.Stub*"/>
|
||||||
<context:include-filter type="aspectj" expression="org.springframework.context.annotation.FooService+"/>
|
<context:include-filter type="aspectj" expression="example.scannable.FooService+"/>
|
||||||
<context:exclude-filter type="aspectj" expression="org.springframework..Scoped*Test*" />
|
<context:exclude-filter type="aspectj" expression="example..Scoped*Test*" />
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
http://www.springframework.org/schema/context
|
http://www.springframework.org/schema/context
|
||||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
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>
|
</beans>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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"/>
|
name-generator="org.springframework.context.annotation.TestBeanNameGenerator"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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"/>
|
scope-resolver="org.springframework.context.annotation.TestScopeMetadataResolver"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -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/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">
|
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 -->
|
<!-- shouldn't cause a conflict -->
|
||||||
<context:component-scan base-package="org.springframework.context.annotation"/>
|
<context:component-scan base-package="example.scannable"/>
|
||||||
|
|
||||||
<aop:aspectj-autoproxy/>
|
<aop:aspectj-autoproxy/>
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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:component-scan base-package="example."
|
||||||
resource-pattern="**/annotation/*.class"
|
resource-pattern="**/scannable/*.class"
|
||||||
use-default-filters="false"
|
use-default-filters="false"
|
||||||
annotation-config="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>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
resource-pattern="**/thispackagedoesnotexist/*.class"
|
resource-pattern="**/thispackagedoesnotexist/*.class"
|
||||||
use-default-filters="false"
|
use-default-filters="false"
|
||||||
annotation-config="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>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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">
|
||||||
use-default-filters="false">
|
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||||
<context:include-filter type="assignable"
|
|
||||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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="interfaces">
|
||||||
use-default-filters="false" scoped-proxy="interfaces">
|
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||||
<context:include-filter type="assignable"
|
|
||||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -5,10 +5,9 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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">
|
use-default-filters="false" scoped-proxy="no">
|
||||||
<context:include-filter type="assignable"
|
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -5,10 +5,8 @@
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
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="targetClass">
|
||||||
use-default-filters="false" scoped-proxy="targetClass">
|
<context:include-filter type="assignable" expression="example.scannable.ScopedProxyTestBean"/>
|
||||||
<context:include-filter type="assignable"
|
|
||||||
expression="org.springframework.context.annotation.ScopedProxyTestBean"/>
|
|
||||||
</context:component-scan>
|
</context:component-scan>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
|
|
||||||
<aop:aspectj-autoproxy/>
|
<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>
|
</beans>
|
||||||
|
|
|
@ -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/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">
|
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/>
|
<aop:aspectj-autoproxy/>
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,8 @@ package org.springframework.context.annotation3;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.context.annotation.FooDao;
|
|
||||||
|
import example.scannable.FooDao;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
|
Loading…
Reference in New Issue