spring 3 和 dwr 3 不适用于单个配置文件

发布于 2024-11-09 05:30:49 字数 6503 浏览 3 评论 0原文

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

谢谢
沙姆斯

I am using Spring 3.0 and DWR 3 in my web app. I have some configuration problem. When i use single configuration file for both tech, then the one which i write at top will work and next will not work. And when i made two different DispatcherServlet then they are working fine.
Here is my web.xml configuration:

<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>

Here is my abc-servlet.xml file (which contain only Spring configuration):

<?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>    

And here another abc-dwr-servlet.xml file (which contain both Spring and DWR configuration):

<?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>

Here two file, abc-servlet.xml contain Spring configuration and abc-dwr-servlet.xml contain DWR and Spring configuration. I have written Spring configuration in both file, coz if i will remove it from 2nd file Spring will not work.
I have tried too much to merge both technology in same configuration file. But only one which i write at top is working and another one is not working.
Is there any way to merge both of them in same file, or i am doing some silly mistake? please help me.

Thanks
Shams

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

憧憬巴黎街头的黎明 2024-11-16 05:30:49

我能够通过仅声明一个 Dispatcher Servlet 来进行正确的配置(Spring 3.x + DWR 3 + Tiles),并且能够使用注释在我的 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

I was able to make the proper configuration (Spring 3.x + DWR 3 + Tiles) with only one Dispatcher Servlet declared and able to inject Spring services in my DWR controller using annotations:

That very good blog contains lot of useful resources about how to config Spring with many other technos:

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

Other tutorials:
http://krams915.blogspot.com/p/tutorials.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文