集成效果:
不需要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"
>
注意加粗部分,将dwr引入到Spring中。原文章中的这方面配置有问题,此为修正版。
2、Bean范例:
<
bean
id
="myService"
class
="example.MyServiceImpl"
>
<
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
>
如果是用的Spring MVC,则直接在Bean中加上:<dwr:controller id=”dwrController” debug=”true”/> 就可以了。
详细内容请参见:http://bram.jteam.nl/index.php/2007/01/31/spring-dwr-ajax-made-easy/

本文介绍如何将DWR集成到Spring框架中,实现Ajax应用。主要步骤包括:定义Spring的namespace,配置可远程调用的bean,并设置DWR的servlet映射。适用于使用Spring和希望简化Ajax开发流程的开发者。
&spm=1001.2101.3001.5002&articleId=1765078&d=1&t=3&u=33ee8feb2fab4ebd961370515b677a40)
173

被折叠的 条评论
为什么被折叠?



