-1

This is my properties file where i have added this variable databaseEnabled=${db.activedb}

Path of my properties file src/main/resources/application-dev.properties

This is my pom.xml where I have added this code

<build>
    <finalName>spring-boot</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>dynamo</id>
        <activation>
            <property>
                <name>env</name>
                <value>dynamo</value>
            </property>
        </activation>
        <properties>
            <db.activedb>dynamodb</db.activedb>
        </properties>
    </profile>
    <profile>
        <id>mongo</id>
        <activation>
            <property>
                <name>env</name>
                <value>mongo</value>
            </property>
        </activation>
        <properties>
            <db.activedb>mongodb</db.activedb>
        </properties>
    </profile>
</profiles>
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56

1 Answers1

0

Add includes tag:

<resource>
    <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>/application-dev.properties</include>
        </includes>
    </resource>
</resource>

To set profile using -P option:

mvn package -P mongo

To check result open target/classes/application.properties file.

Nick
  • 3,691
  • 18
  • 36
  • it's okay but when i try to access in my code like @Value("${databaseEnabled}") private String databaseEnabled;i get Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'db.activedb' in string value "${db.activedb}" – Kumod Sharma Apr 03 '17 at 13:17