我有多個帶有@ConditionalOnMissingBean注釋的bean,哪個會被使用?我怎樣才能控制其優先級?
uj5u.com熱心網友回復:
如果你想控制@Bean創建順序,你可以使用注解@Order
@Component
@Order(1)
public class First {
public int first {
return 1;
}
@Component; }
@Order(2)
public class Second {
public int second() {
return 2;
}
或者你也可以使用@DependsOn
@Configuration
public class ActionCfg {
@Bean[/span
@DependsOn({"actionA", "actionB"})
public ActionC actionC(){
return new ActionC()。
}
@Bean("ActionA")。
public ActionA actionA() {
return new ActionA()。
}
@Bean("ActionB")。
public ActionB actionB() {
return new ActionB()。
}
ActionA和ActionB將在ActionC之前初始化。
uj5u.com熱心網友回復:
首先運行自動配置類的Bean將被占用。
有@AutoConfigureBefore、@AutoConfigureAfter和@AutoConfigureOrder來控制自動配置類的順序。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/307765.html
標籤:
