记录下方法:
package com.zbj.cs.chance.reformChanceBiz.util; import com.zbj.cs.chance.reformChanceBiz.impl.NewChanceConfigBiz; /** * @title 一句话说明功能 * @author: wangtingsong * @Date: 2020/3/30 16:29 * @since 版本号 */ public class ControlNewChanceUtils { //新逻辑执行开关是否打开 public static String NEW_CHANCE_ONOFF; //新逻辑日志入库开关是否打开 public static String NEW_CHANCE_INSERT_LOG; //新逻辑推送消息开关是否打开 public static String NEW_CHANCE_SEND_MESSAGE; public static void setNewChanceConfig(NewChanceConfigBiz newChanceConfig){ ControlNewChanceUtils.NEW_CHANCE_ONOFF = newChanceConfig.getNewChanceOnOff(); ControlNewChanceUtils.NEW_CHANCE_INSERT_LOG = newChanceConfig.getOnOffLog(); ControlNewChanceUtils.NEW_CHANCE_SEND_MESSAGE = newChanceConfig.getOnOffMessage(); } public static boolean checkOnOff(){ return "yes".equals(ControlNewChanceUtils.NEW_CHANCE_ONOFF); } public static boolean checkOnOffLog(){ return "yes".equals(ControlNewChanceUtils.NEW_CHANCE_INSERT_LOG); } public static boolean checkOnOffSendMessage(){ return "yes".equals(ControlNewChanceUtils.NEW_CHANCE_SEND_MESSAGE); } }
使用 @PostConstruct注解方式 实例化bean的时候 进行初始化读取值
package com.zbj.cs.chance.reformChanceBiz.impl; import com.zbj.cs.chance.reformChanceBiz.util.ControlNewChanceUtils; import javax.annotation.PostConstruct; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** * @title 一句话说明功能 * @author: wangtingsong * @Date: 2020/3/30 16:45 * @since 版本号 */ @Configuration @Data public class NewChanceConfigBiz { @Value("${new.chance.onOff}") private String newChanceOnOff; @Value("${new.chance.insert.log}") private String onOffLog; @Value("${new.chance.send.message}") private String onOffMessage; @PostConstruct public void init(){ ControlNewChanceUtils.setNewChanceConfig(this); } }