0

I was trying to create a build for my production environment.In my spring web application, I have 4 .yml files

  1. application.yml
  2. application-development.yml
  3. application-staging.yml
  4. application-production.yml

In the application.yml file, I specified

spring:
  profiles:
    active: production

the command i am using maven to create a build is

mvn clean install tomcat7:deploy -B -Pproduction

In my target folder I can see all properties and my production settings in not come up.

What i am getting is my default application.yml properties. How to build correctly?

Karthik R
  • 5,523
  • 2
  • 18
  • 30
Shamseer PC
  • 787
  • 2
  • 9
  • 20
  • 3
    You shouldn't create a specific build for an environment. There is 1 build that you pass along. While starting the application you specify the profile(s) to activate. – M. Deinum Aug 31 '18 at 07:37
  • Consider looking into spring-cloud-config to easily manage configuration specific per environment. – Gimby Aug 31 '18 at 08:27
  • @M.Deinum in my tomcat $TOMCAT_HOME/bin/setenv.sh i added this option export CATALINA_OPTS="$CATALINA_OPTS -Dspring.profiles.active=production but it is also not working. i am moving a war to already running tomcat instance .do i need to do anything extra ? – Shamseer PC Aug 31 '18 at 10:00

1 Answers1

1

In your application.yml, add as follows:

spring:
  profiles:
    active: @active-profiles@

Then try :

mvn clean install tomcat7:deploy -B -P production

In pom.xml (The maven profile is passed during the mvn command - production profile which finds the property and replaces the ones in application.yaml by spring-boot-maven-plugin inbuilt in spring-boot-starter-parent)

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.RELEASE</version>
    <relativePath />
</parent>
.
.//Dependencies go here
.
<profiles>
        <profile>
            <id>production</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <active-profiles>production</active-profiles>
            </properties>
        </profile>
   </profiles>

More info here :

https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html

http://dolszewski.com/spring/spring-boot-properties-per-maven-profile/

Maven resource filtering not working - because of spring boot dependency

Karthik R
  • 5,523
  • 2
  • 18
  • 30
  • unable to add active: @active.profiles@.it is showing an error – Shamseer PC Aug 31 '18 at 09:32
  • I added more detailed answer. I assumed you already had configured maven profiles. Have a look at this to understand more : https://stackoverflow.com/questions/36501017/maven-resource-filtering-not-working-because-of-spring-boot-dependency – Karthik R Aug 31 '18 at 09:43