Step 1 - Give DWR access to the Spring context
web.xml配置:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:yourSpringContext.xml
</param-value>
</context-param>
<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>
<!-- /dwr/* 必须在/*前面 -->
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
直接使用SPRING MVC + org.directwebremoting.spring.DwrController
<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value> classpath:yourSpringContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
org.directwebremoting.spring.DwrController
<dwr:controller id="dwrController" debug="true"> <dwr:config-param name="activeReverseAjaxEnabled" value="true"/> </dwr:controller
STEP 2 - Configure DWR's remoting DWR配置文件
- Use the DWR/Spring namespace (Spring 2.5 or greater, DWR 2.x or greater, dwr.xml not required or recommended)
- 使用SPRING 配置文件替换原来的DWR文件的配置方式,这种配置方式和原来的DWR文件配置方式变化较小:
-
The configuration tag
<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.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
The
<dwr:configuration/>
is used to mimic the behavior of the configuration available indwr.xml. This tag is optional and it may have nested tags (init, creator, signatures,..). These nested tags mimic the behavior of those available in dwr.xml. Example:<dwr:configuration> <dwr:convert type="bean" class="org.uk.ltd.dwr.dev.model.Address" /> </dwr:configuration>
The remote tag
Inside each bean you want to remote include a
<dwr:remote javascript="Fred">
tag. There you can specify the methods that are going to be proxied and those that won't. For example:<bean id="timeConvert" class="com.mycompany.ui.util.TimeConvert"> <dwr:remote javascript="AjaxTimeConvert"> <dwr:include method="convert" /> </dwr:remote> </bean>
- Use the DWR/Spring namespace with annotations (Spring 2.5 or greater, DWR 2.x or greater, dwr.xml not required or recommended)
- 使用注解的方式替换原有的DWR配置文件,实现零配置文件
-
<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.5.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
- 以下配置作用是
- <dwr:annotation-config id="dwrAnnotationConfig" /><!--开启注解扫描配置 -->
- <dwr:annotation-scan base-package="com.yourpackage.whatever" scanDataTransferObject="true" scanRemoteProxy="false" /> <!--注解扫描范围的配置 -->
-
annotation-scan - Enables DWR to scan the classpath and:
- Detect beans annotated with @RemoteProxy & @RemoteMethod, and register the Spring beans and DWR Creator proxies for them. Because DWR is registering the beans into the Spring context for you all Spring annotated beans (@Service, @Component, @Controller, etc.) will be ignored to avoid duplicate registration.
- Detect DWR converters annotated with @DataTransferObject.
- base-package - The base package to initiate scanning from - i.e. com.myApp.*.
- regex - A regular expression that will be used in the classpath scanner.
- scanRemoteProxy - Should DWR scan for remote proxies? Defaults to true.
- scanDataTransferObject - Should DWR scan for converters? Defaults to true.
- scanGlobalFilter - Defaults to true.
A complete working example of a dwr:annotation-scan configuration can be found here.
- annotation-config - Enables DWR to scan the Spring context, detect beans annotated with @RemoteProxy & @RemoteMethod and register the DWR Creator proxies for them.
- 然后在具体的代码上使用
- @RemoteProxy - Functional namespace equivalent = dwr:remote
- @RemoteMethod - Functional namespace equivalent = dwr:include method="methodName"
- @DataTransferObject - Functional namespace equivalent = dwr:convert
- 案例代码如下:
- package org.myframework.dwr;
- import javax.annotation.Resource;
- import org.directwebremoting.annotations.RemoteMethod;
- import org.directwebremoting.annotations.RemoteProxy;
- import org.springframework.stereotype.Component;
- //http://127.0.0.1:8010/springdwr/test/SayHello
- // http://127.0.0.1:8010/dwr/index.html
- @RemoteProxy(name="SayHello")
- public class SayHello {
- @RemoteMethod
- public String sayHello(String abc){
- return "sayHello to " + abc ;
- }
- @RemoteMethod
- public String sayHelloFromSpringBean(){
- return "sayHello to " + springBean ;
- }
- @Resource(name = "springBean")
- SpringBean springBean;
- }
- Use the Spring Creator (Will work for older versions of Spring and DWR - dwr.xml required. Not the recommended approach.)
- 第三种传统方式不推荐使用:
-
<allow> ... <create creator="spring" javascript="Fred"> <param name="beanName" value="Shiela"/> </create> ... </allow>
另外:直接使用SPRING mvc貌似test的时候必须写清楚调用的具体内容,没有界面展现所有的DWR调用的内容:
- //http://127.0.0.1:8010/springdwr/test/SayHello dwrController
- // http://127.0.0.1:8010/dwr/index.html springDwr
相关推荐
dwr与spring集成的两种方式,来之网上搜索的文档。。
DWR示例 包括DWR基本配置 DWR传递对象 DWR 反转ajax DWR与spring集成
dwr+spring集成配置 dwr采用annotation自动扫描的方式
dwr与spring集成,spring jdbc 数据库集成,spring注入例子
dwr和spring集成简单例子!
介绍srping与dwr的集成:系统介绍dwr在spring中的相关配置。
这个jar是很难找的,是dwr在spring环境里面,使用注解的必须包,希望对你有用。
看了ext不得不感叹,不得不觉得自己的知识贫乏。 哎,bs架构能做成这样 js真是博大精深啊
dwr+hibernate+spring 集成 实例 dwr+hibernate+spring 集成 实例
将dwr集成到spring mvc(dwr的配置是基于xml)
Spring 集成 Dwr 文件上传和文件下载
Spring与DWR集成开发,DWR相当方便的使用,spring与当外人联合使用越来越多,初学教程
struts2.1 spring2.5 ibatis2.3 dwr3 annotation配置 集成 此中例子不完整. 如要下载:http://download.csdn.net/source/2138885
spring2.5 ibatis2.3 struts2.1 dwr3 annotation集成配置
使用Spring集成struts2、ibatis、poi实现的增删改查功能,包括采用jquery实现的无刷新查询机分页、dwr实现的两级联动、以及采用poi动态将数据库数据导出成excel,本demo采用mysql数据库,附有建表sql,项目导入...
NULL 博文链接:https://log-cd.iteye.com/blog/657949
这是一个简单的spring与dwr的整合,希望对大家能有一点帮助
NULL 博文链接:https://panyongzheng.iteye.com/blog/1475762