开发者

Spring namespace handler to create multiple beans

开发者 https://www.devze.com 2023-03-27 10:16 出处:网络
I\'d like to create a namespace handler that creates more than开发者_如何学C one bean. I\'ve been reading the documentation and sample code here: http://static.springsource.org/spring/docs/2.0.x/refer

I'd like to create a namespace handler that creates more than开发者_如何学C one bean. I've been reading the documentation and sample code here: http://static.springsource.org/spring/docs/2.0.x/reference/extensible-xml.html

But that only describes binding one bean to one custom tag. I want something more like this:

<myns:drag-in-my-library-beans handler="appHandler" />

That results in the creation of lets say 4 beans from the library code, some of which need to make use of appHandler. Is this possible? I think the typical thing spring does for tags like this is:

<context:annotation-driven />

So insight on how that tag works internally might be helpful.


You must have missed this line: "BeanDefinition parse(Element, ParserContext) - called when Spring encounters a top-level element (not nested inside a bean definition or a different namespace). This method can register bean definitions itself and/or return a bean definition."

The "register bean definitions itself" would allow you to create an arbitrary number of beans from parsing a single element. See the parse() javadoc for more detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消