在springboot项目中,运行jar包时使用 java -jar xxx.jar --spring.profiles.active=test ,但是并没有走bootstrap-test.yml文件。而使用java -jar -Dspring.profiles.active=test xxx.jar 是可以走bootstrap-test.yml文件的。
原因是在启动类里的run方法没有把args参数加上。
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
加上args参数就可以了。
本文揭示了在SpringBoot项目中如何正确使用`java-jar`启动jar包时`spring.profiles.active`配置的问题,指出未包含args导致bootstrap-test.yml未生效,并提供了解决方案,即在启动类`main`方法中加入args参数。
3117

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



