---
title: "restlet学习笔记-在spring中如何配置application和resource"
author: "andyjackson"
date: "2010-07-21T17:36:54Z"
tags: []
categories: ["企业架构"]
slug: "restlet-spring-application-resource"
draft: false
lastmod: "2010-07-30T20:38:28Z"
id: 718136
url: "https://ajwang.iteye.com/blog/718136"
---

在官方给的spring和restlet结合的例子中，仅仅给出了一个将所有的resources交由spring管理的方式。这样直接跳过了application的配置。但是，他会带来一个问题：无法伪造PUT和DELETE方法。当然，也可以让spring来管理application，然后由application自己管理自己的resources。但是，这样，resources无法由spring来注入dao。([详细在ajax的博客中：有详细介绍](http://ajaxcn.iteye.com/blog/434449) )。我今天仔细研究了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