This is a spring boot rest project that handle the application properties per environment using Maven profiles.
There are two kind of profiles:
- Maven Profiles: A build-time approach.
clean install -Pdev
- Spring Profiles: A runtime approach.
java -jar -Dspring.profiles.active=dev xxx.jar
The answer depends on your requirements. A good rule of thumb:
If you need different artifacts then go with Maven profiles. If it is just a real configuration that can be set AFTER the artifact is built then go with Spring profiles.
Basically, Maven profiles would provide a build-time solution, while Spring profiles would provide a runtime alternative.
- Spring Boot 2.x (spring-boot-starter-web, spring-boot-starter-tomcat)
- Java 8
- Tomcat 8.5.x
- Maven 3.6.x
1. HTTP Method: GET
http://localhost:8080/mvnspringboot/params/all
- Activate Spring property files with Maven profiles: It replaces the placeholder for the spring.profiles.active variable with the active Maven profile at build time so the Spring framework, after starting your app, can load the appropriate configuration file based on the name of the active Spring profile.
- Maven copy-rename-maven-plugin plugin: The idea is to copy the complete specific profile file (dev.properties) to create the application properties inside the project output directory (application.properties). For this you need the help of Maven resources and Maven filtering. The best usage of this rename plugin is when you need a .json file or .txt file per environment.
- Automatic Property Expansion using Maven
- Spring Boot Relaxed Binding
- Spring Boot Externalized Configuration
- Spring Boot traditional deployment
- Spring Boot 2 - Release Notes
- Spring Boot 2.2 - Release Notes
- How to install Tomcat 8.x in AWS
- How to install Jenkins 2.x in AWS
- Configure Jenkins 2.x with Tomcat 8.x in AWS
- All the build phase is done correctly from Eclipse or CLI (Command Line Interface) for the 'dev' profile with the command 'clean install -Pdev'. The war file is created with the variables from the desired profile. If you deploy the war in a Tomcat container manually or using Jenkins it is going to work properly. The problem might arise when you deploy using Eclipse. There are some issues with the m2e plugin where even when you build with the -Pdev it takes the activeByDefault profile. It seems that Eclipse is ignoring the profile provided. In that case, right click to the project -> Properties -> Maven and set the active Maven profile.
I am Carlos Becerra - MSc. Softwware & Systems. But to tell you the truth, I'd prefer to be a passionate developer. You can contact me via:
Any improvement or comment about the project is always welcome! As well as others shared their code publicly I want to share mine! Thanks!
Copyright 2020 Carlos Becerra
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.