ComponentScanBeanDefinitionParser supports placeholders for entire base-package specification and for type filter expressions

Issue: SPR-10424
Issue: SPR-10425
This commit is contained in:
Juergen Hoeller
2014-09-25 01:03:08 +02:00
parent 5ecdd8ca31
commit e52f041a78
4 changed files with 55 additions and 19 deletions

View File

@@ -32,7 +32,6 @@ import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.stereotype.Component;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@@ -49,8 +48,9 @@ public class ComponentScanParserTests {
return new ClassPathXmlApplicationContext(path, getClass());
}
@Test
public void aspectJTypeFilter() {
public void aspectjTypeFilter() {
ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml");
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
@@ -58,6 +58,25 @@ public class ComponentScanParserTests {
context.close();
}
@Test
public void aspectjTypeFilterWithPlaceholders() {
System.setProperty("basePackage", "example.scannable, test");
System.setProperty("scanInclude", "example.scannable.FooService+");
System.setProperty("scanExclude", "example..Scoped*Test*");
try {
ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTestsWithPlaceholders.xml");
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertFalse(context.containsBean("scopedProxyTestBean"));
context.close();
}
finally {
System.clearProperty("basePackage");
System.clearProperty("scanInclude");
System.clearProperty("scanExclude");
}
}
@Test
public void nonMatchingResourcePattern() {
ClassPathXmlApplicationContext context = loadContext("nonMatchingResourcePatternTests.xml");
@@ -131,6 +150,7 @@ public class ComponentScanParserTests {
public static @interface CustomAnnotation {
}
/**
* Intentionally spelling "custom" with a "k" since there are numerous
* classes in this package named *Custom*.
@@ -146,6 +166,7 @@ public class ComponentScanParserTests {
}
}
/**
* Intentionally spelling "custom" with a "k" since there are numerous
* classes in this package named *Custom*.
@@ -154,6 +175,7 @@ public class ComponentScanParserTests {
public static class KustomAnnotationDependencyBean {
}
public static class CustomTypeFilter implements TypeFilter {
/**

View File

@@ -8,7 +8,7 @@
<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:exclude-filter type="aspectj" expression="example..Scoped*Test*"/>
</context:component-scan>
</beans>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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="${basePackage}" use-default-filters="false" annotation-config="false">
<context:include-filter type="aspectj" expression="example.scannable.Stub*"/>
<context:include-filter type="aspectj" expression="${scanInclude}"/>
<context:exclude-filter type="aspectj" expression="${scanExclude}"/>
</context:component-scan>
</beans>