Spring boot jersey-防止控制器的启动实例化

Spring boot jersey-防止控制器的启动实例化,spring,rest,spring-mvc,spring-boot,jersey,Spring,Rest,Spring Mvc,Spring Boot,Jersey,我正在使用带有web和jersey的spring boot(spring boot jersey starter)。我有一个Jersey端点,需要注入一个请求范围bean。然而,在应用程序启动时,我得到一个找不到bean的错误 @Component @Path("blah") @RequestScoped public class JerseyController{ @Inject private MyEntity entity; } @Component pub

我正在使用带有web和jersey的spring boot(spring boot jersey starter)。我有一个Jersey端点,需要注入一个请求范围bean。然而,在应用程序启动时,我得到一个找不到bean的错误

@Component
@Path("blah")    
@RequestScoped
public class JerseyController{
     @Inject 
     private MyEntity entity;
}

@Component
public class JerseyConfiguration extends ResourceConfig{
    public JeyseyConfiguration(){
       register(JeyseyController.class);
       registere(MyEntityProvider.class);
    }
}

在spring boot web应用程序中,有没有一种方法可以防止spring在收到HTTP请求之前尝试实例化和注入我的Jersey Controller,以便我的Jersey provider可以提供注入的依赖项?

@Jersey资源上不需要组件
。拥有它将导致Spring实例化它(使用默认的单例范围)。我不认为Spring不尊重
@RequestScoped
。这是一个新泽西注释。如果您想使用
@组件
,我认为Spring
@Scope(“request”)
可能会奏效

您还可以删除
@RequestScoped
。这是Jersey资源的默认范围


我唯一一次发现需要在Jersey resources上使用
@组件
,就是我是否需要使用Spring
@值
(可能还需要AOP,但我不太需要AOP)。除此之外,Jersey Spring集成已经支持Spring最常用的功能,即DI。如果您真的想使Jersey资源成为单例,Jersey支持
@singleton
注释。

@组件在Jersey资源上不是必需的。拥有它将导致Spring实例化它(使用默认的单例范围)。我认为Spring不尊重
@RequestScoped
。这是一个新泽西注释。如果您想使用
@组件
,我认为Spring
@Scope(“request”)
可能会奏效。就是这样!谢谢能够删除
@组件
属性