Spring启动依赖性问题



我正在尝试将我们的项目从Spring boot 1.4.3升级到2.0.4.RELEASE;

这是我当前的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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SpreadSheetUploadWeb</groupId>
<artifactId>SpreadSheetUploadWeb</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring.version>4.3.9.RELEASE</spring.version>
<spring.boot.version>2.0.4.RELEASE</spring.boot.version>
<db2.driver.version>10.5.9</db2.driver.version>
<spring.batch.version>3.0.8.RELEASE</spring.batch.version>
<tomcat.version>8.5.6</tomcat.version>
<poi.version>3.15</poi.version>
<sonar.coverage.exclusions>**/BlueCostSpreadsheetUploadWebApplication.java</sonar.coverage.exclusions>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
<!-- POI dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>
<!-- DB2 dependencies -->
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc_license_cisuz</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc4</artifactId>
<version>${db2.driver.version}</version>
</dependency>
<!-- HSQLDB dependencies -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version><!--$NO-MVN-MAN-VER$ -->
<scope>test</scope>
</dependency>
<!-- JJD adding to make REST Test cases work 
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency -->
<!-- JJD adding Sonarqube dependency  -->
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
<type>pom</type>
</dependency>   
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<!-- JJD The next two are for generating Swagger Documents for REST api documentation -->
<dependency>     
<groupId>io.springfox</groupId>     
<artifactId>springfox-swagger2</artifactId>     
<version>2.9.2</version>    
</dependency>    
<dependency>     
<groupId>io.springfox</groupId>     
<artifactId>springfox-swagger-ui</artifactId>     
<version>2.9.2</version>    
</dependency>           
</dependencies>
<build>
<finalName>bluecost-spreadsheet-web</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>           
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>AT*</exclude>
<exclude>IT*</exclude>
<exclude>BlueCostSpreadsheetUploadTestSuite</exclude>
</excludes>
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<excludes>
<exclude>TestApplicationProperties</exclude>
<exclude>UTSampleTests</exclude>
<exclude>FT*</exclude>
<exclude>UT*</exclude>
</excludes>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>${failsafeArgLine}</argLine>
<!--
Skips integration tests if the value of skip.integration.tests property
is true
-->
<skipTests>${skip.failsafe.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<!--
Unit Test Jacoco Reports
-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<skipTests>${skip.surefire.tests}</skipTests>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<skipTests>${skip.surefire.tests}</skipTests>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>           
</plugins>
</build>
</project>

现在,当我在现有的测试用例上运行"mvn测试"时,我会得到以下错误:

[INFO] Running com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests
Aug 06, 2018 5:19:12 PM org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper buildDefaultMergedContextConfiguration
INFO: Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests], using SpringBootContextLoader
Aug 06, 2018 5:19:12 PM org.springframework.test.context.support.AbstractContextLoader generateDefaultLocations
INFO: Could not detect default resource locations for test class [com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests]: no resource found for suffixes {-context.xml, Context.groovy}.
Aug 06, 2018 5:19:12 PM org.springframework.test.context.support.AnnotationConfigContextLoaderUtils detectDefaultConfigurationClasses
INFO: Could not detect default configuration classes for test class [com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests]: UTBlueCostRestControllerTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.083 s <<< FAILURE! - in com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests
[ERROR] initializationError(com.ibm.cio.cloud.cost.spreadsheet.controller.UTBlueCostRestControllerTests)  Time elapsed: 0.015 s  <<< ERROR!
java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V

我发现这个主题上的一些线程表明类路径有问题——很可能spring-core在类路径中出现了两次,但我找不到问题所在。我已经使用mvn依赖插件打印了依赖树,以帮助进行故障排除,但我没有发现任何明显的错误。请帮助:

