I have a Spring Boot App running in Azure asapp service, and I would like to add a JVM Arg (-Dspring.profiles.active=dev)
I already tried it using as environmental variable in azure as mentioned in different tutorials, but it has not been read.
Does anyone has a working solution?
As mentioned in MSDOC, arguments can be provided to the JVM by using the application settings:
1. JAVA_OPTS
2. languageWorkers__java__arguments
I have created a Spring boot application and deployed to Azure App Service.
Local Response:
2024-09-27T14:42:27.100+05:30 INFO 19928 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.11 with PID 19928
2024-09-27T14:42:27.100+05:30 INFO 19928 --- [ main] com.example.demo.DemoApplication : The following 1 profile is active: "dev"
2024-09-27T14:42:29.641+05:30 INFO 19928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-09-27T14:42:29.674+05:30 INFO 19928 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2024-09-27T14:42:29.674+05:30 INFO 19928 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.30]
2024-09-27T14:42:29.782+05:30 INFO 19928 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2024-09-27T14:42:29.798+05:30 INFO 19928 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2530 ms
2024-09-27T14:42:30.884+05:30 INFO 19928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2024-09-27T14:42:30.931+05:30 INFO 19928 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 4.977 seconds (process running for 6.198)
Active profile: dev
App Service logs before configuring the Active Profile, web app used the default profile:
.. com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.12 with PID 94 (/home/site/wwwroot/app.jar started by root in /home/site/wwwroot)
.. com.example.demo.DemoApplication : No active profile set, falling back to 1 default profile: "default"
.. o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
.. w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 23576 ms
.. o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
.. com.example.demo.DemoApplication : Started DemoApplication in 50.272 seconds (process running for 115.141)
Configured the JVM Argument -Dspring.profiles.active=dev
using JAVA_OPTS
under App Service=>Settings=>Environment Variables=>App Settings:
The Active profile set to dev can be seen in the App Service logs:
2024-09-27T08:34:59.826Z INFO 93 --- [main] com.example.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 17.0.12 with PID 93 (/home/site/wwwroot/app.jar started by root in /home/site/wwwroot)
2024-09-27T08:34:59.972Z INFO 93 --- [main] com.example.demo.DemoApplication : The following 1 profile is active: "dev"
2024-09-27T08:35:23.825Z INFO 93 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2024-09-27T08:35:25.304Z INFO 93 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 24323 ms
2024-09-27T08:35:37.365Z INFO 93 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2024-09-27T08:35:37.674Z INFO 93 --- [main] com.example.demo.DemoApplication : Started DemoApplication in 55.119 seconds (process running for 92.024)
2024-09-27T08:35:39.475Z INFO 93 --- [http-nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2024-09-27T08:35:39.511Z INFO 93 --- [http-nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms