Spring boot App Using Maven, build with EnvFile

52 Views Asked by At

I started to use maven to create a Spring boot app.

I wan't to deploy the project using maven commands. Here is my file application.properties

spring.config.import=optional:file:env.properties
spring.datasource.url=${DATA_SOURCE_URL}
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
jwt.secret = ${SECRET}

As you can see I import a file named env.properties, however I wan't to import it every time I use the mvn clean install command.

Can you help me to find the correct command or to configure my pom.xml plugins ?

1

There are 1 best solutions below

0
On

Here you are:

To import application properties from pom.xml file you have to:

Set the name of the parameter and value in <properties> tag:

<properties>
    <spring.active.profile>conf</spring.active.profile>
</properties>

And second one you have to add spring-boot-maven-plugin and resource that point to application.properties.

<build>
        <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>
                <includes>
                    <include>application.properties</include>
                </includes>
            </resource>
        </resources>
    </build> 

And after it in application.properties file you will able to access the parameter as next one:

[email protected]@

Also if you didn't like this approach you could use Properties Maven Plugin