java -jar . k-provider.jar --spring.profiles.active=test
本想用测试环境的配置文件运行项目可项目启动时一直是使用dev配置文件运行。
java -jar . k-provider.jar --spring.profiles.active=test
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/softwareWorkspace/hqtx/HqService/ServiceProvider/tk-provider/target/tk-provider.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/softwareWorkspace/hqtx/HqService/ServiceProvider/tk-provider/target/tk-provider.jar!/BOOT-INF/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
====================> : Spring Boot 初始化环境变量
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )\___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)
2018-08-23 16:14:48.494 INFO 349004 --- [ main] com.hq.tk.TkApplication : Starting TkApplication v1.0-SNAPSHOT on longqin with PID 349004 (D:softwareWorkspacehqtxHqServiceServiceProvider k-provider arget k-provider.jar started by Administrator in D:softwareWorkspacehqtxHqServiceServiceProvider k-provider arget)
2018-08-23 16:14:48.497 DEBUG 349004 --- [ main] com.hq.tk.TkApplication : Running with Spring Boot v2.0.4.RELEASE, Spring v5.0.8.RELEASE
2018-08-23 16:14:48.498 INFO 349004 --- [ main] com.hq.tk.TkApplication : The following profiles are active: dev
尝试了无数遍启动都是出现: The following profiles are active: dev,快要崩溃了。后来冷静想了想 命令行的参数是通过 main函数中的args参数接收的,立马去查看启动类,果然。
一开始的写法,springApplication.run 没有传入args参数
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(SsoApplication.class);
//监听生命周期
springApplication.addListeners(new SpringBootApplicationStartup());
springApplication.run();
}
更改
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(SsoApplication.class);
//监听生命周期
springApplication.addListeners(new SpringBootApplicationStartup());
springApplication.run(args);
}
再次打包运行,出现 :The following profiles are active: test
java -jar . k-provider.jar --spring.profiles.active=test
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/softwareWorkspace/hqtx/HqService/ServiceProvider/tk-provider/target/tk-provider.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/softwareWorkspace/hqtx/HqService/ServiceProvider/tk-provider/target/tk-provider.jar!/BOOT-INF/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
====================> : Spring Boot 初始化环境变量
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _
( ( )\___ | '_ | '_| | '_ / _` |
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.4.RELEASE)
2018-08-23 16:30:58.961 INFO 348708 --- [ main] com.hq.tk.TkApplication : Starting TkApplication v1.0-SNAPSHOT on longqin with PID 348708 (D:softwareWorkspacehqtxHqServiceServiceProvider k-provider arget k-provider.jar started by Administrator in D:softwareWorkspacehqtxHqServiceServiceProvider k-provider arget)
2018-08-23 16:30:58.964 DEBUG 348708 --- [ main] com.hq.tk.TkApplication : Running with Spring Boot v2.0.4.RELEASE, Spring v5.0.8.RELEASE
2018-08-23 16:30:58.966 INFO 348708 --- [ main] com.hq.tk.TkApplication : The following profiles are active: test
作者:神马不是神
链接:https://www.jianshu.com/p/24c090994829
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。