Set up an active profile in SpringBoot via Maven

I am trying to install an active profile in a Spring boot application using Maven 3.
In my pom.xml, I set the active active profile and property spring.profiles.active :

<profiles> <profile> <id>development</id> <properties> <spring.profiles.active>development</spring.profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles> 

but every time I run my application, I get the following message in the logs:

 No active profile set, falling back to default profiles: default 

and the SpringBoot profile is set by default (reads application.properties instead of application -development.properties)

What else should I do to get my active SpringBoot profile configured using the Maven profile?
Any help is much appreciated.

+6
source share
3 answers

The Maven profile and the Spring profile are two completely different things. Your pom.xml defines the variable spring.profiles.active , which is available at build time, but not at run time. This is why only the default profile is activated.

How to associate a Maven profile with Spring?

You need to pass the assembly variable to your application so that it is available when it is running.

  • Define the placeholder in application.properties :

     spring.profiles.active=@sprin g.profiles.active@ 

    The variable @ spring.profiles.active@ must match the declared property from the Maven profile.

  • Enable resource filtering in pom.xml:

     <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> โ€ฆ </build> 

    When the build is complete, all files in the src/main/resources directory will be processed by Maven, and the placeholder in your application.properties will be replaced by the variable you defined in your Maven profile.

For more information, you can go to my post where I described this use case.

+17
source

You should use the Spring Maven download plugin :

 <project> ... <build> ... <plugins> ... <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.5.1.RELEASE</version> <configuration> <profiles> <profile>foo</profile> <profile>bar</profile> </profiles> </configuration> ... </plugin> ... </plugins> ... </build> ... </project> 
+3
source

You can run the following command. Here I want to run using the spring local profile:

spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=local"

+3
source

Source: https://habr.com/ru/post/1015180/


All Articles