8

I want to use the feature-toggle paradigm. Specifically, I want my Spring contexts to contain different bean definitions based on a toggle.

I've come across this: http://robertmaldon.blogspot.com/2007/04/conditionally-defining-spring-beans.html, which looks ok, but maybe a bit too cumbersome

Ian Ringrose
  • 49,271
  • 50
  • 203
  • 302
IttayD
  • 25,561
  • 25
  • 109
  • 173

2 Answers2

4

You can use spring profiles - in short, you run your application with a profile setting, and the context contains different beans depending on that profile.

Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121
  • 1
    I think this is not a full solution. Unless I am reading things incorrectly, you can't mix multiple profiles. But you would want to mix multiple features in a feature-toggle solution. Right? – Synesso Feb 27 '13 at 00:54
  • EDIT: Seems Spring will let you set multiple profiles, but I still suspect having features == beans is not always going to be the right granularity, but its a start. – Synesso Feb 27 '13 at 01:03
3

I believe what you're actually looking for is a way for Spring to manage different configuration profiles.

Unfortunately, at the time of this writing, such a feature does not exist. As far as I know, people usually devise various schemes to get around that, but essentially use Spring's PropertyPlaceholderConfigurer to "inject" different runtime configurations into their property files by placing ${placeholder} into their Spring import statements and then dereferencing this placeholder as their enviroment changes (e.g. "DEV", "TEST", "PROD").

That will be changed by Spring 3.1, though - as it will introduce @Profile annotation which seems well coupled with Spring Java Configuration option, giving one a way to completely abandon XML configuration (should one choose to, of course).

Perhaps this article will shed more light into this: Spring 3.1 M1: Introducing @Profile

quantum
  • 2,681
  • 5
  • 37
  • 52