簡體   English   中英

分離Spring-WS和Spring-Webmvc

[英]Separating Spring-WS and Spring-Webmvc

使用spring-ws基於SOAP的應用程序。 但是,如果我添加了以下依賴關系(從spring-boot教程https://spring.io/guides/gs/production-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-ws時必須使用spring-webmvc

我在這里不明白嗎?

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

當您添加排除項時,看起來最終效果是從setApplicationContext添加到FrameworkServlet之前, setApplicationContext是spring-webmvc的舊版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM