集成效果:
不需要dwr.xml进行配置,可以完全在spring配置需要remote到客户端的bean,可以将spring的bean暴露给客户端,通过javascript调用(这一点很爽啊)。
集成步骤:
1、将Spring的namespace重新定义为:
<
beans
xmlns
="http://www.springframework.org/schema/beans"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dwr ="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation ="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd" >
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dwr ="http://www.directwebremoting.org/schema/spring-dwr"
xsi:schemaLocation ="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd" >
注意加粗部分,将dwr引入到Spring中。原文章中的这方面配置有问题,此为修正版。
2、Bean范例:
<
bean
id
="myService"
class
="example.MyServiceImpl"
>
< dwr:remote javascript =”MyAjaxService”/>
<property name ="dao" ref ="myDao" />
</ bean >
< dwr:remote javascript =”MyAjaxService”/>
<property name ="dao" ref ="myDao" />
</ bean >
3、如果需要将DWR暴露到客户端,比如像原始的DWR在配置完dwr.xml运行之后,在http://localhost/WebApp/dwr 可看到的所有可调用的methods。 就需要下面的配置:
在web.xml中添加:
<
servlet
>
< servlet-name > dwr </ servlet-name >
< servlet-class > org.directwebremoting.spring.DwrSpringServlet </ servlet-class >
< init-param >
< param-name > debug </ param-name >
< param-value > true </ param-value >
</ init-param >
</ servlet >
< servlet-mapping >
< servlet-name > dwr </ servlet-name >
< url-pattern > /dwr/* </ url-pattern >
</ servlet-mapping >
< servlet-name > dwr </ servlet-name >
< servlet-class > org.directwebremoting.spring.DwrSpringServlet </ servlet-class >
< init-param >
< param-name > debug </ param-name >
< param-value > true </ param-value >
</ init-param >
</ servlet >
< servlet-mapping >
< servlet-name > dwr </ servlet-name >
< url-pattern > /dwr/* </ url-pattern >
</ servlet-mapping >
如果是用的Spring MVC,则直接在Bean中加上:<dwr:controller id=”dwrController” debug=”true”/> 就可以了。
详细内容请参见:http://bram.jteam.nl/index.php/2007/01/31/spring-dwr-ajax-made-easy/