Skip to content

@Enable registrars invoked with subclass for annotation placed on superclass (3.2.x) [SPR-11251] #15876

@spring-projects-issues

Description

@spring-projects-issues

Oliver Drotbohm opened SPR-11251 and commented

If you have an @Enable… annotation, itself not being annotated with @Inherited, the related ImportBeanDefinitionRegistrar is still invoked multiple times when used in inheritance scenarios for configuration classes.

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Import(SomeImporBeanDefinitionRegistrar.class)
public @interface MyAnnotation {

}

@Configuration
@MyAnnotation
public class Config {}

@Configuration
public class SubConfig {}

new AnnotationConfigApplicationContext(SubConfig.class);

Here are the erroneous effects:

  1. The ImportBeanDefinitionRegistrar gets invoked for the leaf class (SubConfig of the inheritance hierarchy (not the one the annotation is on)
  2. The AnnotationMetadata does then return null if you're trying to access the annotation attributes of the triggering annotation.

I've prepared more code samples and the log output for the invocations in this Gist. Spring 4 seems to handle this correct already.


Affects: 3.2.6

Issue Links:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions