springguice注入未命中

yfwxisqw  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(186)

我正在开发一个使用guice for di的服务。添加了使用springdi的依赖包。为了在spring和guice之间建立桥梁,我将我的服务设置为使用springguice。
服务

class ServiceHelper {
    @Inject
    private CommandBuilder cmdBuilder;

    /**
   @Inject
   private Spec spec;

    public run() {
         // spec is not NULL. (tested if spec injection had happened or not)
    }
  **/

    public run() {
        cmdBuilder.apply();
    }
}

独立Spring组件

@Component
class CommandBuilder {
    @Autowired
    private Spec spec;

    public apply() {
         spec.work(); // spec is coming as NULL if called from CommandBuilder obj.
    }
}

这对我来说很奇怪,而且我的服务器在调用api时不会抛出错误(突出显示任何缺少的依赖项)。
你能从上面看出可能的原因吗 spec 如果从中使用,则为空 CommandBuilder 如果直接注射,效果好吗?
谢谢,安舒

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题