spring 3 and dwr 3 not working with single configuration file
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.springframewo开发者_如何学运维rk.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
ShamsI 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
精彩评论