Affects: 5.3.9


Environment: Kotlin 1.5.30, SpringBoot 2.5.4(Spring 5.3.9)

I'm trying to create a composed annotation to simplify similar template annotation codes. The annotation class is like this:

@Profile("default")   //NOTE1
annotation class ProfileAware(
    @get: AliasFor(annotation = Profile::class, attribute = "value")
    val profiles: Array<String>,
    //properties delegated for other annotations
)

expected usage:

@Component
@ProfileAware(profiles = ["dev"]) //NOTE2
class TheBean

But after the application starts, TheBean is not registered as expected.

After multiple times tries and investigation(For more detail see The StackOverflow Question), it looks like that spring just parses original hardcoded value (default, at NOTE1 in above code snippet), but what I want is the dynamic value from the call place(at NOTE2).

Comment From: Muyangmin

Any ideas or updates?

Comment From: sbrannen

@Profile is looked up by org.springframework.context.annotation.ProfileCondition whose matches(...) method uses org.springframework.core.type.AnnotatedTypeMetadata.getAllAnnotationAttributes(String) to look up the @Profile annotations, and the Javadoc for that method states the following (bold emphasis added by me).

Retrieve all attributes of all annotations of the given type, if any (i.e. if defined on the underlying element, as direct annotation or meta-annotation). Note that this variant does not take attribute overrides into account.

Thus, you currently cannot use @Profile with @AliasFor for annotation attribute overrides.

Comment From: Muyangmin

Thanks for your clear and useful explaination :thumbsup:. I'll go back to use hardcoded version instead.