zoukankan      html  css  js  c++  java
  • Spring boot 如何读取jar包外面的properties文件

    先来张target跟目录的文件结构

    conf文件夹中存放的是properties文件,

    lib文件夹中存放的是各种jar文件,

    start.bat是windows命令行的启动文件。

    来张properties文件的内容

    1. 创建配置文件相关的配置类,每个properties文件对应一个配置类

    这里使用了@ConfigurationProperties,

    prefix是指properties文件中的前缀, 比如 asdf.name, 前缀就是asdf,  实体类中的name对应着asdf后面的name。

    locations是指的properties文件的地址,这里我用了file, 而不是classpath,  使用classpath总是出问题,不晓得为什么。  conf文件夹是因为start命令行是在target根目录,当前运行的目录就是target根目录。

    2. 在application类中添加@EnableConfigurationProperties

    有几个配置类,就要加几个类。

    3. 在要使用的地方导入

    4. 可以使用了

  • 相关阅读:
    git
    java网络
    配置本地git服务器(gitblit win7)
    atom 插件安装【转载】
    javaIo
    如何在eclipse中设置断点并调试程序
    如何将工程推到github上
    git操作记录
    编码
    node升级7.0以上版本使用gulp时报错
  • 原文地址:https://www.cnblogs.com/yfdream/p/6322116.html
Copyright © 2011-2022 走看看