<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-34  評論-1965  文章-0  trackbacks-0

    前些日子看了一篇關于在Spring 2中整合DWR 2的文章《AJAX, DWR and Spring》。最近,想動手試一下,就下載其源代碼回來看看,依葫蘆畫瓢做了一遍。在運行時,得到XML驗證錯誤。經過一翻折騰,終于把問題解決。

    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開發中的配置文件泛濫的問題。

    posted on 2007-01-31 16:45 Max 閱讀(17384) 評論(6)  編輯  收藏 所屬分類: 方法與技巧(Tips & tricks)

    評論:
    # re: 在Spring 2中整合DWR 2 2008-04-26 15:11 | yidwo
    個人覺得這樣把Spring的配置信息和dwr的配置信息放在一起.
    認為相當之雜亂, 修改與維護時查找不方便,配置文件也顯得冗長.
    分開來更符合實際點.
    dwr調用Spring類時可以如此:
    <create javascript="jsname" creator="spring">
    <param name="beanName" value="beanId" />
    </create>  回復  更多評論
      
    # re: 在Spring 2中整合DWR 2 2008-05-22 11:29 | xx
    看不懂,亂  回復  更多評論
      
    # re: 在Spring 2中整合DWR 2 2008-06-05 11:34 | elary
    實際意義并不大,覺得只是浪費時間。  回復  更多評論
      
    # re: 在Spring 2中整合DWR 2 2008-07-23 11:58 | 愛上對方是多方
    可以在@yidwo
    這樣可以統一配置,并且可以隨時注入需要的bean  回復  更多評論
      
    # re: 在Spring 2中整合DWR 2 2009-12-17 16:47 | weiyi
    哥們, 看了你的文章。 照著來, 可是結果老報錯啊

    (1)報錯:
    <dwr:configuration>
    <dwr:create javascript="supPowerMenu" type="spring">
    <dwr:param name="beanName" value="supPowerManager"/>
    <dwr:include method="findRolePowerJDBC"/>
    </dwr:create>
    </dwr:configuration>

    Info:
    -------------------------
    Exception on invoking context event listener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__dwrConfiguration': Cannot resolve reference to bean '__supPowerMenu' while setting bean property 'creators' with key [supPowerMenu]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__supPowerMenu': Cannot create inner bean '(inner bean)' of type [org.directwebremoting.spring.SpringCreator] while setting bean property 'creator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'beanClass' of bean class [org.directwebremoting.spring.SpringCreator]: No property 'beanClass' found
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '__supPowerMenu': Cannot create inner bean '(inner bean)' of type [org.directwebremoting.spring.SpringCreator] while setting bean property 'creator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'beanClass' of bean class [org.directwebremoting.spring.SpringCreator]: No property 'beanClass' found
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1': Initialization of bean failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'beanClass' of bean class [org.directwebremoting.spring.SpringCreator]: No property 'beanClass' found
    Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'beanClass' of bean class [org.directwebremoting.spring.SpringCreator]: No property 'beanClass' found
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:376)

    -------------------------

    (2)不報錯:
    <dwr:create javascript="supUserCode" type="new" class="com.xxx.supervision.managers.impl.UserManagerImpl">
    <dwr:include method="checkUserCodeUniqueJDBC"/>
    </dwr:create>
    但是DWR調試下,沒生成supUserCode.js  回復  更多評論
      
    # re: 在Spring 2中整合DWR 2 2009-12-17 16:51 | weiyi
    說明下:supPowerManager是已經定義好的beanId,沒問題。

    幫幫忙! 指點指點

    問題出在什么地方了?
      回復  更多評論
      
    主站蜘蛛池模板: 国产成人亚洲精品| 麻豆成人精品国产免费| 99ri精品国产亚洲| 久久九九AV免费精品| 亚洲国产精品无码专区影院 | 亚洲国产一级在线观看| 久久无码av亚洲精品色午夜| 老司机永久免费网站在线观看| 亚洲一区二区无码偷拍| 最近中文字幕无吗免费高清| 亚洲成A人片在线播放器| 成人片黄网站色大片免费| 亚洲免费福利在线视频| 在线视频免费观看www动漫| 亚洲精品无码人妻无码| 日韩成全视频观看免费观看高清| 亚洲AV无码国产一区二区三区| 国产美女被遭强高潮免费网站| 无码天堂va亚洲va在线va| 亚洲av午夜成人片精品电影| jizz免费观看| 国产成A人亚洲精V品无码| 无码人妻精品中文字幕免费 | 成年性羞羞视频免费观看无限| 亚洲欧美一区二区三区日产| 日韩视频在线免费| 水蜜桃视频在线观看免费| 久久久亚洲精品蜜桃臀| 国产一级片免费看| 亚洲毛片无码专区亚洲乱| 成人免费无码视频在线网站| 久久亚洲欧美国产精品| 中文字幕亚洲日韩无线码| 嫩草在线视频www免费观看| 亚洲的天堂av无码| 毛片视频免费观看| 免费一级毛片在线播放放视频 | 一区二区免费视频| 亚洲av永久无码精品天堂久久| 尤物永久免费AV无码网站| a级毛片免费高清视频|