resources下创建多个application.properties
application.properties
server.port=8888
imagesPath=src/main/resources/static/asserts/images/
application-dev.properties
server.port=8889
imagesPath=src/main/resources/static/asserts/images/dev/
application-test.properties
server.port=8890
imagesPath=src/main/resources/static/asserts/images/test/
test.java
public class test {
/**
* 图片存储路径
*/
@Value("imagesPath")
private String imagesPath;
}
jar包运行命令
java -jar test.jar
java -jar test.jar --spring.profiles.active=test
java -jar test.jar --spring.profiles.active=dev
idea启动在Enviromment下的Enviromment variables添加–spring.profiles.active=test


本文详细介绍如何在Spring Boot项目中使用多个application.properties文件来配置不同环境的参数,包括开发(dev)、测试(test)和生产环境。通过在resources目录下创建application-dev.properties、application-test.properties等,可以轻松实现环境变量的切换。文章还提供了Java代码示例,展示如何在程序中读取这些配置,并给出了在不同环境下运行项目的命令。
733

被折叠的 条评论
为什么被折叠?



