Spring 2基于XML Schema的配置
众所周知,Spring 2通过XML Schema配置方式极大地简化的其配置,而且使得第三方扩展变为可能。配置如下代码所示:
<? xml version="1.0" encoding="UTF-8" ?>
< beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd" >
<!-- <bean /> definitions here -->
</ beans >
清单1 applicationContext.xml
不知大家有没有想过spring-beans-2.0.xsd位置在那里?其实,大家可以用Eclipse打开Spring的jar包,展开META-INF,并双击打开其中的spring.schemas文件,内容如下:
http\://www.springframework.org/schema/beans/spring-beans- 2.0 .xsd = org/springframework/beans/factory/xml/spring-beans- 2.0 .xsd
http\://www.springframework.org/schema/tool/spring-tool- 2.0 .xsd = org/springframework/beans/factory/xml/spring-tool- 2.0 .xsd
http\://www.springframework.org/schema/util/spring-util- 2.0 .xsd = org/springframework/beans/factory/xml/spring-util- 2.0 .xsd
http\://www.springframework.org/schema/aop/spring-aop- 2.0 .xsd = org/springframework/aop/config/spring-aop- 2.0 .xsd
http\://www.springframework.org/schema/lang/spring-lang- 2.0 .xsd = org/springframework/scripting/config/spring-lang- 2.0 .xsd
http\://www.springframework.org/schema/tx/spring-tx- 2.0 .xsd = org/springframework/transaction/config/spring-tx- 2.0 .xsd
http\://www.springframework.org/schema/jee/spring-jee- 2.0 .xsd = org/springframework/ejb/config/spring-jee- 2.0 .xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd = org/springframework/beans/factory/xml/spring-beans- 2.0 .xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd = org/springframework/beans/factory/xml/spring-tool- 2.0 .xsd
http\://www.springframework.org/schema/util/spring-util.xsd = org/springframework/beans/factory/xml/spring-util- 2.0 .xsd
http\://www.springframework.org/schema/aop/spring-aop.xsd = org/springframework/aop/config/spring-aop- 2.0 .xsd
http\://www.springframework.org/schema/lang/spring-lang.xsd = org/springframework/scripting/config/spring-lang- 2.0 .xsd
http\://www.springframework.org/schema/tx/spring-tx.xsd = org/springframework/transaction/config/spring-tx- 2.0 .xsd
http\://www.springframework.org/schema/jee/spring-jee.xsd = org/springframework/ejb/config/spring-jee- 2.0 .xsd
清单2 spring.schemas
从以上的文件中,可以看出XML Sechema文件在类包中位置。
DWR 2.0 RC 2中的XML Schema文件
根据上面的描述,我打开DWR的jar包中spring.schemas文件,内容如下:
http\://www.directwebremoting.org/schema/spring-dwr- 2.0 .xsd = org/directwebremoting/spring/spring-dwr- 2.0 .xsd
然后,按照上面的路径打开spring-dwr-2.0.xsd文件,内容如下:
<? xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!-- 省略了版权信息 -->
< xsd:schema xmlns ="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:xsd ="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.directwebremoting.org/schema/spring-dwr"
elementFormDefault ="qualified"
attributeFormDefault ="unqualified" >
<!-- 省略了具体的定义 -->
</ xsd:schema >
清单3 spring-dwr-2.0.xsd
文件spring-dwr-2.0.xsd告诉我们,其名称空间应为“http://www.directwebremoting.org/schema/spring-dwr”,所以我们在配置Spring 2时,应使用以上的名称空间,如下面的代码片段所示:
<? xml version="1.0" encoding="UTF-8" ?>
< beans xmlns ="http://www.springframework.org/schema/beans"
xmlns:dwr ="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation ="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd" >
< dwr:configuration >
< dwr:convert class ="net.blogjava.max.pws.domain.Album" type ="bean" >
< dwr:exclude method ="photos" />
</ dwr:convert >
< dwr:convert class ="net.blogjava.max.pws.domain.Photo" type ="bean" >
< dwr:exclude method ="original, poster, thumb, full, album" />
</ dwr:convert >
</ dwr:configuration >
< bean id ="ajaxFacade"
class ="net.blogjava.max.pws.web.ajax.AjaxFacade" >
< dwr:remote javascript ="AjaxFacade" />
< property name ="personalWebSite" ref ="personalWebSite" />
</ bean >
</ beans >
清单3 ajaxContext.xml
WEB-INF/web.xml配置
通过上面的配置,我们可以省去dwr.xml配置,不过在web.xml配置dwr的Servlet时,要使用新的Servlet类。配置代码片段如下:
< 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 >
< load-on-startup > 1 </ load-on-startup >
</ servlet >
< servlet-mapping >
< servlet-name > dwr </ servlet-name >
< url-pattern > /dwr/* </ url-pattern >
</ servlet-mapping >
清单4 web.xml
总结
通过在Spring 2整合DWR 2配置,可以集中管理应用程序的配置,从一定程度上解决JavaEE开发中的配置文件泛滥的问题。
分享到:
相关推荐
Spring 2中整合DWR 2 MSN:zhoujianguo_leo@hotmail.com
spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记 spring使用annotation整合dwr笔记
spring整合DWR的一些配置问题,如下: 1、web.xml中加入dwr配置 2、由spring接管dwr,配置spring的xml文件 3、配置dwr的service 4、配置页面
dwr与 spring整合 传对象的例子
精心整理的,dwr与目前流行框架spring和struts2的整合,值得一学
使用struts2、hibernate、spring、dwr整合的简单项目。包括级联等 注意:csdn上面显示为chm文件。该文件为.7z的压缩文件。用压缩软件可以打开的 csdn弄错了
源码 博文链接:https://callan.iteye.com/blog/166986
Struts2 + spring + hibernate + dwr 完美整合代码 dwr 用户注册 多级下拉联动 刷新表格.. 全部代码
这两个部分是笔者在“疯狂Java实训营”的培训讲义,是《疯狂Ajax讲义:Prototype/jQuery+DWR+Spring+Hibernate整合开发》的重点部分。第三部分则提供了2个综合性案例:Blog系统和电子拍卖系统,让读者将前面所学真正...
使用spring 整合dwr的反推技术,可以运用于在线聊天的实现。
此实例作为Spring整合dwr基础入门实例,是菜鸟开始的必备资料!
struts2 spring ibatis dwr整合配置 自己整合的,很好用
NULL 博文链接:https://605113068.iteye.com/blog/1731323
配置整合DWR3.0和Spring2.5使用annotation注解
dwr2.0 spring 3.0 整合示例
网络上Spring整合DWR comet 实现无刷新、多人聊天室 的代码整理,包含jar包,eclipse工程,直接导入即可运行。
Spring+struts+hibernate+dwr框架整合教程 本教程是专门介绍如何在ssh框架中搭建dwr框架。
这是一个SPRING+DWR的整合项目.包括整合的三种方式,最彻底的整合是不需要配置DWRSERVLET+dwr.xml文件.使用annonation实现. 希望对你有用. 一起学习,一起进步...
Spring+Dwr+Hibernate整合项目,包括所需要的包和数据库
DWR整合Spring MVC ,前端jsp文件调用后台java方法,适合DWR学习