• @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 指定文件地址 多个文件用 ","隔开





  • 相关阅读:
    配置 Sublime Text 用 Node.js 执行 JavaScript 程序
    KNN算法
    堆排序(heap sort)
    复原二叉树
    二叉树的广度优先遍历(层次遍历)
    二叉树(BT)相关
    BST(二叉搜索树)相关
    二叉树遍历(先序、中序、后序)
    排序算法
    查找算法
  • 原文地址:https://www.cnblogs.com/zxf330301/p/9282402.html
Copyright © 2020-2023  润新知