java分离SpringWS和SpringWebmvc
使用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
我不明白的是什么
# 1 楼答案
spring-ws-core
需要spring-webmvc
,您无法避免,因为一些核心Spring WS类是在Spring WebMVC类(包括MessageDispatcherServlet)之上构建的spring-ws-core
POM定义了对spring-webmvc
的显式依赖关系从https://repo1.maven.org/maven2/org/springframework/ws/spring-ws-core/2.2.4.RELEASE/spring-ws-core-2.2.4.RELEASE.pom
在maven中添加排除很少是一个好主意——有时你需要这样做,但你几乎是在说你认为你比打包程序更好地理解库的依赖关系,而你可能不这么认为
至于错误消息,
MessageDispatcherServlet
继承自org.springframework.web.servlet.FrameworkServlet
,它打包在spring-webmvc
中。在FrameworkServlet
上定义的setApplicationContext
方法,但仅在4中添加。x发布Spring WebMVC当你添加排除项时,看起来净效果是你最终得到了一个旧版本的spring webmvc,它是在
setApplicationContext
被添加到FrameworkServlet
之前