java -jar .\tk-provider.jar --spring.profiles.active=test
本想用測試環境的配置文件運行項目可項目啓動時一直是使用dev配置文件運行。javascript
java -jar .\tk-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:\softwareWorkspace\hqtx\HqService\ServiceProvider\tk-provider\target\tk-provider.jar started by Administrator in D:\softwareWorkspace\hqtx\HqService\ServiceProvider\tk-provider\target) 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參數接收的,立馬去查看啓動類,果真。html
一開始的寫法,springApplication.run 沒有傳入args參數java
public static void main(String[] args) { SpringApplication springApplication = new SpringApplication(SsoApplication.class); //監聽生命週期 springApplication.addListeners(new SpringBootApplicationStartup()); springApplication.run(); }
更改spring
public static void main(String[] args) { SpringApplication springApplication = new SpringApplication(SsoApplication.class); //監聽生命週期 springApplication.addListeners(new SpringBootApplicationStartup()); springApplication.run(args); }
再次打包運行,出現 :The following profiles are active: testide
java -jar .\tk-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:\softwareWorkspace\hqtx\HqService\ServiceProvider\tk-provider\target\tk-provider.jar started by Administrator in D:\softwareWorkspace\hqtx\HqService\ServiceProvider\tk-provider\target) 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