我正在努力在Tomcat / Jersey服务器中使用Spring注入依赖项。我有这个:
@Component
public class TextEntryFacade { ... }
这:
@Component
public class TextEntryController {
@Autowired
public class TextEntryController(final TextEntryFacade textEntryFacade) {
...
}
...
}
但是我明白了:
java.lang.NoSuchMethodException: Could not find a suitable constructor in com.tuiasi.petru.sop.service.controller.TextEntryController class.
org.glassfish.jersey.internal.inject.JerseyClassAnalyzer.getConstructor(JerseyClassAnalyzer.java:192)
org.jvnet.hk2.internal.Utilities.getConstructor(Utilities.java:179)
org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:993)
...
我真的不了解HK2和Spring在这种情况下如何相互作用。我以为Spring会从HK2那里接管依赖注入,但似乎我错了。非常感谢。
答案 0 :(得分:0)
您是否尝试过像这样基于构造函数的注入?
@Component
public class TextEntryController {
private final TextEntryFacade textEntryFacade
public class TextEntryController(TextEntryFacade textEntryFacade) {
this.textEntryFacade = textEntryFacade;
}
...
}