【问题标题】:spring boot with JAX-RS resources带有 JAX-RS 资源的 spring boot
【发布时间】:2014-04-15 16:13:51
【问题描述】:

如何通过 Spring Boot 配置 JAX-RS 资源以在嵌入式 tomcat 容器中可用?

以下是我拥有的 JAX-RS 资源(Groovy):

@Component
@Path('files')
@CompileStatic
class MyResource  {
    @Autowired
    FileRepository repository

    @GET
    @Path('{id}')
    @Produces(value = MediaType.APPLICATION_JSON)
    Response getFileDetails(@PathParam("id") String id) {
        println "getFileDetails called with $id"
        return Response.ok().build()
    }

}

当我尝试使用 localhost:8080/files/123 进行 http GET 时,我收到 404 错误。我错过了什么? 我在 tomcat 启动期间没有看到错误。

【问题讨论】:

    标签: jax-rs spring-boot


    【解决方案1】:

    我必须在 SpringApplication.run 中指定 jersey SpringServlet。这样就解决了。

    @Configuration
    @EnableAutoConfiguration
    @ComponentScan
    class Application {
        public static void main(String[] args) {
            ApplicationContext context = SpringApplication.run(
                    [SpringServlet.class,
                    "classpath:/META-INF/bootstrap.xml"] as Object [], args)
        }
    }
    

    【讨论】:

    • @Fredrik com.sun.jersey.contribs:jersey-spring:1.16。我还在 Jersey 1.x
    猜你喜欢
    • 2019-01-08
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2016-02-14
    • 1970-01-01
    相关资源
    最近更新 更多