Create bean in spring
Hello !
Can anyone point me the possibility of adding new bean into Spring application context.
I'm interested in some API call of bundled spring plugin.
Idea is provide a intention action for my plugin to create spring beans when Spring Facet is configured in my project.
I realize that this can be done manually by patching XML, but maybe there's more convenient way of doing this ?
请先登录再写评论。
Evgeny Shepelyuk wrote:
You can do it using DOM, maybe this would be a little more convenient.
Get SpringModel for this file from SpringManager#getLocalSpringModel,
get the DOM root of type Beans
(SpringModel.getRoots().get(0).getRootElement()), call addBean() there
and tune the resulting object as you wish (for example,
getId().setStringValue("foo")).
Thanx for information. Though i can not find those calls in my version of IDEA/Spring plugin. I will keep searching that direction.
What's your version? SpringManager and Beans were in the IDEA-bundled
Spring plugin for ages.
IDEA build - > 7935
Spring plugin from same build
1. SpringManager.getInstance(Project).getLocalSpringModel(XmlFile)
need some XmlFile
where i should take it ?
2.
>>get the DOM root of type Beans
>>(SpringModel.getRoots().get(0).getRootElement()), call addBean() there
Interface SpringModel doesn't have method getRoots()
Edited by: Evgeny Shepelyuk on Aug 12, 2008 8:40 PM
You know where to add your bean (which file should it be), don't you?
That's it.
>>> get the DOM root of type Beans
>>> (SpringModel.getRoots().get(0).getRootElement()), call addBean() there
SpringModel extends DomModel, which has
List>]]> getRoots();
Or not?
No i don't' know. That's the idea of my question. Is there any API to call it and let it decide where inject new bean declarion.
So as i see there's no way except patching XML.
Yes you're 100% correct.
Thnx for your help !
>>
>> You know where to add your bean (which file should it be), don't you?
>> That's it.
If you know how to patch XML you should know the file to patch it in.
And then if you want you can use DomElement's.
As for letting decide, you should do it yourself, or let the user do it.
There is SpringManager#getAllModels(Module) that will give you all
Spring config files visible from particular module, this should help.
thnx 4 help !