SpringBoot因兼容性问题而失败

时间:2018-02-09 17:55:34

标签: spring maven spring-boot

这是我的pom.xml文件:

http://maven.apache.org/xsd/maven-4.0.0.xsd">     4.0.0

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <start-class>com.phoneBook.Main</start-class>
</properties>

<groupId>SpringProject</groupId>
<artifactId>SpringProject</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.phoneBook.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.5.10.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.10.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

</dependencies>

当我尝试加载一个简单的SpringBoot项目时,它失败并出现以下错误:

  

java.lang.NoSuchMethodError:   org.springframework.util.ObjectUtils.unwrapOptional(Ljava /郎/对象;)Ljava /郎/对象;     在   org.springframework.validation.DataBinder。(DataBinder.java:179)     在   org.springframework.boot.bind.RelaxedDataBinder。(RelaxedDataBinder.java:83)     在   org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:253)     在   org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)     在   org.springframework.boot.context.config.ConfigFileApplicationListener.bindToSpringApplication(ConfigFileApplicationListener.java:241)     在   org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:197)     在   org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:182)     在   org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:168)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)     在   org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)     在   org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)     在   org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:296)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)     在com.phoneBook.Main.main(Main.java:30)

我从阅读帖子中了解到这是与依赖项兼容的问题。我试图使用不同版本而没有成功。

它不是重复:Spring Boot Application Unable to start?

我添加了那里显示的依赖项,但仍然遇到了同样的错误。

你能帮帮我吗?

1 个答案:

答案 0 :(得分:3)

根据错误,我们可以看到spring-contextspring-core之间的版本不匹配:

178:  public DataBinder(@Nullable Object target, String objectName) {
179:     this.target = ObjectUtils.unwrapOptional(target);
180:     this.objectName = objectName;
181:  }

要检查每个版本的运行方式:

mvn dependency:tree | grep 'spring-context\|spring-core'

你可以更进一步检查实际的打包版本,它应该与maven所示的相同:

jar tf SpringProject-1.0-SNAPSHOT.jar | grep 'spring-context\|spring-core'

如果显示:

  

BOOT-INF / LIB /弹簧上下文4.3.14.RELEASE.jar
  BOOT-INF / LIB /弹簧芯4.3.14.RELEASE.jar

并且错误仍然存​​在,请发布完整的源示例和步骤以重现它。