java - 带有 @RequestMapping 注释的 ReSTLet 不起作用

标签 java spring annotations restlet

我的应用程序中有一些 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配置,可以按照以下两种方式:

关于java - 带有 @RequestMapping 注释的 ReSTLet 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24228465/

相关文章:

java - struts2 创建 session 对象,为什么以及何时?

Spring Boot : Is it possible to use external application. 带有胖 jar 的任意目录中的属性文件?

java - Swagger 与 @RepositoryRestController 配合使用

java - Wildfly 忽略 Jackson 注释并且不使用 @Provider 类

java - 在没有泛型的情况下从 TypeElement 获取父类(super class)?

java - 使用数据提供者编写 Java 测试

java - 删除操作的JPA和DAO实现

java - 我对 Spring Rest 服务的 ajax 调用永远处于挂起状态

java - JPA 每组最新行

Javadoc 使用 @value 在内部类常量上显示值