有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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) 个答案

  1. # 1 楼答案

    spring-ws-core需要spring-webmvc,您无法避免,因为一些核心Spring WS类是在Spring WebMVC类(包括MessageDispatcherServlet)之上构建的

    spring-ws-corePOM定义了对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之前