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
大师,burenzheng.ResourceApplication类怎么实现,继承 Application??
您好,感谢您的回复,我的错误已经得到解决,问题出在找不到ApplicationContext.xml文件,之后改变存放的路径就解决了,感谢您的回复!
不好意思,好久没上javaeye了。404是路径错误,可能web.xml配置也有问题。要不你把整个项目发我邮箱,我帮你看看。liyf155@gmail.com
您好,我是一名大四学生,导师要求毕设采用restlet+spring+hibernate的结构实现,在配置中,将与上述类似的配置写入一个xml中
再将其他如sessionfactory等写入applicationcontext.xml中:
但是当测试时发送一个post请求时总会获得404错误,您能指导一下是配置问题还是Resource对于DAO的调用问题。 万分感谢!
大师啊,能否把代码发到圈子里共享的地方供大家下载学习?
大师啊!没想到在这里看到了两位大师的真容!
大师,这么牛逼的文章怎么能不往首页发呢?