Skip to content

Support profile exclusivity and/or bean definition finality [SPR-7982] #12637

Closed
@spring-projects-issues

Description

@spring-projects-issues

Neale Upstone opened SPR-7982 and commented

There's a real opportunity to nail some corner cases with profiles, and conversely the risk of propagating some open-doors to bad practice.

Reading the example given at http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/, I can see a few areas I'd like to be explicit for fast failure:

  1. To be able to define valid (/invalid) profile combinations. In your example, you can specify "production,dev", which is clearly not what is intended, and all too easy to do when profiles are less obviously exclusive. This could be achieved by allowing profiles combinations to be specified in the application context.
  2. To be able to configure specific bean definition override behaviour, by 'final' bean defs and/or by an override flag. This could be done at the level of a bean or on the now nestable <beans> element. ** This would have saved a LOT of time on the project I've recently been working on, mainly due to the number of components developed by different teams with varying levels of Spring experience **

I quite like the idea of allowing some combination of final and override as it would give expressiveness to developers intent. <bean id='blah' override='true' ../> would not only clearly denote that override was intended, but also allow validation that there was already a bean to override.

Either of these suggestions would prevent the 'prod,dev' profile from being bootstrapped.

Examples would be:

<config>
  <profileOptions exclusive="production,dev,uat"/>
  <profileOptions exclusive="perf,trace"/>
</config>
<beans profile="production" final="true">
   ... jndi datasource bean defs
</beans>
<beans profile="dev" final="true">
   ... dev datasources
</beans>

Affects: 3.1 M1

Reference URL: http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/#comment-185086

Issue Links:

6 votes, 12 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions