最近学习struts2的框架,在配置spring的时候,出了一个问题。
我的web.xml
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>applicationContext.xml我是放在/WEB-INF/classes/下面,内容是:
<?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:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="略"/>
<property name="username" value="略"/>
<property name="password" value="略"/>
</bean>
</beans>但是在启动tomcat的时候,发生了错误,日志如下:
2009-08-04 16:07:24,281-[TS] ERROR main org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/classes/applicationContext.xml]; nested exception is java.lang.IllegalArgumentException: Class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] does not implement the NamespaceHandler interface
Caused by: 
java.lang.IllegalArgumentException: Class [org.apache.xbean.spring.context.v2.XBeanNamespaceHandler] does not implement the NamespaceHandler interface
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.initHandlerMappings(DefaultNamespaceHandlerResolver.java:119)
略网上搜索了很久,也没找到如何解决问题,望有经验高手不吝赐教

解决方案 »

  1.   

    spring.xml的配置文件:
    <beans default-lazy-init="false" default-dependency-check="none" default-autowire="no">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
         <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
     <property name="url" value="jdbc:mysql://IPAddress:3306/databaseName?useUnicode=true&amp;characterEncoding=UTF8&amp;autoGenerateTestcaseScript=true&amp;elideSetAutoCommits=true&amp;prepStmtCacheSize=100&amp;prepStmtCacheSqlLimit=512&amp;maintainTimeStats=false&amp;cacheCallableStmts=true&amp;dontTrackOpenResources=true&amp;useLocalSessionState=true"/>      
         <property name="username" value="test"/>
         <property name="password" value="111111"/>
         <property name="maxActive" value="10"/>
         <property name="initialSize" value="5"/>
    </bean> 
    <bean id="service" class="com.igobb.service.Service" autowire="byName"/>
    </beans>web.xml的配置文件:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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">
    <!--<session-config>
    <session-timeout>20</session-timeout>
    </session-config>--> <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring.xml</param-value>
    </context-param> <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>
    org.springframework.web.context.ContextLoaderServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <!--<servlet>
    <servlet-name>initServlet</servlet-name>
    <servlet-class>com.project.system.InitServlet</servlet-class>
    <load-on-startup>3</load-on-startup>
    </servlet>-->

    <servlet>
    <servlet-name>projectName</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>projectName</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <!-- application manager start-->
    <!--<servlet>
    <servlet-name>applicationManager</servlet-name>
    <servlet-class>com.igobb.system.ApplicationManager</servlet-class>
    <load-on-startup>3</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>applicationManager</servlet-name>
    <url-pattern>
    /applicationManager
    </url-pattern>
    </servlet-mapping>-->
    <!-- application manager end-->
    </web-app>
    另外struts还有一个自己的配置文件:
    projectName-servlet.xml:
    <beans>
    <bean id="babymeController" class="com.project.web.AController">
    <property name="methodNameResolver">
    <ref bean="methodNameResolver"/>
    </property>
    </bean>
    <bean id="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/member/*.htm">memberController</prop>
    ....
    </props>
    </property>
    </bean>
    <bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
            <property name="paramName" value="m"/>//这里是你的url路径 例如:/product/a.htm?m=myMethodName&a=1
            <property name="defaultMethodName" value="defaultHandle"/>
        </bean>
        
    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.JstlView</value>
    </property>
    <property name="prefix">
    <value>/</value>
    </property>
    <property name="suffix">
    <value>.jsp</value>
    </property>
    </bean>
    </beans>OK!到这里就算ok了 这是标准的struts+spring的配置文件。一定要加分哦!
      

  2.   

    你spring使用的是2.0还是2.5版本??
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    你引入的约束是2.0的
      

  3.   


      就是包的问题 你要是用myeclipse内至的SPRING包肯定会出问题 我曾经出过 后来解决了 但是是糊涂着解决了 帮不上LZ忙 顶一个吧