外部配置文件读取失败问题
-
可执行zip包的结构如下:
-
*.zip
-
*.jar
-
license:
- license.dat
-
-
-
license:
- license.dat
-
-
期望:程序启动,读取Jar外部的
license/license.dat -
结果:程序启动,读取了
*.jar文件内部的license/license.dat -
解决:
- 打包时,不要将
license/license.dat打进Jar包 - 指定路径,保证外部的
license/license.dat能够被读取
- 打包时,不要将
打包不包含license/license.dat
在pom.xml中,添加如下配置
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<excludes>
<exclude>license/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
指定外部路径
在application.yml中增加如下配置:
server:
# address: ${spring.cloud.client.ip-address}
port: 7090
tongweb:
license:
type: file
# license文件所在路径
path: ./license/license.dat
指向相对于Jar文件的相对路径,而不使用原先的classpath:license/license.dat读取上下文中的文件。