我正在尝试运行 Spring 入门指南
(使用 Maven
),但在使用生成 Web 服务
时遇到问题> 一。
此处的指南链接 https://spring.io/guides/gs/producing-web-service/
由于某种原因,我不断收到错误:
The method setApplicationContext(ApplicationContext) is undefined for the type MessageDispatcherServlet
下面的代码:
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
我检查了 API 引用,MessageDispatcherServlet
应该从 FrameworkServlet
继承 setApplicationContext
,但由于某种原因它不存在。
任何帮助将不胜感激。
最佳答案
看起来您的类路径中的 spring-web
版本有误。
setApplicationContext
方法是在版本 4.0 中引入的。
查看官方documentation
关于java - 官方示例中 Spring setApplicationContext 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30029441/