1

我在我的网络应用程序中使用 Spring 3.0 和 DWR 3。我有一些配置问题。当我对两种技术都使用单个配置文件时,我在顶部编写的一个将起作用,而下一个将不起作用。当我制作了两个不同的 DispatcherServlet 时,它们工作正常。
这是我的 web.xml 配置:

<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 将不起作用。我已经尝试了太多将这两种技术合并到同一个配置文件中。但是只有我在顶部写的一个在工作,而另一个不工作。有没有办法将它们合并到同一个文件中,或者我犯了一些愚蠢的错误?请帮我。

谢谢沙姆斯
_

4

1 回答 1

0

我能够进行正确的配置(Spring 3.x + DWR 3 + Tiles),只声明了一个 Dispatcher Servlet,并且能够使用注释在我的 DWR 控制器中注入 Spring 服务:

那个非常好的博客包含很多关于如何使用许多其他技术配置 Spring 的有用资源:

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

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

于 2012-01-11T22:17:57.533 回答