20

Given:

<beans ... namespace decelerations>
     <bean id="foo" class="com.example.foo" />
     <beans profile="abc">
         <bean id="bar" class="com.exmaple.bar" />
     </beans>
</bean>

what is the name of the profile that foo is registered under? Is there a way to override foo in another profile definition? Is there a name for the default profile in spring when a profile is not explicitly specified.

ams
  • 60,316
  • 68
  • 200
  • 288
  • 1
    possible duplicate of [Default profile in Spring 3.1](http://stackoverflow.com/questions/10041410/default-profile-in-spring-3-1) – Markus Malkusch Jan 11 '14 at 20:42

2 Answers2

24

Default profile in spring is "default", see this: https://jira.springsource.org/browse/SPR-8203

You can change the default profile in web.xml by doing this:

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

Command line:

-Dspring.profiles.default=production

Env variable:

export spring_profiles_default=production

If active profile is set, it overrides the default.

Solubris
  • 3,603
  • 2
  • 22
  • 37
5

Foo is simply registered under no profile, it will always be instantiate regardless of the profile you are using in that environment. Spring only allow to create multiple beans within an XML file with the same id if they are in different <beans> sets so I don't think that is possible to overwrite the Foo bean if it is not inside a <beans> tag with a profile.

If no profile are defined, Spring will use the profile named default. But, a bean that is not inside a <beans> tag with a profile will not be registered under that profile. It only means that if you have something like the following XML and that no profiles are provided, beans with the default profile will be loaded as well as beans with no profile.

<beans ... namespace decelerations>
     <bean id="foo" class="com.example.foo" />
     <beans profile="default">
         <bean id="bar" class="com.exmaple.bar" />
     </beans>
</bean>
Jean-Philippe Bond
  • 10,089
  • 3
  • 34
  • 60
  • Do you have a reference for this: "If no profile are defined, Spring will use the profile named default. " ? – Marko Vranjkovic Jul 18 '13 at 15:26
  • 3
    AbstractEnvironment and subclasses now register a reserved default profile named literally 'default' such that with no action on the part of the user, beans defined against the 'default' profile will be registered - if no other profiles are explicitly activated. https://jira.springsource.org/browse/SPR-8203 – Jean-Philippe Bond Jul 18 '13 at 15:42