Vinay Nagaraj
Vinay Nagaraj

Reputation: 1192

Purpose of @Component annotation on spring-boot-starter-jersey resources in Spring boot

@Path("test")
public TestResource {

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

}

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?

Upvotes: 2

Views: 603

Answers (1)

Vinay Nagaraj
Vinay Nagaraj

Reputation: 1192

"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:"

Upvotes: 1

Related Questions