Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. spring-projects-issues commented on Aug 8, 2014

    @spring-projects-issues
    CollaboratorAuthor

    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

  2. added
    type: bug
    in: core
    on Jan 11, 2019
  3. added this to the 4.0.7 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: coretype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions