春天与春天Restlet:100%XML配置? [英] Spring & Restlet : 100% XML configuration?

查看:126
本文介绍了春天与春天Restlet:100%XML配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个项目中,所有配置都保存在XML文件中.我将在该项目的一小部分开始,而我将使用Restlet.基本上,我想做的是创建ServerResource的一些子类.

I'm working on a project where all configurations are kept in XML files. I'm about to begin on a smaller part of this project, and I'll be using Restlet for that. Basically, what I'd like to do is to create a few subclasses of ServerResource.

我可以使用注释来指定哪些类方法接受哪些HTTP方法,但是由于我将XML用于其他所有内容,因此我有点勉强.有没有一种方法可以将HTTP方法映射到Restlet资源的类方法?

I could use annotations to specify which class methods accepts which HTTP methods, but since I'm using XML for everything else I'm a bit reluctant. Is there a way to map HTTP methods to class methods for Restlet resources?

Spring和Restlet之间的实际集成仅是XML(webcontext.xml):

The actual integration between Spring and Restlet is XML only (webcontext.xml) :

  <bean id="apiComponent" class="org.restlet.ext.spring.SpringComponent">
    <property name="defaultTarget" ref="apiAppliction" />
  </bean>

  <bean id="apiAppliction" class="com.company.api.ApiApplication">
    <property name="inboundRoot" ref="router" />
  </bean>

  <!-- Define the router -->
  <bean name="router" class="org.restlet.ext.spring.SpringBeanRouter" />

  <!-- Define all the routes -->
  <bean name="/track/{trackId}" class="com.company.api.resource.TrackResource" scope="prototype" autowire="byName">
      <constructor-arg index="0" ref="serviceFactory"/> 
  </bean>
  <bean name="/album" class="com.company.api.resource.AlbumResource" scope="prototype" autowire="byName"/>  
  <bean name="/album/{albumId}/tracks" class="com.company.api.resource.AlbumTracksResource" scope="prototype" autowire="byName" />

是否可以添加上述配置并将HTTP方法映射到类方法?

Is there a way I can add to the above configuration and map HTTP methods to class methods?

推荐答案

事实上,没有.您不能使用Restlet本身和Spring配置来定义HTTP方法和目标服务器资源方法之间的映射.

In fact, no. You can't define the mapping between HTTP methods and target server resource methods both with Restlet itself and with Spring configuration.

实际上,这是Restlet的两个不同部分:

In fact, these are two different distinct parts of Restlet:

  • 定义路由以处理请求(身份验证,过滤器,服务器资源等).这是在方法createInboundRoot(您的bean apiAppliction的属性inboundRoot)的Restlet应用程序类中完成的.
  • HTTP方法漫游的定义.选择要使用的服务器资源后,将在服务器资源内部显式地进行此操作(使用方法handleRequest中的测试)或使用批注.
  • Definition of the routing to handle requests (authentication, filters, server resources and so on). This is done within the Restlet application class within the method createInboundRoot (your property inboundRoot for your bean apiAppliction).
  • Definition of the rounting for HTTP methods. Once the server resource to use is selected, this is done internally to the server resource explicitely (with tests within the method handleRequest) or using annotations.

实际上,Spring MVC具有相同的功能.在Spring容器中定义检测控制器的方式(例如,基于注释Controller的自动检测),然后使用专用注释配置控制器.

In fact, you have the same thing with Spring MVC. You define the way to detect the controllers in the Spring container (auto-detection based on the annotation Controller for example) and then you configure your controllers using dedicated annotations.

此外,Roger Stocker改进了基于XML名称空间的Spring扩展(请参阅此链接

In addition, Roger Stocker provides an improvment of Spring extension based on an XML namespace (see this link http://code4you.org/2013/07/spring-custom-xml-namespace-scheme-for-the-restlet-framework/). This contribution is currently in incubation to be integrated in the official Spring extension.

希望有帮助, 蒂埃里

这篇关于春天与春天Restlet:100%XML配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