Description
Rob Winch opened SPR-13779 and commented
It would be nice to be able to allow Java Configuration to register multiple types of Beans. For example, right now the Spring Security exposes a Java DSL like this:
public void configure(HttpSecurity http) {
http
.formLogin()
}
This single invocation (made by the developer configuring Spring Security) should ideally create numerous Beans (i.e. UsernamePasswordAuthenticationFilter, AuthenticationEntryPoint, etc) and expose them to the Spring ApplicationContext.
The key takeaway is that a developer should be able to interact with a DSL where a single invocation creates multiple Beans.
This is something Juergen Hoeller and I spoke about briefly at SpringOne that I would like to get on the roadmap (hopefully for Spring 5).
Updated
To elaborate on my comment below, I think it would be nice if we could do something like this:
class MyDsl {
private boolean addABean;
private boolean addBBean;
// getters /setters
}
class MyDslXmlParser {
MyDsl parse(Document d) {
return createDls(d);
}
}
class MyDslParser {
public void registerBeans(MyDsl dsl, BeanFactory) {
if(dsl.isAddABean()) {
bf.registerBean(new A());
}
if(dsl.isAddBBean()) {
bf.registerBean(new B());
}
}
}
I Java Config Users could consume this with:
class JavaConfig {
@Bean
public MyDsl myDsl() {
MyDsl myDsl = new MyDsl();
myDsl.setAddABean(true);
return myDsl;
}
}
and MyDslParser.registerBeans
would automatically be invoked with the proper arguments.
In XML Config users could consume this with:
<mydsl:mydsl aBean="true" />
and MyDslParser.registerBeans
would automatically be invoked with the proper arguments.
This would allow the framework to easily support multiple ways of configuring the Beans.
Issue Links:
- Add a functional way to register a bean [SPR-14832] #19398 Add a functional way to register a bean ("depends on")
- Functional bean dependencies tracking [SPR-15417] #19979 Functional bean dependencies tracking ("depends on")
- New controller for Spring MVC using Lambda [SPR-12954] #17546 New controller for Spring MVC using Lambda
- easier framework support for the creation & injection of a bean by its class [SPR-4594] #9271 easier framework support for the creation & injection of a bean by its class
- Provide additional conditional registration capabilities in
BeanRegistrar
#21497 Support for conditional registration of functional bean definitions - Provide registerBean variants based on ResolvableType [SPR-15197] #18463 Provide registerBean variants based on ResolvableType
2 votes, 16 watchers