4

I have a project with 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 build the maven project with

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

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

However, the active profile is still dev.

What is the correct way to activate a spring profile on tc Server

SooCheng Koh
  • 2,271
  • 3
  • 21
  • 34

3 Answers3

1

Configuring Tomcat

  • defining context param in web.xml – that breaks “one package for all environments” statement. I don’t recommend that
  • defining system property -Dspring.profiles.active=your-active-profile

I believe that defining system property is much better approach. So how to define system property for Tomcat? Over the internet i could find a lot of advices like “modify catalina.sh” because you will not find any configuration file for doing stuff like that. Modifying catalina.sh is a dirty unmaintable solution. There is a better way to do that.

Just create file setenv.sh in Tomcat’s bin directory with content:

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

and it will be loaded automatically during running catalina.sh start or run.

Xstian
  • 8,184
  • 10
  • 42
  • 72
1

If you are running your app from with STS and the tc Server that comes with it, you can put the system property definition into the launch configuration of tc Server. Once you started up tc Server once, you can modify the lauch config via "Run Configurations...", select the one for Pivotal tc Server, go to the VM arguments and add the -Dspring.profiles.active=prod setting.

Since this is a runtime option, it doesn't have any effect while building the app via Maven (the clean install way you tried).

Martin Lippert
  • 5,988
  • 1
  • 15
  • 18
0

I don't know why the JAVA_OPTS method didn't work for me.

What does is adding spring.profiles.active=dev in /conf/catalina.properties

ihebiheb
  • 3,673
  • 3
  • 46
  • 55