Details
-
Improvement
-
Status: Closed
-
Trivial
-
Resolution: Won't Fix
-
2.0.11.1
-
None
Description
The Spring plugin looks up Spring beans based on the fully qualified class name, and doesn't find Spring-managed Action classes configured by Spring annotations. (Spring 2.5 can automatically find annotated beans instead of using xml config). These annotated beans have short bean names, meaning "object" instead of java.lang.Object
Instead, the Spring plugin instantiates the bean itself and follows the autowire policy, but the bean is not managed by Spring.
Ultimate Goal:
Be able to use the Spring annotation config and the Struts Codebehind plugin to eliminate xml configuration in Struts and Spring, and yet still have Actions be fully Spring managed.
There are three current workarounds:
1) let the Spring plugin instantiate and autowire Actions as it does now, but can't use any AOP features for those Actions
2) configure the bean in struts.xml and provide the 'short' bean name as the class name
3) configure the bean in a spring xml file and don't specify an id (the default id is the fully qualified class name)
None of these workarounds provide the ultimate goal of zero xml configuration and full Spring integration.
Proposed fix:
Alter the Spring plugin to lookup the bean based on type instead of using the class as the bean name. It could use ListableBeanFactory#getBeansOfType(), and throw an exception if there is more than one bean for that Action class. This could be configurable by a Struts constant (like "struts.objectFactory.spring.lookup" whose values could be "byClass" or "byName"). The changes could go in SpringObjectFactory#buildBean(String, Map, boolean)