blue-sky
blue-sky

Reputation: 53806

Default spring profile?

To read a Spring profile I use :

<beans profile="LOC">

I have this property set as a jvm property :

-Dspring.profiles.active=LOC

Is it possible to use some logic just use the profile "LOC" if it exists and it does not exist use a default profile ?

Upvotes: 3

Views: 598

Answers (2)

Wojciech G&#243;rski
Wojciech G&#243;rski

Reputation: 943

This is possible in spring 3.2, where the ! operator has been introduced:

<beans profile="LOC">
    <import resource="LOC.xml"/>
</beans>
<beans profile="!LOC">
    <import resource="default.xml"/>
</beans>

LOC.xml will be included when the LOC profile is active. default.xml will be included if LOC is not defined.

The change has been announced here: http://www.springsource.org/node/3563
and the commit is here: https://github.com/SpringSource/spring-framework/commit/bcd44f3798ed06c0704d2a3564b8a9735e747e87

Upvotes: 3

d0x
d0x

Reputation: 11571

If you have a web.xml you can specify it there:

<context-param>
   <param-name>spring.profiles.default</param-name>
   <param-value>LOC</param-value>
</context-param>

Otherwise you can try to use the org.springframework.context.ApplicationContextInitializer. See: http://blog.chariotsolutions.com/2012/01/spring-31-cool-new-features.html

Is this enough for you?

Upvotes: 2

Related Questions