新聞中心
讓DWR和Spring一起工作的步驟
1. 確認(rèn)你用的是***版的DWR。Spring創(chuàng)造器已經(jīng)有了變化,所以你***檢查一下DWR的***版本。
2. 確認(rèn)你查看過開始指南中的內(nèi)容。
3. 確認(rèn)你的Spring的Bean在DWR外面運(yùn)行良好。
4. 配置DWR和Spring一起工作。 (看下面)
5. 查看演示頁面: http://localhost:8080/[ YOUR-WEBAPP ]/dwr ,檢查spring的Bean是否出現(xiàn)。

DWR對于Spring沒有運(yùn)行期依賴,所以如果你不使用Spring那么Spring的支持不會(huì)產(chǎn)生任何影響到。The SpringCreator這個(gè)創(chuàng)造器會(huì)查找spring的中配置的Bean,用Spring去創(chuàng)建它們。如果你已經(jīng)在使用Spring,那么這個(gè)創(chuàng)造器會(huì)非常有用。
你可以通過下面的方式來創(chuàng)建遠(yuǎn)程調(diào)用的Bean:
- ...
creator="spring" javascript="Fred"> - name="beanName" value="Shiela"/>
尋找你的Spring配置
有三種方式尋找配置文件:
ContextLoaderListener
最簡單的方式是使用org.springframework.web.context.ContextLoaderListener。你不必使用所有的Spring-MVC功能,只需要這個(gè)Listener就夠了,所以這是個(gè)不錯(cuò)的方案。你需要在WEB-INF/web.xml中做如下配置:
contextConfigLocation /WEB-INF/classes/beans.xml org.springframework.web.context.ContextLoaderListener
我能找到的ContextLoaderListener的***的文檔就是javadoc。如果你知道還有更好的文檔,請告知我。
Rob Sanheim 指出還有一個(gè)能深入了解ContextLoaderListener的文檔。
使用location*參數(shù)
如果你要在dwr.xml中指定使用哪些bean,你可以使用location*參數(shù)。你可以指定任意多個(gè)文件,只要參數(shù)以location開始并且唯一即可。例如:location-1, location-2。這些location被用做Spring的ClassPathXmlApplicationContext的參數(shù):
- ...
creator="spring" javascript="Fred"> - name="beanName" value="Shiela"/>
- name="location" value="beans.xml"/>
直接設(shè)置BeanFactory
SpringCreator有一個(gè)靜態(tài)方法 setOverrideBeanFactory(BeanFactory) 用來通過編程的方式直接設(shè)置BeanFactory。
配置DWR和Spring
Bram Smeets寫了一個(gè)有意思的blog,教你配置DWR使用beans.xml代替WEB-INF/web.xml。
分享文章:讓DWR和Spring一起工作
分享路徑:http://fisionsoft.com.cn/article/coocjch.html


咨詢
建站咨詢
