andyjackson 发表于 2013-1-29 11:55:46

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

在官方给的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
页: [1]
查看完整版本: restlet学习笔记-在spring中如何配置application和resource