我正在使用struts2,spring和hibernate做一个项目。我在struts.xml文件中遇到了一个问题,即它没有接受在applictioncontext.xml中声明的bean。 我的applicationcontext.xml看起来像这个
<bean id="dvdDAO" class="com.ideas2it.dvdstruts.DvdDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="userDetailDAO" class="com.ideas2it.dvdstruts.UserDetailDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hibernatetransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean name="DvdAction" class="com.ideas2it.dvdstruts.DvdAction" >
<property name="dvdDAO" ref="dvdDAO"/>
<property name="userDetailDAO" ref="userDetailDAO"/>
</bean>
<bean name="LoginAction" class="com.ideas2it.dvdstruts.LoginAction" >
<property name="userDetailDAO" ref="userDetailDAO"/>
</bean>
<bean name="AccountCreationAction" class="com.ideas2it.dvdstruts.AccountCreationAction" >
<property name="userDetailDAO" ref="userDetailDAO"/>
我的struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.objectFactory" value="spring"/>
<package name="basicstruts2" namespace="/" extends="struts-default">
<action name="register" class="AccountCreationAction" method="register" >
<result name="success">Login.jsp</result>
<result name="input">failure.jsp</result>
</action>
<action name="login" class="LoginAction" method="loginProcess" >
<result name="success" type="redirectAction">
<param name="actionName">display</param>
<param name="userDetail">${userDetail}</param>
</result>
<result name="input">failure.jsp</result>
</action>
<action name="insert" class="DvdAction" method="insertDvd">
<result type="redirectAction">
<param name="actionName">display</param>
</result>
</action>
<action name="delete" class="DvdAction" method="deleteDvd">
<result type="redirectAction">
<param name="actionName">display</param>
</result>
</action>
<action name="update" class="DvdAction" method="updateDvd">
<result type="redirectAction">
<param name="actionName">display</param>
</result>
</action>
<action name="display" class="DvdAction" method="displayDvd">
<result name="success">Dvd.jsp</result>
</action>
</package>
</struts>
在applicationcontext.xml中的bean,这里没有引用。我在日志中遇到错误 日志中的错误:
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
2012-12-14 10:22:09,821 INFO org.springframework.web.context.ContextLoader.initWebApplicationContext:187 - Root WebApplicationContext: initialization started
2012-12-14 10:22:09,901 INFO org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh:456 - Refreshing Root WebApplicationContext: startup date [Fri Dec 14 10:22:09 IST 2012]; root of context hierarchy
2012-12-14 10:22:09,999 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions:315 - Loading XML bean definitions from ServletContext resource [/WEB-INF/config/dvdstruts-context.xml]
2012-12-14 10:22:10,173 INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions:315 - Loading XML bean definitions from ServletContext resource [/WEB-INF/classes/struts.xml]
2012-12-14 10:22:11,644 INFO org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons:555 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6dbdc9: defining beans [dataSource,sessionFactory,dvdDAO,userDetailDAO,hibernatetransactionManager,DvdAction,LoginAction,AccountCreationAction]; root of factory hierarchy
.........//hibernate mapping some log file info
2012-12-14 10:22:22,825 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.debug:57 - Loaded [BUILDER] {PackageConfig Name:convention-default namespace: parents:[{PackageConfig Name:struts-default namespace: parents:[]}]}
2012-12-14 10:22:22,825 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.debug:57 - Loaded [BUILDER] {PackageConfig Name:hibernate-default namespace: parents:[{PackageConfig Name:struts-default namespace: parents:[]}]}
2012-12-14 10:22:22,826 DEBUG com.opensymphony.xwork2.interceptor.I18nInterceptor.debug:57 - new I18nInterceptor()
2012-12-14 10:22:22,843 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.debug:57 - Loaded [BUILDER] {PackageConfig Name:hibernateManager namespace:/hibernateManager parents:[{PackageConfig Name:struts-default namespace: parents:[]}]}
2012-12-14 10:22:22,850 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.debug:57 - Loaded /hibernateManager/* in 'hibernateManager' package:{ActionConfig * (.{1}()) - action - jar:file:/home/saranya/Desktop/apache-tomcat-6.0.20/webapps/dvd_struts/WEB-INF/lib/struts2-fullhibernatecore-plugin-1.4-GA.jar!/struts-plugin.xml:74:36}
2012-12-14 10:22:22,850 DEBUG com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.debug:57 - Loaded [BUILDER] {PackageConfig Name:basicstruts2 namespace:/ parents:[{PackageConfig Name:struts-default namespace: parents:[]}]}
Dec 14, 2012 10:22:22 AM org.apache.catalina.core.StandardContext start
SEVERE: Error filterStart
Dec 14, 2012 10:22:22 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/dvd_struts] startup failed due to previous errors
2012-12-14 10:22:22,885 INFO org.springframework.web.context.support.XmlWebApplicationContext.doClose:1002 - Closing Root WebApplicationContext: startup date [Fri Dec 14 10:22:09 IST 2012]; root of context hierarchy
2012-12-14 10:22:22,886 INFO org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons:422 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6dbdc9: defining beans [dataSource,sessionFactory,dvdDAO,userDetailDAO,hibernatetransactionManager,DvdAction,LoginAction,AccountCreationAction]; root of factory hierarchy
2012-12-14 10:22:22,887 INFO org.springframework.orm.hibernate3.LocalSessionFactoryBean.destroy:246 - Closing Hibernate SessionFactory
2012-12-14 10:22:22,887 INFO org.hibernate.impl.SessionFactoryImpl.close:805 - closing
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.
我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Struts 2 Dvd Application</display-name>
<filter>
<filter-name>Spring_struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<load-on-startup>1</load-on-startup>
</filter>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/dvdstruts-context.xml,/WEB-INF/classes/struts.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter-mapping>
<filter-name>Spring_struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
答案 0 :(得分:0)
尝试将<beans default-autowire="autodetect">
添加到applicationContext.xml
,并检查您的图书馆的版本和数量。
答案 1 :(得分:0)
我通过更换jar版本解决了这个问题。谢谢您的帮助!