首页 > 代码库 > Spring boot 如何读取jar包外面的properties文件
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. 可以使用了
Spring boot 如何读取jar包外面的properties文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。