使用spring-ws
执行基于SOAP的应用程序。但是,如果我添加以下依赖项(从spring-boot教程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
?
我在这里不明白?
答案 0 :(得分:2)
spring-ws-core
需要spring-webmvc
,你无法避免这种情况,因为一些核心的Spring-WS类是在Spring-WebMVC类(包括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中添加排除项很少是一个好主意 - 有时您需要这样做,但是您几乎都说您认为您比包装程序更好地理解库依赖项,而您可能不会。
对于错误消息,MessageDispatcherServlet
继承自org.springframework.web.servlet.FrameworkServlet
,spring-webmvc
打包。在setApplicationContext
上定义的FrameworkServlet
方法,但仅在 Spring-WebMVC 的4.x版本中添加。
当您添加排除时,从setApplicationContext
添加到FrameworkServlet
之前,看起来效果是您最终使用旧版本的spring-webmvc。