六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 52|回复: 0

restlet学习笔记-在spring中如何配置application和resource

[复制链接]

升级  6.67%

14

主题

14

主题

14

主题

秀才

Rank: 2

积分
60
 楼主| 发表于 2013-1-29 11:55:46 | 显示全部楼层 |阅读模式
在官方给的spring和restlet结合的例子中,仅仅给出了一个将所有的resources交由spring管理的方式。这样直接跳过了application的配置。但是,他会带来一个问题:无法伪造PUT和DELETE方法。当然,也可以让spring来管理application,然后由application自己管理自己的resources。但是,这样,resources无法由spring来注入dao。(详细在ajax的博客中:有详细介绍)。我今天仔细研究了restlet给出的关于spring的扩展包,发现还有第三种方法。将application和resources都交给spring来管理,并且由spring为每个application分配resources。
<bean id="component" class="org.restlet.ext.spring.SpringComponent"><property name="defaultTarget" ref="application" /></bean><bean id="application" class="burenzheng.ResourceApplication"><lookup-method name="createRoot" bean="resource" /></bean>  <bean id="resource" class="org.restlet.ext.spring.SpringRouter"><property name="attachments"><map><entry key="/items"><bean class="org.restlet.ext.spring.SpringFinder"><lookup-method name="createResource" bean="itemsResource" /></bean></entry><entry key="/items/{id}"><bean class="org.restlet.ext.spring.SpringFinder"><lookup-method name="createResource" bean="itemResource" /></bean></entry></map></property></bean><bean id="itemsResource" class="burenzheng.ItemsResource" /><bean id="itemResource" class="burenzheng.ItemResource" /> 相信大家应该能够看懂,其实关键就是:我们知道是在Applciation的createRoot方法中为application配置resources,那么,现在最关键的就是如何配置这个方法?
sprig的lookup-method,就能够解决它。然后,大家可以在自己的构造函数中伪造PUT和DELETE
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表