@boot注解在Spring Boot中的spring-boot-starter-jersey资源上的用途 [英] Purpose of @Component annotation on spring-boot-starter-jersey resources in Spring boot

查看:86
本文介绍了@boot注解在Spring Boot中的spring-boot-starter-jersey资源上的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Path("test")
public TestResource {

    @GET
    public Response testGet() {
        return Response.ok().build();
    }

}

从Spring Boot文档的JAX-RS和Jersey上的部分开始,例如,所有注册的端点都应该是带有HTTP资源注释的@Components(@GET等)".上面的资源仍然可以在没有@Component批注的情况下使用.省略@Component注释会破坏什么?

From the spring boot documentation, the section on JAX-RS and Jersey, "All the registered endpoints should be @Components with HTTP resource annotations (@GET etc.), e.g.". The above resource still works without the @Component annotation. What would I be breaking by leaving out the @Component annotation?

推荐答案

为了使JAX-RS资源能够运行需要代理的Spring功能,例如Spring事务管理(使用@Transactional),Spring Security和面向方面的编程(例如@Aspect),资源本身必须由Spring管理,方法是使用@ Component,@ Service,@ Controller或@Repository进行注释:"

"To enable JAX-RS resources to work Spring functionality that requires proxying, such as Spring transaction management (with @Transactional), Spring Security and aspect oriented programming (such as @Aspect), the resources must themselves be managed by Spring, by annotating with @Component, @Service, @Controller or @Repository:"

这篇关于@boot注解在Spring Boot中的spring-boot-starter-jersey资源上的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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