配置文件读取yml自定义参数(亲测可用)

    技术2022-07-11  117

    dict: js: url: D:\jsFile\

    首先自定义一个参数

    @Component @Data @ConfigurationProperties(prefix = "dict.js") @PropertySource(value = "classpath:application-dev.yml") public class PropertisParam { private String url; }

    利用平时@value 获取值

    然后在所需要的调用的配置类里面注入PropertisParam,利用@PostConstruct初始化值

    @Resource private PropertisParam param; private static String root=null; @PostConstruct public void init(){ root = param.getUrl(); }

     

     

    Processed: 0.016, SQL: 9