Spring profile not activated on STS tc server

I have a project with a Spring profile

In my web.xml I have

<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>dev</param-value>
</context-param>

      

to set the default Spring profile.

I am creating a maven project with

clean install -Dspring.profiles.active="prod"

      

Then I choose Run As -> Run on Server option to deploy the maven project to the tc server.

However, the active profile is still dev.

What is the correct way to activate a Spring profile on a tc server

+3


source to share


2 answers


If you run your application with STS and the tc server that comes with it, you can put a system property definition in the tc Server startup configuration. After you have started the tc Server once, you can change the lauch configuration via "Run Configurations ...", select the one for the Pivotal tc Server, go to the VM arguments and add the -Dspring.profiles.active = prod parameter.



Since this is a runtime option, it has no effect when building the application through Maven (the clean install path you tried).

+1


source


Tomcat setup

  • defining the context parameter in web.xml - this breaks the "one package for all environments" statement. I do not recommend this
  • defining the system property -Dspring.profiles.active = your-active profile

I find that defining a system property is much better suited. So how do I define a system property for Tomcat? On the Internet I could find a lot of advice like "modify catalina.sh" because you won't find any configuration file for doing this. Modifying catalina.sh is a messy inherent solution. There is a better way to do this.



Just create setenv.sh file in Tomcats bin directory with content:

JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active="prod"

      

and it will be loaded automatically when Catalina.sh starts or starts.

+1


source







All Articles