Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven profiles or spring profiles?

a lot java applications are build with maven. maven has Profiles concept, it is really handy to build release package for different environments. e.g. dev/test/prod using different path / jndiname / security rule / properties files... I think I don't have to list codes here to explain it.

Spring is a very nice and popular framework for java development, since spring3 it has supported profiles concept too.

Now question comes, for releasing to different ENVs purpose, which one is better? right now I prefer maven profile. since spring has to copy each bean definition in each profile. and it needs an initializer/property to let spring know which profile should be actived.

but I feel spring profile is more flexible than maven profile.

what do you think? please give some advices. thank you.

like image 808
Kent Avatar asked Aug 08 '12 16:08

Kent


People also ask

Why profiles are used in Maven?

Profiles modify the POM at build time, and are used to give parameters different target environments (for example, the path of the database server in the development, testing, and production environments).

What are spring profiles used for?

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments. Any @Component or @Configuration can be marked with @Profile to limit when it is loaded: @Configuration @Profile("production") public class ProductionConfiguration { // ... }


2 Answers

Maven profiles would provide a build-time solution, while SpringFramework profiles would provide a runtime alternative. I think this is the first question one may ask himself: if he wants to have a single package that can be deployed in different environments, or if he wants the build tool to provide different packages according to the destination environment.

One thing to keep in mind is that many questions may arise if you have different packages deployed into different servers. In my workplace, for example, if I am deploying a package to correct a bug previously occurred in production environment, a company policy would state that the only acceptable scenario is that I have the same solution package in QA and in production servers.

like image 123
Filipe Fedalto Avatar answered Sep 19 '22 18:09

Filipe Fedalto


If you need different artifacts then go with maven. If it is just a real configuration that can be configured AFTER the artefact is build then user Spring profiles.

like image 44
Ralph Avatar answered Sep 20 '22 18:09

Ralph