【问题标题】:Correct the classpath of your application so that it contains a single, compatible version of ServletServerContainerFactoryBean更正应用程序的类路径,使其包含单个兼容版本的 ServletServerContainerFactoryBean
【发布时间】:2022-02-03 10:35:38
【问题描述】:

我在尝试将 Spring 项目从 4.3.2 升级到最新项目时遇到问题。 项目使用:4.1.1.Release安全和4.3.2 Spring框架。 我正在尝试将它们升级到 5.3.13Release 和 5.2.19.Release for spring。

App 也使用 websockets:

更正应用程序的类路径,使其包含一个兼容的 org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean 版本

spring依赖是:

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-websocket</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-cas</artifactId>
        <version>${spring-security.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
        </exclusions>
    </dependency>


    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
        <version>${spring.version}</version>

        <exclusions>
            <exclusion>
                <groupId>org.springframework.security</groupId>
                <artifactId>spring-security-web</artifactId>
            </exclusion>
        </exclusions>

    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring-security.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring-security.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

【问题讨论】:

  • 你的依赖是一团糟。您正在将 Spring Boot(无论版本)与不兼容的 Spring 版本相结合。如果您使用的是 Spring Boot,则不能简单地升级 Spring 版本,因为正在使用的 Spring Boot 版本是为某个 Spring 版本构建的。
  • 是的。这不是我的项目。这是我被要求升级的项目。但我一直面临这个问题。
  • 如上所述,使用 spring boot 时不能简单地升级 spring。您需要升级 Spring Boot,并在使用它时修复依赖关系。解决这个问题会让你的生活更轻松。
  • 谢谢。我会努力这样做的

标签: java spring spring-mvc spring-security spring-websocket


【解决方案1】:

首先,您不能为 Spring Boot 升级 Spring,因为它与特定的 Spring 主要版本相关联。要升级 Spring,您需要升级到更新的 Spring Boot 版本。

其次,你的依赖是一团糟。许多不需要的排除项和其他不需要的依赖项。

清理后的版本

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
</dependency>

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

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

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

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-cas</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <scope>provided</scope>
</dependency>

这是针对 Spring (Boot) 依赖项。删除 spring.versionspring-security.version 除非你真的想覆盖它(这可以在同一个主要版本中完成!)但你可能最好使用新的 Spring Boot 版本(更新父版本)。

可能有更多的依赖项(spring-boot-starter-data-jpa 已经进入休眠状态,因此您也可以删除该显式依赖项)。

【讨论】:

  • 非常感谢您的回复。我尝试了此配置并删除了不必要的依赖项,但仍然收到错误消息。 :(
  • 您的列表可能并不广泛/完整,因此可能还有更多。此外,您应该从 &lt;properties&gt; 块中删除 spring.versionspring-security.version
  • 缺少邮件发件人依赖项,因此我添加了它并将所有 Spring Boot 依赖项放入版本 1.5.22.RELEASE。再次: 描述:试图调用一个不存在的方法。尝试从以下位置进行:hr.igea.webgis.web.websocket.WebSocketConfig.createWebSocketContainer(WebSocketConfig.java:23) //etc 操作:更正应用程序的类路径,使其包含单个兼容版本org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean
  • 在这些依赖项和其他一些依赖项版本(jackson)的帮助下,我必须修复,项目成功运行。非常感谢 M. Deinum。
猜你喜欢
  • 1970-01-01
  • 2022-01-01
  • 2021-06-29
  • 2019-08-11
  • 2021-07-08
  • 2021-11-07
  • 2021-04-14
  • 1970-01-01
相关资源
最近更新 更多