返回列表 发帖

struts2+spring整合问题

我按照老师的struts2的13章。把必要的几个包放进web路径下面。一直出现异常。这是怎么回事?

严重: Exception starting filter struts2
Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/F:/projecthammer/tomcat-hammer/webapps/ROOT/WEB-INF/lib/struts2-core-2.0.9.jar!/struts-default.xml:8:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)


web.xml有配置struts2的fiter.也有加载spring:
<listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>
<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>


struts.xml:

<struts>
<constant name="struts.i18n.encoding" value="GBK" />
<constant name="struts.objectFactory" value="spring" />


<package name="system_login" extends="struts-default">
  <action name="login" class="loginAction">
   <result name="suss">/succ.jsp</result>
  </action>
</package>
</struts>

[ 本帖最后由 hammer 于 2008-6-11 13:10 编辑 ]

hammer.rar (15.13 KB)

一开服务器就出这个异常?

TOP

把web.xml和几份配置文件放上来看看

TOP

对。一开服务器就异常。

web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
        xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
       
  <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath*:config/spring/*.xml</param-value>
  </context-param>
  <!--Spring ApplicationContext 载入 -->
        <listener>
                <listener-class>
                        org.springframework.web.context.ContextLoaderListener
                </listener-class>
        </listener>

        <filter>
                <filter-name>struts2</filter-name>
                <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter>
        <filter-mapping>
                <filter-name>struts2</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
       
</web-app>

struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
        <constant name="struts.i18n.encoding" value="GBK" />
        <constant name="struts.objectFactory" value="spring" />
       
       
        <package name="system_login" extends="struts-default">
                <action name="login" class="loginAction">
                        <result name="suss">/succ.jsp</result>
                </action>
        </package>
</struts>

struts.properties:

struts.devMode = false
struts.configuration.xml.reload=ture

applicationContext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
        default-autowire="byName" default-lazy-init="true">
        <import resource="applicationContext-action.xml"/>
       
</beans>

applicationContext-action.xml:
        <bean id="loginAction"
                class="com.hammer.companyManager.web.aciton.system.LoginAction"
                scope="prototype">
        </bean>
        <!-- 系统登录 -->
        <bean id="loginService"  class="com.hammer.companyManager.service.LoginService"/>
</beans>

TOP

lib里面的包:
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.1.jar
commons-logging-1.0.4.jar
spring-2.0.jar
xwork-2.0.4.jar
struts2-spring-plugin-2.0.11.1.jar
freemarker-2.3.8.jar

TOP

struts.properties加多一句看看struts.objectFactory = spring

TOP

还有在struts.xml里面指定
<include file="struts-default.xml"/>

TOP

I had the same issue. After experimenting for half a day I decided to determine the difference with the working examples (war files). This solved the problem at last. I was loading unneeded libraries. Of all the libraries supplied in the download file of struts2 I needed only a small subset. After removing all struts*.jar libraries, except struts2-core-2.0.11.1.jar, I got rid of the problems. What a waste of time......

来自apache, 包的问题

TOP

按照你说的。两行代码都加了。异常还是存在。一模一样。
我的struts.xml里面的
<constant name="struts.objectFactory" value="spring" />
好像可以代替propeties里面的那行吧?

TOP

https://issues.apache.org/struts/browse/WW-2478
你看下这里吧, 跟你一样的问题, 二楼说的是包的问题, 试下把strutd*.jar移除, 只留下struts2-core-2.0.11.1.jar

TOP

返回列表