[INFO] Verbose not supported since maven-dependency-plugin 3.0
[WARNING] The artifact org.codehaus.mojo:sonar-maven-plugin:pom:3.4.0.905 has been relocated to org.sonarsource.scanner.maven:sonar-maven-plugin:pom:3.4.0.905
[INFO] SpreadSheetUploadWeb:SpreadSheetUploadWeb:jar:1.0
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.0.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.4.RELEASE:compile
[INFO] |  |  - org.springframework:spring-context:jar:4.3.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.4.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  - ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  - org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  - org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.9.RELEASE:compile
[INFO] |  |  - commons-logging:commons-logging:jar:1.2:compile
[INFO] |  - org.yaml:snakeyaml:jar:1.19:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.4.RELEASE:compile
[INFO] |  +- com.zaxxer:HikariCP:jar:2.7.9:compile
[INFO] |  - org.springframework:spring-jdbc:jar:4.3.9.RELEASE:compile
[INFO] |     +- org.springframework:spring-beans:jar:4.3.9.RELEASE:compile
[INFO] |     - org.springframework:spring-tx:jar:4.3.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.4.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.4.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] |  |  |  - com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.6:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.6:compile
[INFO] |  |  - com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.6:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.4.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.6:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.6:compile
[INFO] |  |  - org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.6:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.11.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  - org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.9.RELEASE:compile
[INFO] |  |  - org.springframework:spring-aop:jar:4.3.9.RELEASE:compile
[INFO] |  - org.springframework:spring-webmvc:jar:4.3.9.RELEASE:compile
[INFO] |     - org.springframework:spring-expression:jar:4.3.9.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.4.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.4.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  - net.minidev:json-smart:jar:2.3:test
[INFO] |  |     - net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |        - org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.7.11:compile
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
[INFO] |  |  - org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  - com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  +- org.springframework:spring-test:jar:4.3.9.RELEASE:test
[INFO] |  - org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.apache.poi:poi-ooxml:jar:3.15:compile
[INFO] |  - com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] +- org.apache.poi:poi:jar:3.15:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.11:compile
[INFO] |  - org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] +- org.apache.poi:poi-ooxml-schemas:jar:3.15:compile
[INFO] |  - org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO] |     - stax:stax-api:jar:1.0.1:compile
[INFO] +- com.ibm.db2.jcc:db2jcc_license_cisuz:jar:10.5.9:compile
[INFO] +- com.ibm.db2.jcc:db2jcc4:jar:10.5.9:compile
[INFO] +- org.hsqldb:hsqldb:jar:2.4.0:test
[INFO] +- org.sonarsource.scanner.maven:sonar-maven-plugin:pom:3.4.0.905:compile
[INFO] |  +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.4:compile
[INFO] |  |  - org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] |  +- org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
[INFO] |  +- org.sonarsource.scanner.api:sonar-scanner-api:jar:2.10.0.1189:compile
[INFO] |  - commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.flywaydb:flyway-core:jar:5.0.7:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.9.2:compile
[INFO] |  +- io.swagger:swagger-annotations:jar:1.5.20:compile
[INFO] |  +- io.swagger:swagger-models:jar:1.5.20:compile
[INFO] |  |  - com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  +- io.springfox:springfox-spi:jar:2.9.2:compile
[INFO] |  |  - io.springfox:springfox-core:jar:2.9.2:compile
[INFO] |  +- io.springfox:springfox-schema:jar:2.9.2:compile
[INFO] |  +- io.springfox:springfox-swagger-common:jar:2.9.2:compile
[INFO] |  +- io.springfox:springfox-spring-web:jar:2.9.2:compile
[INFO] |  +- com.google.guava:guava:jar:20.0:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.4: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.2.0.Final:compile
[INFO] - io.springfox:springfox-swagger-ui:jar:2.9.2:compile

我应该补充一下,在版本更新后,我已经在我的机器上运行了以下命令:

mvn清洁mvn-eclipse:cleanmvn eclipse:eclipse

Eclipse中的项目更新。我也许可以尝试重新导入到另一个工作区,但目前我没有想法,需要帮助。

如https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes#third-派对图书馆升级和https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#dependency-版本,您需要将您的Spring版本升级到5.x.

在pom.xml中,更改

<spring.version>4.3.9.RELEASE</spring.version>

<spring.version>5.0.8.RELEASE</spring.version>

您可能需要为主要春季版本的迁移做更多的更改。

不要将父级添加为Spring Boot,而是使用Spring Boot BOM表进行依赖项管理。

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

这样,您就不必手动添加每个依赖项的版本号。

例如:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
</dependency>

您可以从这里查看依赖项和版本的详细信息。http://central.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.0.2.RELEASE/spring-boot-dependencies-2.0.2.RELEASE.pom

最新更新