Spring Boot @Configuration order

huangapple go评论53阅读模式
英文:

Spring boot @Configuration order

问题

我有两个配置类,ConfigAConfigB,有没有办法按我想要的顺序加载这些配置类,我想要先加载 ConfigB 然后再加载类 ConfigA。请帮助我。

英文:

I have two configuration classes, ConfigA & ConfigB , Is there anyway that I can load those configuration classes in the order, I want ConfigB to be loaded first then load the class ConfigA. Please help me.

答案1

得分: 1

如果@Configuration类被组件扫描,您不能可靠地控制它们的顺序,因此第一步是确保它们不被组件扫描。然后,您可以使用@Import来导入配置类。它们将按照您在@Import注解中列出的顺序进行处理。

英文:

If the @Configuration classes are component-scanned you cannot reliably control their order so the first step is to ensure that they aren't component scanned. You can then use @Import to import the configuration classes. They will be processed in the order in which you list them in the @Import annotation.

huangapple
  • 本文由 发表于 2023年4月17日 23:07:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036613-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定