2016-04-29 78 views
0

我試過如下;如何在Spring Boot中使用AllNestedConditions

public class MySwitch extends AllNestedConditions { 

    public MySwitch(ConfigurationPhase configurationPhase) { 
     super(configurationPhase); 
    } 

    @ConditionalOnProperty(name = "EnableSomething") 
    static class OnProperty { 
    } 
} 

,但我得到這樣的錯誤: Failed to Instantiate as no default Constructor Found

這樣做的正確方法是什麼?

回答

1

您必須使用超級構造函數來告訴彈簧在哪個階段應該考慮條件。在你的情況下,它應該看起來像這樣:

public class MySwitch extends AllNestedConditions { 

    public MySwitch() { 
     super(ConfigurationPhase.REGISTER_BEAN); 
    } 

    @ConditionalOnProperty(name = "EnableSomething") 
    static class OnProperty { 
    } 
} 
+0

工作!謝謝!! – Raj

相關問題