Spring Boot Version
3.0.2
Description of Bug/Issue
When I'm using @AutoConfiguration to develop a custom starter, I've noticed that even after specifying before, @AutoConfiguration still doesn't execute as expected.
I have customized MultiLettuceConnectionConfiguration and expect this configuration to be applied before LettuceConnectionConfiguration, replacing the LettuceConnectionFactory configuration in it.
Because the LettuceConnectionFactory in LettuceConnectionConfiguration is annotated with @ConditionalOnMissingBean(RedisConnectionFactory.class), as long as MultiLettuceConnectionConfiguration is executed before it, the RedisConnectionFactory in LettuceConnectionConfiguration will not be loaded.
Finally, in my project, I use org.springframework.boot.autoconfigure.AutoConfiguration.imports to import MultiLettuceConnectionConfiguration. However, when I use my starter in another project, the following exception occurs.
Both RedisConnectionFactory from LettuceConnectionConfiguration and MultiLettuceConnectionConfiguration are being loaded, which is not as expected. However, when I change the @AutoConfiguration annotation on MultiLettuceConnectionConfiguration to the following, it works as expected:
As mentioned above, I added RedisAutoConfiguration in the before attribute, as I noticed that RedisAutoConfiguration uses @Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class }). I suspect that testing this might be the cause. I don't know if this situation is designed this way by default or if it's due to issues with the @Import annotation.
Please answer the question, thank you!
Comment From: philwebb
You can only use the before and after attributes of @AutoConfiguration to refer to other auto-configuration classes. Using before=LettuceConnectionConfiguration.class will have no effect. Your second example is working because you are referencing RedisAutoConfiguration which is an auto-configuration class.