How can a Struts plugin get references to beans contained
in a Spring context?
I don’t want to use any Spring-specific classes in this plugin.
Any helps are appreciated.
How can a Struts plugin get references to beans contained
in a Spring context?
I don’t want to use any Spring-specific classes in this plugin.
Any helps are appreciated.
Take a look at the source code of WebApplicationContextUtils and copy the getWebApplicationContext functionality to your plugin.
Kees de Kooter
www.boplicity.net
Thanks for your reply.Originally Posted by Kees de Kooter
But I don’t want to use any Spring-specific classes in this plugin.
Not sure what you can do then
You could abstract it with an interface:
and then have one implementation which uses Spring etc.Code:interface BeanLoader { Object loadBean(final String name); }
The only dependency in your structs action would be on the SpringBeanLoader, which is a single line.
HTH.
Hi,
Anyone has a better solution injecting bean in struts plugin without importing spring API.
Thx
Anan
Hi Anan,
Generally one component will need to know about/ and be able to find the other, in order to set any reference between them.
You can definitely achieve this; but it's not quite as easy as working solely in Spring. One bean/ action will be in Struts and hard to find from Spring; the other will be in Spring and hard to find from Struts.
Order of initialization issues will also apply; it won't work if you try to set the reference at init-time, since one or the other side will still be uninited and nonexistent.
Probably simplest: implement a static singleton class as a 'registry' which one side can set; and the other side can read later. This then decouples you from the Spring API, and from order-of-init issues.
Any other solutions ?
Cheers
T