Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature toggle in spring context

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

like image 409
IttayD Avatar asked Oct 09 '11 09:10

IttayD


People also ask

What is meant by feature toggle?

Feature toggles, also known as feature flags, are components of software development that allow specific features of an application to be activated or deactivated at will. This allows developers to safely “toggle” new features on or off for testing.

Why do we need feature toggle?

A feature flag approach could use any of these methods to separate code paths in different phases of development. The main usage of feature toggles is to avoid conflict that can arise when merging changes in software at the last moment before release, although this can lead to toggle debt.

What is feature toggle Java?

Feature Toggles are a very common agile development practices in the context of continuous deployment and delivery. The basic idea is to associate a toggle with each new feature you are working on. This allows you to enable or disable these features at application runtime, even for individual users.


2 Answers

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.

like image 171
Bozho Avatar answered Nov 02 '22 20:11

Bozho


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

like image 40
quantum Avatar answered Nov 02 '22 21:11

quantum