4

In my spring boot project I use a module, which provides a @Configuration class. The configuration ist imported via @Import(ConfigurationFromModule.class) in Application class.

The configuration from the module needs to happen before a certain AutoConfiguration. Unfortunately annotations defining the order of configurations seem to be ignored in the modules classes.

I annotated the Configuration with @AutoConfigureBefore({SomeBuildInAutoConfiguration.class}), but still SomeBuildInAutoConfiguration was triggered before ConfigurationFromModule.

Out of curiosity I tried to annoatate ConfigurationFromModule with @AutoConfigureOrder(1) and @Primary - but they don't change anything.

For @Configurationclasses within the main applications all those annotations work as expected.

How to define order of AutoConfiguration within a module?

kai-dj
  • 315
  • 1
  • 18

1 Answers1

0

Spring AutoConfiguration provides a basic configuration if certain classes are in the classpath or not.

If you want that configuration in order you can make use of @DependsOn

@DependsOn("One") 
public class Two{
    
}

This helps you to create bean "One", then bean "Two".

Spring automatically detects the dependencies by analyzing the bean classes.

If Bean One has an autowired property or a constructor argument of type Two, spring knows that it must instantiate Two before One.

TechGeek
  • 480
  • 1
  • 8
  • 22
  • DependsOn is the other way round - I need to have my custom class from module loaded before a build-in-autoconfiguration. DependsOn would only ensure some build-in-autoconfiguration is done before my custom class is loaded – kai-dj Aug 24 '20 at 06:24