zoukankan      html  css  js  c++  java
  • @PropertySource加载文件的两种用法以及配置文件加载顺序

    第一种:

    现在我把资源文件的路径放在application.properties里

    config.path=/home/myservice/config.properties

    @PropertySource(value = {"file:${config.path}"}, encoding="utf-8")
    public class MyConfig {
        @Value("${myconfig.index}")
        private String index;
    
        public String getIndex() {
           return index;
        }
    }
    配置文件中 配置文件是绝对路径时 用:file

    第二种
    @PropertySource("classpath:/document.properties")

    public class MyConfig {
        @Value("${myconfig.index}")
        private String index;
    
        public String getIndex() {
           return index;
        }
    }
    classpath路径下就是可以用第二种方式

    springboot 文件加载顺序 一般默认加载application.propertise 或者 application.yml文件
    jar包目录下
    1.config
    2.jar同级目录
    class目录下
    3.config目录
    4.class同级目录
    相同属性 按照优先级最高的匹配

    另外:可以在启动命令中 加入 --spring.config.location 指定文件地址 多个文件用 ","隔开





  • 相关阅读:
    用css实现三角形
    css实现加载中的效果
    图片轮播图插件
    支付密码框
    angular里面ng-class的几个用法
    Redis数据恢复
    Jenkins简单介绍
    spring框架中定时器的配置及应用
    springMVC与freemarker的整合
    freemarker入门小例子
  • 原文地址:https://www.cnblogs.com/zxf330301/p/9282402.html
Copyright © 2011-2022 走看看