2016-01-18 35 views
1

使用spring-ws做基于SOAP的应用程序。但是,如果我添加此以下依赖(从春季引导教程https://spring.io/guides/gs/producing-web-service/锯),分离Spring-WS和Spring-Webmvc

<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

请详细说明。 (1)你能不能排除你的屁股? (2)您可以发布实际错误(使用堆栈跟踪)。 – Tim

+0

@Tim:这是编译时错误。在IDE中显示。并更新了问题。 – Raj

+0

在这种情况下,您包含的错误消息显然不是直接复制的。该消息会说更像“没有方法setApplicationContext上....”请逐字粘贴。 – Tim

回答

2

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

<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。在FrameworkServlet上定义的setApplicationContext方法,但仅在4.x版本的Spring-WebMVC中添加。

当您添加排除项目时,看起来最终结果是您的旧版本的spring-webmvc从setApplicationContext被添加到FrameworkServlet之前。