Skip to content

Support Class meta-annotation attributes with ASM-based annotation processing [SPR-11557] #16181

Closed

Description

@spring-projects-issues

Sérgio Silva opened SPR-11557 and commented

I'm trying to create a composed annotation which uses @Configuration and @ComponentScan as meta-annotations.

@Configuration
@ComponentScan
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface BennuSpringModule {
    String[] basePackages() default {};

    String[] bundles() default {};
}

The problem appears in ConfigurationClassPostProcessor:

java.lang.IllegalArgumentException: Attribute 'nameGenerator' is of type [String], but [Class] was expected. Cause: 
	at org.springframework.core.annotation.AnnotationAttributes.doGet(AnnotationAttributes.java:117)
	at org.springframework.core.annotation.AnnotationAttributes.getClass(AnnotationAttributes.java:89)
	at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:82)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:236)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:173)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:241)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:205)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:152)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:299)
	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.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:530)
	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
	at javax.servlet.GenericServlet.init(GenericServlet.java:160)
	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091)
	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5033)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5317)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

The meta-annotation is being processed with classValuesAsString set to true which breaks the look-up for Class Type. See AnnotationAttributesReadingVisitor for details.


Affects: 4.0.2

Issue Links:

Referenced from: commits 9ce0df8, e7b8a65, f1fbe85

Activity

  1. spring-projects-issues commented on Mar 14, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Sérgio Silva, I attempted to reproduce the issue you describe; however, I was unsuccessful.

    Please take a look at the unit and integration tests that I checked in with GitHub commit f1fbe85 and let me know if that adequately represents the configuration you are using.

    If you are still experiencing the IllegalArgumentException, please provide us a project that reproduces the problem. Details on how to do that can be found in the README of the spring-framework-issues project on GitHub.

    Can you also please confirm that you experience this issue against Spring Framework 4.0.2?

    Thanks in advance for feedback!

    Sam

  2. spring-projects-issues commented on Mar 14, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sérgio Silva commented

    Updated stacktrace.

    I can confirm it is 4.0.2. I will try to add an example test/project soon.

  3. spring-projects-issues commented on Mar 16, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Sérgio Silva, thanks for updating the stacktrace and confirming that this is against 4.0.2.

    Based on your stacktrace, it is apparent that there is a problem; however, I have yet to come up with a test case that reproduces this. So, an example/test project would be very useful!

    Please provide a test project or at least an example of the class hierarchy and exact annotations (including meta- and meta-meta-annotations) that you're using. The sooner you can do this, the better... since we plan to release Spring Framework 4.0.3 before the end of March.

    We also need to know how you are bootstrapping the application context. It appears that you're experiencing the problem as the DispatcherServlet for your Spring MVC web application starts up, but knowing the details of your configuration might prove useful.

    Thanks in advance!

    Sam

  4. spring-projects-issues commented on Mar 16, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sérgio Silva commented

    I tried to reproduce it based on your tests and also with the issues war-java project but unsuccessfully. I think this something specific with my setup since we have a multi-jar scenario, I will try to send you a setup where this is reproducible till midnight.

  5. spring-projects-issues commented on Mar 16, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    I tried to reproduce it based on your tests and also with the issues war-java project but unsuccessfully. I think this something specific with my setup since we have a multi-jar scenario

    I think it has something to do with how your application classes are loaded (e.g., a combination of JARs) and whether or not Spring has to use ASM or reflection to inspect the annotations on your classes. Thus your specific setup is likely required to reproduce this.

    I will try to send you a setup where this is reproducible till midnight.

    Thanks!

  6. spring-projects-issues commented on Mar 17, 2014

    @spring-projects-issues
    CollaboratorAuthor
  7. spring-projects-issues commented on Mar 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Sérgio Silva, thanks for supplying us the example project!

    That certainly helps. I am working on a solution and will keep you posted.

    Regards,

    Sam

  8. spring-projects-issues commented on Mar 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Fixed as described in the comments for GitHub commit 9ce0df8:

    Support Class meta-annotation attributes with ASM

    Prior to this commit, AnnotationAttributesReadingVisitor treated Class
    annotation attributes as Strings instead of Classes. As a result,
    look-ups for Class attributes in meta-annotations failed with an
    IllegalArgumentException.

    This commit fixes this issue by consistently treating Class attributes
    as Classes in AnnotationAttributesReadingVisitor.

  9. spring-projects-issues commented on Mar 18, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Sérgio Silva,

    I have some good news and some bad news for you.

    As you can see above, I have resolved this issue as Fixed. However, the scope is limited.

    With the fix in place (available in the next snapshot build for Spring Framework 4.0.3), you should now be able to use @ComponentScan as a meta-annotation in your web application. However, analysis of your example application has revealed a much larger issue. Namely, Spring simply does not currently support meta-annotation attribute overrides -- like the basePackages attribute in your example -- when annotation processing is performed using ASM instead of reflection.

    Thus, you will likely want to add yourself as as watcher for #16198.

    Regards,

    Sam

  10. spring-projects-issues commented on Mar 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sérgio Silva commented

    Thanks for the feedback. I will wait for the fix!

  11. spring-projects-issues commented on Mar 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Sérgio Silva, I just deployed your example application to Tomcat 7 against a local 4.0.3 snapshot for Spring that contains the fix for this issue and #16198, and when I access http://localhost:8080/xpto/spaces, I now see the following in the browser:

    Hello World!This is my controller!
    

    So it appears that your problem has been solved. Please test against the next 4.0.3.BUILD-SNAPSHOT build for Spring and let us know if everything looks good on your end.

    Thanks,

    Sam

  12. spring-projects-issues commented on Mar 31, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sérgio Silva commented

    Working as expected with 4.0.3-RELEASE

  13. spring-projects-issues commented on Apr 2, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Great!

    Thanks for confirming.

  14. added
    type: bug
    in: core
    on Jan 11, 2019
  15. added this to the 4.0.3 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