There are multiple ways to configure Spring profile in tomcat. Let’s see here.
How to Configure Spring Profile in Tomcat:
If you are running the application in your local, you can set the active profile using -Dspring-boot.run.profiles=test/dev/prod
property as a parameter to your maven or Gradle run command.
Example:
#maven
mvnw spring-boot:run -Dspring-boot.run.profiles=dev
#Gradle
gradlew bootRun -Dspring-boot.run.profiles=dev
Eclipse Tomcat:
To configure the same in Eclipse tomcat, select Run -> Run Configurations and choose your Tomcat run configuration. Click the Arguments tab and add -Dspring.profiles.active=dev
at the end of VM arguments.
External Tomcat:
Again you can have multiple options here to configure Spring profile in tomcat in the external config, the most prominent way is to set the profile in catalina.properties
.
catalina.properties
Add profile in catalina.properties file by omitting -D
spring.profiles.active=dev
Run the tomcat:
./startup.sh
ed JARs during scanning can improve startup time and JSP compilation time.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.4.RELEASE)
2020-05-05 08:02:13.992 INFO 192322 --- [ main] c.s.SampleApplication : Starting SampleApplication v0.0.1-SNAPSHOT on localhost.localdomain with PID 192322 (/opt/cgoka/tomcat/webapps/sample_application/WEB-INF/classes started by root in /root)
2020-05-05 08:02:13.996 INFO 192322 --- [ main] c.s.SampleApplication : The following profiles are active: dev
Now you can see the log message “The following profiles are active: dev” like above.
References:
Happy Learning 🙂