0

我正在使用 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>
4

2 回答 2

0

我通过替换jar版本解决了这个问题。谢谢您的帮助!

于 2012-12-14T06:41:42.173 回答
0

尝试添加<beans default-autowire="autodetect">applicationContext.xml并检查您的库的版本和数量。

于 2012-12-13T17:24:44.467 回答