Spring Condition not able to read value from property file

后端 未结 4 891
耶瑟儿~
耶瑟儿~ 2021-01-11 13:24

I am trying to implement Spring Condition org.springframework.context.annotation.Conditionas follows:

public class APIScanningDecisionMaker impl         


        
4条回答
  •  执念已碎
    2021-01-11 14:01

    If you add @Conditional to config class then APIScanningDecisionMaker should implement ConfigurationCondition. And don't forget to add @PropertySource to config class.

    import org.springframework.context.annotation.ConfigurationCondition;
    
    public class APIScanningDecisionMaker implement ConfigurationCondition {
        @Override
        public ConfigurationPhase getConfigurationPhase() {
            return ConfigurationPhase.REGISTER_BEAN;
        }
    }
    

    Properties will have been loaded in ConfigurationPhase.REGISTER_BEAN phase.

    If you use @Conditional for methods then you could implement Condition.

提交回复
热议问题