【发布时间】:2017-04-13 22:25:59
【问题描述】:
我有 springBoot 独立应用程序。我在我的独立应用程序中使用了@SpringBootApplication、@ServletComponentScan 注释。我所有的组件,bean 在 spring 容器中初始化并在应用程序启动时打印。
在我的 servlet 中,我调用了处理程序,并且 bean 以 null 的形式出现。我如何通过我的 servlet 传递 spring 容器?
@SpringBootApplication
@ServletComponentScan
public class AStandaloneApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(AStandaloneApplication.class, args);
}
}
@WebServlet("/ba")
public class BAServlet extends SpeechletServlet {
@Autowired
private BASpeechletHandler bASpeechletHandler;
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
this.setSpeechlet(bASpeechletHandler);
}
}
public class BASpeechletHandler implements Speechlet {
@Autowired
private BSEngine bSEngine;
@Autowired
private IBotResponseObjToAlexaSpeechletResponseObj botResponseObjToAlexaSpeechletResponseObj;
}
bASpeechletHandler 在 servlet 中为空,如果我在我的 servlet 中为 bASpeechletHandler 设置对象并继续前进,那么 bASpeechletHandler 中的组件、服务和存储库也为空。 谢谢。
【问题讨论】:
-
如果你使用的是Servlet,它不再是独立的了,分享你的代码
-
嗨@SundararajGovindasamy,谢谢。我用代码 sn-p 更新了问题
标签: spring servlets spring-boot