简体   繁体   中英

Separating Spring-WS and Spring-Webmvc

Doing a SOAP based application using spring-ws . But if i add this following dependency (saw from spring-boot tutorials https://spring.io/guides/gs/producing-web-service/ ),

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

It also pulls spring-webmvc . If i exclude it,

        <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>

I get error here;

@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/*");
}

Arn't they separate modules? Why i must use spring-webmvc , when i just need spring-ws ?

What i don't understand here?

spring-ws-core needs spring-webmvc , you can't avoid that as some of the core Spring-WS classes are built on top of Spring-WebMVC classes (including MessageDispatcherServlet).

The spring-ws-core POM defines an explicit dependency on spring-webmvc

From 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>

Adding exclusions in maven is rarely a good idea - sometimes you need to do it, but you're pretty much saying that you think you understand the libraries dependencies better than the packager did, and you probably don't.

As for the error message, MessageDispatcherServlet inherits from org.springframework.web.servlet.FrameworkServlet , which is packaged in spring-webmvc . The setApplicationContext method defined on FrameworkServlet , but was only added in the 4.x release of Spring-WebMVC .

When you add the exclusion, it looks like the net effect is that you're ending up with an older version of spring-webmvc, from before setApplicationContext was added to FrameworkServlet .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM