I am having some trouble getting some Spring configuration to be applied in the desired order with Spring Boot in a multi-module Maven project.
I have modules A and B that are written by me and a dependency on a third party module that I have no control over in module C (dependencies are as follows: A depends on C, B depends on A)
In module A I have a class annotated with @Configuration
and also @AutoConfigureBefore(ClassFromModuleD.class)
. In module B I have another class annotated with @Configuration
and also @AutoConfigureBefore(ClassFromModuleA.class)
I was hoping that this would result in the bean definitions in my module B being configured first, followed by beans in my module A configuration class then finally the ones in C.
I also tried adding a META-INF/spring.factories
file to both module A and B which declares the single configuration file present in its own module. E.g. for module A
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.exmaple.moduleAConfiguration
and in module B:
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.exmaple.moduleBConfiguration
I am not seeing the desired order of configuration, in fact, it seems to be the exact opposite to what I want. I have used logging statements and a debugger to step through and it seems the config from Module C is applied first, followed by A then finally B.
Could anyone point out what I may have missed or if there is another way to do this? thanks very much in advance.