【问题标题】:Multiple versions of spring boot多个版本的spring boot
【发布时间】:2020-02-16 13:11:19
【问题描述】:

我正在运行 Spring 应用程序并收到以下错误:java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.websocket.WebSocketAutoConfiguration$TomcatWebSocketConfiguration.websocketContainerCustomizer

in this question 已经回答了类似的问题。在接受的答案中,Gergely Bacso 指出问题在于 Spring Boot 的多个版本。

堆栈跟踪列出了SpringBootCondition.java 中发生的错误,当我尝试单击它时,会看到两个不同的 Spring Boot 版本,如下图所示:

我的问题是:1)这就是我得到这个例外的原因吗? 2)如果是这样,我该如何摆脱额外的版本? (或者,如果没有,还有其他想法为什么会发生这种情况?)

作为参考,这里是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>murraco</groupId>
    <artifactId>jwt-auth-service</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>spring-boot-jwt</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <start-class>taskorchard.JwtAuthServiceApp</start-class>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.6.RELEASE</version>
        <relativePath /> <!-- lookup parentId from repository -->
    </parent>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.8</version>
        </dependency>

        <dependency>
            <!-- Setup Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>ch.qos.logback</groupId>
                    <artifactId>logback-classic</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <!-- JPA Data (Repositories, Entities, Hibernate, etc..) -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <!-- Starter for using Spring Security -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <!-- Make method based security testing easier -->
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <!-- Automatically restart whenever files on the classpath change -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <!-- Automated JSON API documentation for API's built with Spring -->
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.7.0</version>

        </dependency>
        <dependency>
            <!-- Generate beautiful documentation from a Swagger-compliant API. -->
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.7.0</version>
        </dependency>
        <dependency>
            <!-- JSON Web Token Support -->
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.7.0</version>
        </dependency>
        <dependency>
            <!-- Model Mapper -->
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

这是我的 application.yml:

spring:
  datasource: #TODO replace application.yml with an xml or java config file
    url: jdbc:${DBURL} #localhost/taskorchard
    username: ${DBUSER}
    password: ${DBPASSWORD}
  tomcat:
    max-wait: 20000
    max-active: 50
    max-idle: 20
    min-idle: 15
  jpa:
    hibernate:
      ddl-auto: validate
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        format_sql: true
        id:
          new_generator_mappings: false

server:
   port: 8080 # This is the default port anyway, but you can change it here

security:
  jwt:
    token:
      secret-key: secret-key
      expire-length: 300000 # 5 minutes duration by default: 5 minutes * 60 seconds * 1000 miliseconds

UserController:
  signin: Authenticates user and returns its JWT token.
  signup: Creates user and returns its JWT token
  delete: Deletes specific user by username
  search: Returns specific user by username
  me: Returns current user's data

当我运行我的 maven 依赖树时,我看到了这个:

/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/jimstewart/Git/ermine-defrock "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=50853:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version2019.1.4 dependency:tree
objc[82632]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java (0x1029ef4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x102a734e0). One of the two will be used. Which one is undefined.
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< murraco:jwt-auth-service >----------------------
[INFO] Building spring-boot-jwt 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ jwt-auth-service ---
[INFO] murraco:jwt-auth-service:jar:1.0.0
[INFO] +- org.postgresql:postgresql:jar:42.2.8:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.6.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.6.RELEASE:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.6.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.16:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.16:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.16:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.9:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.9:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.10.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.10.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:4.3.10.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.10.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.10.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.6.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.10:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.6.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.16:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.16:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.10.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.12.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.12.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.11.6.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.13.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.10.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.10.RELEASE:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.10.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.10.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-test:jar:4.2.3.RELEASE:test
[INFO] |  +- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.10.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.10.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.6.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.6.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.6.RELEASE:compile
[INFO] +- com.h2database:h2:jar:1.4.196:runtime
[INFO] +- io.springfox:springfox-swagger2:jar:2.7.0:compile
[INFO] |  +- io.swagger:swagger-annotations:jar:1.5.13:compile
[INFO] |  +- io.swagger:swagger-models:jar:1.5.13:compile
[INFO] |  +- io.springfox:springfox-spi:jar:2.7.0:compile
[INFO] |  |  \- io.springfox:springfox-core:jar:2.7.0:compile
[INFO] |  |     \- net.bytebuddy:byte-buddy:jar:1.6.14:compile
[INFO] |  +- io.springfox:springfox-schema:jar:2.7.0:compile
[INFO] |  +- io.springfox:springfox-swagger-common:jar:2.7.0:compile
[INFO] |  +- io.springfox:springfox-spring-web:jar:2.7.0:compile
[INFO] |  |  \- org.reflections:reflections:jar:0.9.11:compile
[INFO] |  +- com.google.guava:guava:jar:18.0:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] |  \- org.mapstruct:mapstruct:jar:1.1.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.7.0:compile
[INFO] +- io.jsonwebtoken:jjwt:jar:0.7.0:compile
[INFO] \- org.modelmapper:modelmapper:jar:1.1.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.357 s
[INFO] Finished at: 2019-10-19T21:34:36-04:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

【问题讨论】:

  • SpringBoot 2.2.0 是几天前刚刚发布的,也许有一些关于那个。但是您似乎没有导入其他依赖于另一个 SpringBoot 版本的依赖项,奇怪
  • 我看到 SpringBoot 2.2.0 最近被添加到我的 Project Structure-->modules 中。但是当我尝试取出它时,Spring 根本无法正确编译,即使我取出添加之前添加的任何代码。
  • 试试把&lt;version&gt;1.5.6.RELEASE&lt;/version&gt;改成2.2.0.RELEASE吧?
  • 通常你不应该自己定义通过 Spring 继承的版本。除此之外,我无法用给定的 pom 重现您的问题...是否尝试在普通命令行上构建?

标签: spring maven spring-boot


【解决方案1】:

好的,我想通了。我去了文件-->项目结构,在那里看到了spring-boot-starter-test.2.2.0。当我删除它时,一开始我不知道发生了什么,因为我之前排除了 log4j.logger-classic 模块,因为与 log4j 版本的不同冲突,所以当程序正确运行时我没有看到日志并且不知道它正在运行。

如果您有类似的问题并且无法解决,请对此发表评论,我会尽力帮助您。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2023-03-20
    • 2021-01-12
    • 1970-01-01
    • 2016-02-01
    • 2021-07-27
    相关资源
    最近更新 更多