我的应用程序中有一些 ServerResources,它们由 @Service(name)
注释标识。这些方法使用 @Get
和 @Post
ReSTLet 注释进行注释。
一切都工作正常,直到最近我想添加另一个 ServerResource,它必须提供具有不同参数和请求方法的 URL 模式,因此我尝试在以下方法上使用 @RequestMapping
注释:
@Service
public class MyResource extends ServerResource {
@RequestMapping(value="/pathToMyResource/{parameter1}", method=RequestMethod.GET)
public Representation getResponseForGetRequest(Representation entity) {
...
}
//and for the other method:
@RequestMapping(value="/pathToMyResource/{parameter1}/{parameter2}", method=RequestMethod.POST)
public Representation getResponseForPostRequest(Representation entity) {
...
}
...
}
但是,我的资源未正确注册到 org.reSTLet.ext.spring.SpringBeanRouter
,因为请求此 URL 时找不到该资源。
我找出适用于一个资源的多个路径的唯一方法是通过 XML 配置:
<bean name="/pathToMyResource/{parameter1}"
id="myGetResource"
class="com.mycompany.resource.MyResource"
autowire="byName" scope="prototype">
</bean>
<bean name="/pathToMyResource/{parameter1}/{parameter2}"
id="myPostResource"
class="com.mycompany.resource.MyResource"
autowire="byName" scope="prototype">
</bean>
并为方法使用 ReSTLet 注释:
public class MyResource extends ServerResource {
@Get
public Representation getResponseForGetRequest(Representation entity) {
...
}
//and for the other method:
@Post
public Representation getResponseForPostRequest(Representation entity) {
...
}
...
}
您知道@RequestMapping
注释如何与ReSTLet配合使用吗?我想完全避免 XML 配置并尝试找到一种方法让它与注释一起工作...
正如我所提到的,我对仅映射到一个路径的资源没有问题,例如:
@Service("/pathToMyResource/{parameter1}")
public class MyResource extends ServerResource {
...
}
这工作正常...只有多个路径映射会导致问题。
感谢您的帮助!
最佳答案
据我所知,我们不支持从 Spring 框架获取的注释。
如果你想删除任何xml配置,可以按照以下两种方式:
- 使用经典的 ReSTLet 代码:定义一个应用程序,实现 createInboundRoot 方法以定义路由方面,使用带注释的 ServerResource。 (请参阅此页面的简单示例 http://restlet.com/learn/guide/2.2/editions/jse/ ,或此页面的完整代码 http://restlet.com/learn/guide/2.2/introduction/first-steps/first-application ,
- 使用 JaxRs 扩展以依赖 JaxRs 注释(请参阅 http://restlet.com/learn/guide/2.2/extensions/jaxrs)
关于java - 带有 @RequestMapping 注释的 ReSTLet 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24228465/