2011-05-21 66 views
1

我在我的web应用中使用了Spring 3.0和DWR 3。我有一些配置问题。当我为这两种技术使用单个配置文件时,那么我在顶部编写的那个将工作,接下来将无法工作。当我做了两个不同的DispatcherServlet,然后他们工作正常。
这里是我的web.xml配置:spring 3和dwr 3不支持单个配置文件

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

    <servlet-mapping> 
     <servlet-name>abc</servlet-name> 
     <url-pattern>*.form</url-pattern> 
    </servlet-mapping> 

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

    <servlet-mapping> 
     <servlet-name>abc-dwr</servlet-name> 
     <url-pattern>/dwr/*</url-pattern> 
    </servlet-mapping> 

这里是我的ABC-servlet.xml文件(只包含Spring配置):

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> 

    <mvc:annotation-driven /> 
    <context:annotation-config /> 
    <tx:annotation-driven /> 
    <context:component-scan base-package="a.b.c"> 
     <context:include-filter type="regex" expression="(service|controller)\*" /> 
    </context:component-scan> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass"> 
      <value>org.springframework.web.servlet.view.tiles2.TilesView</value> 
     </property> 
    </bean> 

    <bean id="tilesConfigurer" 
     class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
     <property name="definitions"> 
      <list> 
       <value>WEB-INF/tiles-defs.xml</value> 
      </list> 
     </property> 
    </bean>  

这里另一个ABC- dwr-servlet.xml文件(包含Spring和DWR配置):

<?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:dwr="http://www.directwebremoting.org/schema/spring-dwr" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
     http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> 

    <!-- DWR SETTING STARTS HERE --> 
    <dwr:configuration > 
     <dwr:convert type="bean" class="a.b.c.formbean.XYZ" /> 
    </dwr:configuration> 
    <dwr:annotation-config /> 
    <dwr:url-mapping /> 
    <dwr:controller id="dwrController" debug="true" /> 
    <dwr:annotation-scan base-package="a.b.c.dwr" /> 

    <!-- DWR SETTING ENDS HERE --> 
    <mvc:annotation-driven /> 
    <context:annotation-config /> 
    <tx:annotation-driven /> 
    <context:component-scan base-package="a.b.c"> 
     <context:include-filter type="regex" expression="(service|controller)\*" /> 
    </context:component-scan> 

这里有两个文件,abc-servlet.xml包含Spring配置,abc-dwr-servlet.xml包含DWR和Spring配置。我在这两个文件中都写了Spring配置,因为如果我将它从第二个文件中删除,Spring将无法工作。 我已经尝试过太多以将两种技术合并到同一个配置文件中。但只有一个我在顶部写的是工作,另一个不工作。 有什么办法可以将它们两个合并到同一个文件中,或者我正在犯一些愚蠢的错误?请帮帮我。

感谢
沙姆斯

+0

没有人有任何想法来纠正这一个? – Shams 2011-05-24 05:52:08

回答

0

我能够做出正确的配置(春季3.X + DWR 3个+砖),只有一个调度程序Servlet的声明,并能够使用注释我DWR控制器注入Spring服务:

这很好的博客包含大量有关如何与其他许多TECHNOS配置春季有用的资源:

春+ DWR
http://krams915.blogspot.com/2011/01/spring-mvc-3-and-dwr-3-integration.html

其他教程: http://krams915.blogspot.com/p/tutorials.html

+0

嗨,我已经阅读了本教程。但我无法确定,我在哪里做错配置。你能检查我的两个.xml文件,并让我知道我错在哪里?或发布您的配置,以便我可以与我的配置进行比较。 谢谢 – Shams 2012-01-23 09:15:09

+0

很难说部分配置。我必须在上下文配置中声明以下bean(我在dwr-config.xml中声明它):'' – 2012-02-13 18:06:49