Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

includeFilters and excludeFilters of @ComponentScan cause failures when used in meta-annotations [SPR-12065] #16681

Closed
spring-projects-issues opened this issue Aug 4, 2014 · 1 comment
Assignees
Labels
in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 4, 2014

Maciej Drozdzowski opened SPR-12065 and commented

If @ComponentScan is used as a meta annotation and filters are attributes that can be overriden via the target annotation, the following happens:

java.lang.IllegalArgumentException: Attribute 'excludeFilters' is of type [Filter[]], but [AnnotationAttributes[]] was expected. Cause: 
	at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)
	at org.springframework.core.annotation.AnnotationAttributes.getAnnotationArray(AnnotationAttributes.java:101)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:103)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:249)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:218)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:185)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:155)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:609)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

When the filters are uses like so, in the meta-annotation, it works well:

@ComponentScan(
    excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, value = TestConfiguration.class)
    }
)
@Import(PostProcessors.class)
@EnableWebMvc
@Configuration
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface WebContextConfiguration {
}

This however, breaks:

@ComponentScan
@Import(PostProcessors.class)
@EnableWebMvc
@Configuration
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface WebContextConfiguration {

    Filter[] excludeFilters() default {};

}

@WebContextConfiguration(
    excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, value = TestConfiguration.class)
    }
)
public class Config {}

Affects: 4.0.6

Referenced from: commits d61353d, ef51d4d

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 8, 2014

Juergen Hoeller commented

Turns out that this was caused by a missing value adaptation step for overriding attributes - in AnnotatedElementUtils itself. Fixed for 4.1 RC2 and 4.0.7 now.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core type: bug
Projects
None yet
Development

No branches or pull requests

2 participants