The Maven profile and the Spring profile are two completely different things. Your pom.xml defines spring.profiles.active
variable which is available in the build process, but not at runtime. That is why only the default profile is activated.
How to bind Maven profile with Spring?
You need to pass the build variable to your application so that it is available when it is started.
- Define a placeholder in your
application.properties
:[email protected]@
The@spring.profiles.active@
variable must match the declared property from the Maven profile. - Enable resource filtering in you pom.xml:
<build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> … </build>
When the build is executed, all files in thesrc/main/resources
directory will be processed by Maven and the placeholder in yourapplication.properties
will be replaced with the variable you defined in your Maven profile.
For more details you can go to my post where I described this use case.
Related Posts:
- Spring @PropertySources value not overriding
- Spring boot – Request method ‘POST’ not supported. Tried everything
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- How to resolve Unable to load authentication plugin ‘caching_sha2_password’ issue
- java.lang.IllegalStateException: Failed to introspect Class
- Spring boot: Unable to start embedded Tomcat servlet container
- Eclipse/Maven error: “No compiler is provided in this environment”
- Spring Boot – Unable to resolve Whitelabel Error Page
- How is “mvn clean install” different from “mvn install”?
- Understanding Spring @Autowired usage
- com.atomikos.icatch.SysException: Error in init: Log already in use? tmlog in ./
- Lombok and Maven
- HTTP Status 405 – Request method ‘POST’ not supported (Spring MVC)
- “NoClassDefFoundError: Could not initialize class” error
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘MyController’:
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- No String-argument constructor/factory method to deserialize from String value (”)
- Why Maven project is tied to J2SE-1.5 by default?
- “NoClassDefFoundError: Could not initialize class” error
- “NoClassDefFoundError: Could not initialize class” error
- Error creating bean with name ‘entityManagerFactory’ defined in class path resource : Invocation of init method failed
- What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
- Difference between spring @Controller and @RestController annotation
- @Autowired – No qualifying bean of type found for dependency
- HTTP Status 405 – Request method ‘POST’ not supported (Spring MVC)
- unused import statement for used ones in IntelliJ IDEA
- How to resolve Error listenerStart when deploying web-app in Tomcat 5.5?
- Maven: Failed to read artifact descriptor
- com.sun.jdi.InvocationException occurred invoking method
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘demoRestController’
- UnsatisfiedDependencyException: Error creating bean with name
- UnsatisfiedDependencyException: Error creating bean with name
- Only using @JsonIgnore during serialization, but not deserialization
- What exactly is a Maven Snapshot and why do we need it?
- Cannot change version of project facet Dynamic Web Module to 3.0?
- Maven error : Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
- Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]
- Why SpringMVC Request method ‘GET’ not supported?
- Error: JAVA_HOME is not defined correctly executing maven
- intellij incorrectly saying no beans of type found for autowired repository
- Web server failed to start. Port 8080 was already in use. Spring Boot microserviceWeb server failed to start. Port 8080 was already in use. Spring Boot microservice
- Could not resolve placeholder in string value
- Web server failed to start. Port 8080 was already in use. Spring Boot microservice
- JAVA_HOME should point to a JDK not a JRE
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- Is spring default scope singleton or not?
- How to solve the “failed to lazily initialize a collection of role” Hibernate exception
- MultipartException: Current request is not a multipart request
- How are “mvn clean package” and “mvn clean install” different?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- “The import org.springframework cannot be resolved.”
- What is the proper annotation since @SpringApplicationConfiguration, @WebIntegration, is deprecated in Spring Boot Framework?
- JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object
- “Source folder is not a Java project” error in eclipse
- Downloading a file from spring controllers
- Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven
- The request was rejected because no multipart boundary was found in springboot
- Maven dependency update on commandline
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- when spring boot startup,throw out the “method names must be tokens” exception
- model.addAttribute() parameters
- How do I enable index downloads in Eclipse for Maven dependency search?
- Spring Boot – Cannot determine embedded database driver class for database type NONE
- What does Java option -Xmx stand for? [duplicate]
- How do I convert a String to an int in Java?
- What does Java option -Xmx stand for? [duplicate]
- Is there an invisible character that is not regarded as whitespace?
- Problem with gif with transparent background
- Finding white rectangle in an image
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- How to convert nanoseconds to seconds using the TimeUnit enum?
- Search for words with telephone numbers from 2-3-4 tree
- Using or ‘|’ in regex [duplicate]
- How to format strings in Java
- What is the difference between x86 and x64
- && (AND) and || (OR) in IF statements
- How to use the toString method in Java?
- What is a NullPointerException, and how do I fix it?
- What exactly is Apache Camel?
- Unable to find valid certification path to requested target – error even after cert imported
- Unable to find valid certification path to requested target – error even after cert imported
- What is the equivalent of the C++ Pair
in Java? - Java – Convert integer to string [duplicate]
- Getting random numbers in Java [duplicate]
- What is an instance variable in Java?
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- javac is not recognized as an internal or external command, operable program or batch file [closed]
- Java: “error: cannot find symbol”
- How does the Java ‘for each’ loop work?
- What is a StackOverflowError?
- How to uninstall Eclipse?
- Is GNU’s Java Compiler (GCJ) dead? [closed]
- How does System.out.print() work?
- How do I “decompile” Java class files? [closed]
- How do I determine whether an array contains a particular value in Java?
- How to initialize an array in Java?