In Boot 2.7.6, the convenience annotations @AutoConfigureBefore/After are available to enhance the behavior of auto-configuration classes, and they are cumulative with the properties on @AutoConfiguration. The annotations are declared with a target of TYPE and are presumably intended to be applied only to classes specifically.
However, Spring has a wide tradition of supporting meta-annotation with configuration directives, and it would be very helpful to have that functionality here. For example, I have an internal library that provides some setup help for Amazon SNS topics, and it internally configures after separate implementations using AWS SDK 1 and 2. I'd like to be able to export an annotation @AutoConfigureAfterSnsIntegration that encapsulates all of the @AutoConfigureAfter(name = { ... }) specification, so that clients wouldn't have to enumerate a potentially-changing list of dependencies. Right now, @AutoConfigureAfter can be meta-annotated physically, but meta-annotation logic is not applied by Boot.
Comment From: philwebb
@chrylis Since @AutoConfigureBefore and @AutoConfigureAfter can only be used on auto-configuration classes we haven't really considered the need for them to work on meta-annotations. Who would be the audience for your @AutoConfigureAfterSnsIntegration annotation? Do you have downstream projects that provide auto-configuations that need to apply this ordering?
Comment From: chrylis
I export a library that auto-configures adapters to and from AWS messaging products into Spring Integration channels, using AWSpring and Spring Integration AWS. This library can be used directly by applications to declare mappings, but it also has a reusable registrar component that other libraries can use. We have a microservices architecture that uses messaging, and the idea is to be able to provide a service client library that can be auto-configured by providing an SNS topic name but otherwise contains the necessary information inside its jar (e.g., message formatting).
Due to the in-progress state of AWSpring 3, we currently have to use the AWS SDK 1 interfaces to talk to their messaging services, but we will roll those over to SDK 2 as soon as support is ready in Spring Integration AWS, and I'm abstracting the DSL configurations onto the channel adapters, which means that different provider auto-configurations may be at play. I ended up with a kind of diamond problem of "A before C" and "B before C" but where the sequencing of A and B was nondeterministic.
Note that the meta-annotation would be for convenience of maintenance; it doesn't add any new fundamental capability, but it would allow us to add new "auto-configure after" entries without having to edit all of the applications that depend on our microservice-client library.
The analogy isn't exact, but the relationship is similar to HibernateJpaConfiguration, DataSourceAutoConfiguration, and the connection-pool auto-configurations, which are nicely referenced in Boot because they're in the same artifact, but which are arranged as dependencies for us.
Comment From: philwebb
We discussed this one today and we decided that we don't think we should invest in supporting @AutoConfigureBefore or @AutoConfigureAfter as meta-annotations. One issue with supporting them is that it's not as easy as moving to MergedAnnotation. We have an annotation processor that creates properties files that would also need to change. Once we add support we'd also need to maintain it going forward.
Given the limited use we've found for this ourselves, we don't think we can justify the investment.
Thanks anyway for the suggestion @chrylis!