Java Spring boot with maven. How to configure profiles?

74 Views Asked by At

I have problem with setting profiles in my spring boot app. I use java with react and currently am learning how to deploy app to aws. For development I was using docker image of postgres db and this config file (application.yml):

app:
  datasource:
    jdbc-url: jdbc:postgresql://localhost:5432/karatesandemo
    username: username
    password: password
    pool-size: 30

For my aws db I had to make diffrent configuration, so i made another file (application-prod.yml):

server:
  port: 5000
app:
  datasource:
    jdbc-url: jdbc:URL:5432/karatesandemo
    username: username
    password: password
    pool-size: 30

And this is my pom.xml profile:

 <profiles>
    <profile>
    <id>prod</id>
        <properties>
            <spring.profiles.active>prod</spring.profiles.active>
        </properties>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>1.9.1</version>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <workingDirectory>${frontend.src.directory}</workingDirectory>
                            <installDirectory>${project.build.directory}</installDirectory>
                        </configuration>
                        <executions>
                            <execution>
                                <id>install node</id>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                                <phase>generate-resources</phase>
                            </execution>
                            <execution>
                                <id>npm-install</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>build-ui</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>run build</arguments>
                                </configuration>
                                <phase>prepare-package</phase>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>add-react-build</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <outputDirectory>${project.build.outputDirectory}/static</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${frontend.src.directory}/build</directory>
                                            <filtering>false</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>

            </build>
    </profile>
    </profiles>

Problem is when i want to install it with mvn clean install -Pprod. it keeps taking application.yml configuration (No active profile set, falling back to 1 default profile: "default").

I've been trying to fiddle with adding :

spring:
  profiles:
    active: @spring.profiles.active@

To application.yml files and it stayed same. What works for me is deleting it from application-prod.yml and leaving it in application.yml. Only this way it works. Can someone explain this to me?

0

There are 0 best solutions below