【问题标题】:spring 3 and dwr 3 not working with single configuration filespring 3 和 dwr 3 不能使用单个配置文件
【发布时间】:2011-05-21 12:46:19
【问题描述】:

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

谢谢
假货

【问题讨论】:

  • 没有人想纠正这个问题??

标签: configuration spring-mvc dwr


【解决方案1】:

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

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

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

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

【讨论】:

  • 嗨,我已经完成了本教程。但我无法确定我在哪里做错配置。你能检查我的两个 .xml 文件并让我知道我哪里错了吗?或发布您的配置,以便我可以与我的配置进行比较。谢谢
  • 部分配置很难说。我必须在上下文配置中声明以下 bean(我在 dwr-config.xml 中声明了它):&lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" /&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-16
  • 2011-07-19
  • 1970-01-01
  • 2021-04-13
相关资源
最近更新 更多