15dwr - DWR 与 Spring整合

让 DWR 和 Spring 一起工作的检查列表

  1. 确认你用的是最新版的 DWR。Spring 创造器已经有了变化,所以你最好检查一下 DWR 的最新版本 。
  2. 确认你的 Spring 的 Bean 在 DWR 外面运行良好。
  3. 配置 DWR 和 Spring 一起工作。 (看下面)
  4. 查看演示页面: http://localhost:8080/[ YOUR-WEBAPP ]/dwr ,检查 spring 的 Bean 是否出现。

DWR 对于 Spring 没有运行期依赖,所以如果你不使用 Spring 那么 Spring 的支持不会产生任何影响到。

Spring Creator

这个创造器会在 spring beans.xml 里查询 beans,并且会使用 Spring 去创建它们。如果你已经使用 Spring,
这个创造器会非常有用。否则将完全没有任何用处。

要让 DWR 使用 Spring 创造器去创建和远程调用 beans,要像如下所示:

<allow>
...
<create creator="spring" javascript="Fred">
<param name="beanName" value="Shiela" />
</create>
</allow>

找到 Spring 配置文件

有 3 个方法可以找到 Spring 配置文件

1. ContextLoaderListener
最简单的用法使从 Spring-MVC 里使用
org.springframework.web.context.ContextLoaderListener
你不必使用整个 Spring-MVC 去确认这个普遍的解决方案使多么好。只要再你的 web.xml 里配置:

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>/WEB-INF/classes/beans.xml</param-value>
</context-param>
<listener>
	<listener-class>
		org.springframework.web.context.ContextLoaderListener
	</listener-class>
</listener>

2. 使用 location 参数
如果你喜欢指定的 beans.xml 在你的 dwr.xml 文件中,那么你能使用 location 参数。你可以指定你希望数
量的,必须有唯一的以”location”开头的命名。比如:location-1, location-2。这些 locations 是作为参数传
到 Spring 的 ClassPathXmlApplicationContext:

<allow>
...
	<create creator="spring" javascript="Fred">
		<param name="beanName" value="Shiela" />
		<param name="location" value="beans.xml" />
	</create>
</allow>

3. 设置 beenFactory 目录
Spring 创造器有一个静态的方法:setOverrideBeanFactory(BeanFactory),这个方法提供一个可编程的方
式去覆盖任何 BeanFactories。

4.使用 Spring 配置 DWR
Bram Smeets 写了一个有意思的 blog ,教你配置 DWR 使用 beans.xml 代替 WEB-INF/web.xml。
我也对于如何在 beans.xml 中指定 dwr.xml 很感兴趣,尽管这看上去有些 Spring 传染病的感觉。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值