首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分离Spring和Spring

分离Spring和Spring
EN

Stack Overflow用户
提问于 2016-01-18 05:35:45
回答 1查看 1.3K关注 0票数 1

使用spring-ws执行基于SOAP的应用程序。但是,如果我添加以下依赖项(从spring教程https://spring.io/guides/gs/producing-web-service/中看到),

代码语言:javascript
复制
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

它也吸引着spring-webmvc。如果我把它排除在外

代码语言:javascript
复制
        <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>

我在这里出了差错;

代码语言:javascript
复制
@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

我在这里不明白什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-18 06:44:59

spring-ws-core需要spring-webmvc,您无法避免这一点,因为一些Spring核心类构建在Spring类之上(包括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

代码语言:javascript
复制
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.0.9.RELEASE</version>
  <scope>compile</scope>
</dependency>

在maven中添加排除很少是一个好主意--有时您需要这样做,但您几乎是说,您认为自己比packager更好地理解库依赖关系,而且您可能不理解。

至于错误消息,MessageDispatcherServlet是从org.springframework.web.servlet.FrameworkServlet继承的,后者被打包在spring-webmvc中。setApplicationContext方法定义在FrameworkServlet上,但只在Spring的4.x版本中添加。

添加排除时,其净效果似乎是在将setApplicationContext添加到FrameworkServlet之前,最终得到了一个较旧版本的spring。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34847898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档