Is it possible to set order of instantiation in Spring?
I don\'t want to use @DependsOn and I don\'t want to use Ordered interface. I just
If you want to make sure that a specific bean is created before another bean you can use the @DependsOn annotation.
@Configuration
public class Configuration {
@Bean
public Foo foo() {
...
}
@Bean
@DependsOn("foo")
public Bar bar() {
...
}
}
Keep in mind that this does not set the order, it only guarantees that the bean "foo" is created before "bar". JavaDoc for @DependsOn