Giter Site home page Giter Site logo

mavenprofilespringboot's Introduction

Maven profiles per environment with Spring Boot 2.x

This is a spring boot rest project that handle the application properties per environment using Maven profiles.

Which Profile?

There are two kind of profiles:

  1. Maven Profiles: A build-time approach.
clean install -Pdev
  1. 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.

Technologies

  1. Spring Boot 2.x (spring-boot-starter-web, spring-boot-starter-tomcat)
  2. Java 8
  3. Tomcat 8.5
  4. Maven

Exposed methods to test that it works

1. HTTP Method: GET

http://localhost:8080/mvnspringboot/params/all

Other Alternatives (Examples)

  • 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.

Useful Documentation

Additional Useful Links

Troubleshooting

  • 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.

About me

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!

License

Copyright 2019 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.

mavenprofilespringboot's People

Contributors

carloscharz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.