使用spring-ws执行基于SOAP的应用程序。但是,如果我添加以下依赖项(从spring教程https://spring.io/guides/gs/producing-web-service/中看到),
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>它也吸引着spring-webmvc。如果我把它排除在外
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>我在这里出了差错;
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
//ERROR Here
//cannot find symbol
//symbol: method setApplicationContext(ApplicationContext)
//location: variable servlet of type MessageDispatcherServlet
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}他们不是把模块分开了吗?当我只需要spring-webmvc时,为什么我必须使用spring-ws?
我在这里不明白什么?
发布于 2016-01-18 06:44:59
spring-ws-core需要spring-webmvc,您无法避免这一点,因为一些Spring核心类构建在Spring类之上(包括MessageDispatcherServlet)。
spring-ws-core POM定义了对spring-webmvc的显式依赖。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.9.RELEASE</version>
<scope>compile</scope>
</dependency>在maven中添加排除很少是一个好主意--有时您需要这样做,但您几乎是说,您认为自己比packager更好地理解库依赖关系,而且您可能不理解。
至于错误消息,MessageDispatcherServlet是从org.springframework.web.servlet.FrameworkServlet继承的,后者被打包在spring-webmvc中。setApplicationContext方法定义在FrameworkServlet上,但只在Spring的4.x版本中添加。
添加排除时,其净效果似乎是在将setApplicationContext添加到FrameworkServlet之前,最终得到了一个较旧版本的spring。
https://stackoverflow.com/questions/34847898
复制相似问题