- SpringBoot version: 2.5.0
2.Environment Variable Prefixes
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.5-Release-Notes#environment-variable-prefixes
3.
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication application = new SpringApplication(MyApp.class);
application.setEnvironmentPrefix("myapp");
application.run(args);
}
}
4.the application.properties
myapp.server.port=8000
- but the server port is 8080(default) or not 8000(myapp.server.port)
021-05-22 21:33:44.323 INFO 9759 --- [ main] noxus.com.draven.prefix.MyApp : Starting MyApp using Java 1.8.0_231 on draven with PID 9759 (/Users/draven/Documents/documents/java/documents/draven-springboot/noxus-draven-springboot-2.5.x/noxus-draven-2.5.x-prefix/target/classes started by draven in /Users/draven/Documents/documents/java/documents/draven-springboot)
2021-05-22 21:33:44.326 INFO 9759 --- [ main] noxus.com.draven.prefix.MyApp : No active profile set, falling back to default profiles: default
2021-05-22 21:33:44.936 INFO 9759 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2021-05-22 21:33:44.943 INFO 9759 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-05-22 21:33:44.943 INFO 9759 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.46]
2021-05-22 21:33:44.991 INFO 9759 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2021-05-22 21:33:44.991 INFO 9759 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 632 ms
2021-05-22 21:33:45.243 INFO 9759 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-05-22 21:33:45.251 INFO 9759 --- [ main] noxus.com.draven.prefix.MyApp : Started MyApp in 5.137 seconds (JVM running for 38.743)
2021-05-22 21:33:45.252 INFO 9759 --- [ main] o.s.b.a.ApplicationAvailabilityBean : Application availability state LivenessState changed to CORRECT
Comment From: snicoll
@maoxiaoxiong adding a property in application.properties
does not constitute a system environment variables. This feature is limited to those as the focus is to be used when several Spring Boot apps are running in the same OS environment.