How to integrate spring beans and struts2?
Given below is the stack trace and I have been stuck with this problem for long time now, from the trace i could just make out that there was some problem in properly wiring up spring bean with struts for dependency injection using maven as the build tool. Here baseAction i开发者_开发知识库f the name of the ACTION class.
2011-07-09 21:28:52,766 DEBUG [CommonsLogger.java:57] : Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@fdb413], property=struts]
2011-07-09 21:28:52,767 DEBUG [CommonsLogger.java:57] : Creating an DefaultActionProxy for namespace / and action name base
2011-07-09 21:28:52,768 DEBUG [DefaultListableBeanFactory.java:385] : No bean named 'com.app.action.BaseAction' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@169df00: defining beans [userService]; root of factory hierarchy
2011-07-09 21:28:52,769 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'actionErrors' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:52,769 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'actionMessages' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:52,770 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'fieldErrors' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:52,770 DEBUG [AbstractBeanFactory.java:214] : Returning cached instance of singleton bean 'userService'
2011-07-09 21:28:52,771 DEBUG [AbstractAutowireCapableBeanFactory.java:1033] : Added autowiring by name from bean name 'com.app.action.BaseAction' via property 'userService' to bean named 'userService'
2011-07-09 21:28:52,771 DEBUG [CommonsLogger.java:57] : intercept '//base' {
2011-07-09 21:28:52,772 DEBUG [CommonsLogger.java:57] : applied invocation context locale=en_US
2011-07-09 21:28:52,772 DEBUG [CommonsLogger.java:57] : before Locale=en_US
2011-07-09 21:28:52,772 DEBUG [CommonsLogger.java:57] : cannot find method [prepareExecute] in action [com.app.action.BaseAction@10812ac]
2011-07-09 21:28:52,773 DEBUG [CommonsLogger.java:57] : cannot find method [prepareDoExecute] in action [com.app.action.BaseAction@10812ac]
2011-07-09 21:28:52,773 DEBUG [CommonsLogger.java:57] : Setting static parameters {}
2011-07-09 21:28:52,774 DEBUG [CommonsLogger.java:57] : Setting params NONE
2011-07-09 21:28:52,774 DEBUG [CommonsLogger.java:57] : Setting params
2011-07-09 21:28:52,775 DEBUG [CommonsLogger.java:57] : Invoking validate() on action com.app.action.BaseAction@10812ac
2011-07-09 21:28:52,776 DEBUG [CommonsLogger.java:57] : cannot find method [validateExecute] in action [com.app.action.BaseAction@10812ac]
2011-07-09 21:28:52,776 DEBUG [CommonsLogger.java:57] : cannot find method [validateDoExecute] in action [com.app.action.BaseAction@10812ac]
2011-07-09 21:28:52,777 DEBUG [CommonsLogger.java:57] : Executing action method = null
2011-07-09 21:28:55,023 DEBUG [CommonsLogger.java:57] : Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@fdb413], property=struts]
2011-07-09 21:28:55,024 DEBUG [CommonsLogger.java:57] : Creating an DefaultActionProxy for namespace / and action name base
2011-07-09 21:28:55,024 DEBUG [DefaultListableBeanFactory.java:385] : No bean named 'com.app.action.BaseAction' found in org.springframework.beans.factory.support.DefaultListableBeanFactory@169df00: defining beans [userService]; root of factory hierarchy
2011-07-09 21:28:55,025 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'actionErrors' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:55,026 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'actionMessages' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:55,026 DEBUG [AbstractAutowireCapableBeanFactory.java:1039] : Not autowiring property 'fieldErrors' of bean 'com.app.action.BaseAction' by name: no matching bean found
2011-07-09 21:28:55,027 DEBUG [AbstractBeanFactory.java:214] : Returning cached instance of singleton bean 'userService'
2011-07-09 21:28:55,027 DEBUG [AbstractAutowireCapableBeanFactory.java:1033] : Added autowiring by name from bean name 'com.app.action.BaseAction' via property 'userService' to bean named 'userService'
2011-07-09 21:28:55,028 DEBUG [CommonsLogger.java:57] : intercept '//base' {
2011-07-09 21:28:55,029 DEBUG [CommonsLogger.java:57] : applied invocation context locale=en_US
2011-07-09 21:28:55,029 DEBUG [CommonsLogger.java:57] : before Locale=en_US
2011-07-09 21:28:55,030 DEBUG [CommonsLogger.java:57] : cannot find method [prepareExecute] in action [com.app.action.BaseAction@b17e0a]
2011-07-09 21:28:55,031 DEBUG [CommonsLogger.java:57] : cannot find method [prepareDoExecute] in action [com.app.action.BaseAction@b17e0a]
2011-07-09 21:28:55,031 DEBUG [CommonsLogger.java:57] : Setting static parameters {}
2011-07-09 21:28:55,032 DEBUG [CommonsLogger.java:57] : Setting params NONE
2011-07-09 21:28:55,032 DEBUG [CommonsLogger.java:57] : Setting params
2011-07-09 21:28:55,037 DEBUG [CommonsLogger.java:57] : Invoking validate() on action com.app.action.BaseAction@b17e0a
2011-07-09 21:28:55,037 DEBUG [CommonsLogger.java:57] : cannot find method [validateExecute] in action [com.app.action.BaseAction@b17e0a]
2011-07-09 21:28:55,038 DEBUG [CommonsLogger.java:57] : cannot find method [validateDoExecute] in action [com.app.action.BaseAction@b17e0a]
2011-07-09 21:28:55,038 DEBUG [CommonsLogger.java:57] : Executing action method = null
Ok, I think all of that log is fluff except for this line:
2011-07-09 21:28:52,768 DEBUG [DefaultListableBeanFactory.java:385] : No bean named 'com.app.action.BaseAction'
found in org.springframework.beans.factory.support.DefaultListableBeanFactory@169df00: defining beans [userService];
root of factory hierarchy
When spring says it cannot find a bean with that name, I believe it is telling you that it has not been informed of such a bean.
Check in the spring context.xml (perhaps WEB-INF/spring/web-application-context.xml
) file and add a
<bean id="com.app.action.BaseAction" class="com.app.action.BaseAction" />
declaration for your bean.
精彩评论