用到的Jar : com.noelios.restlet.ext.spring_2.5.jar
org.restlet.ext.spring_2.5.jar
asm-1.5.3.jar
cglib-2.1_3.jar
定义 resource 类:
public class RequestMergeResource extends Resource{
public void init(Context context, Request request, Response response) {
super .init(context, request, response);
// This representation has only one type of representation.
getVariants().add( new Variant(MediaType. TEXT_PLAIN ));
setModifiable( true );
}
public Representation represent(Variant variant) throws ResourceException {}
public void acceptRepresentation(Representation entity) throws ResourceException {}
}
配置 bean :
<!-- 配置 resource-->
<bean id= "RequestMergeRoute" class= "org.restlet.ext.spring.SpringRouter" >
<property name= "attachments" >
<map>
<entry key= "/requestMerge" >
<bean class= "org.restlet.ext.spring.SpringFinder" >
<lookup-method name= "createResource" bean= "RequestMergeResource" />
</bean>
</entry>
</map>
</property>
</bean>
<bean id= "RequestMergeResource"
class= "restlet.resource.requestmerge.RequestMergeResource" >
<property name= "breadService" ref= "breadService" />
<property name="bookService" ref="bookService" />
</bean>
<!-- 配置 resource 完毕 -->
<!-- 配置 application-->
<bean id= "component" class= "org.restlet.ext.spring.SpringComponent" >
<property name= "defaultTarget" ref= "restRoute" />
</bean>
<bean id= "restRoute" class= "org.restlet.ext.spring.SpringRouter" >
<property name= "attachments" >
<map>
<entry key= "/requestMerge" value-ref= "RequestMergeRoute" />
</map>
</property>
</bean>
<!-- 配置 application 完毕 -->
配置 web.Xml
<context-param>
<param-name> contextConfigLocation </param-name>
<param-value>
classpath:spring.xml;classpath*:restlet/**/*.xml;
</param-value>
</context-param>
<servlet>
<servlet-name> restlet </servlet-name>
<servlet-class> com.noelios.restlet.ext.spring.SpringServerServlet </servlet-class>
<init-param>
<param-name> org.restlet.component </param-name>
<param-value> component </param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name> restlet </servlet-name>
<url-pattern> /rest/* </url-pattern>
</servlet-mapping>
输入: http://localhost:8080/projectName/rest/requestMerge/requestMerge
搞定!!!!!!!!!!