Default profile in Spring 3.1

java, profiles, spring

Solution

My experience is that using

@Profile("default")

the bean will only be added to the context if no other profile is identified. If you pass in a different profile, e.g. `-Dspring.profiles.active="demo"`, this profile is ignored.

Problem

In my application I have beans annotated with `@Profile("prod")` and `@Profile("demo")`. The first one, as you can guess :), is used on beans that connect to production DB and second one annotates beans that use some fake DB (`HashMap` or whatever)- to make development faster. What I would like to have is default profile (`"prod"`) that will be used always if it is not overridden by "something-else". Perfect would be to have in my `web.xml`: ``` <context-param> <param-name>spring.profiles.active</param-name> <param-value>prod</param-value> </context-param> ``` and then override this with `-Dspring.profiles.active="demo"` so that I could do: ``` mvn jetty:run -Dspring.profiles.active="demo". ``` But sadly this is not working. Any idea how could I achive that? Setting `-Dspring.profiles.active="prod"` on all my environments is not an option.

Original source