具体错误为:
Http Status 500 - Handler dispatch failed;nested exception is
java.lang.noSuchMethodError:
org.springframework.web.serblet.mvc.method.annotation.ServletInvocableHandlerMethod.
getResponseStatus()/Lorg/Springframework/http/HttpStatus;
出现这个错误就是因为,
第一:没有正确的写入pom.xml文件,
第二:工具使用的差异(eclipse和idea有区别的)
测试过的eclipse的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>cn.jzh</groupId>
<artifactId>spring_boot_demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<properties>
<webVersion>3.1</webVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.8.RELEASE</version><!-- $NO-MVN-MAN-VER$ -->
</dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
这是eclipse的文件和idea不同的是:
spring-web这个jar包在eclipse里面必须用4.1.6.RELEASE或者4.3.8.RELEASE要不然会报不能引入@ResquestMapping和@ResponseBody这两个jar包但是idea没有收什么影响
spring-webmvc这个maven依赖,在eclipse里面不会报错,但是在idea里面就是一个累赘,会报上述的noSuchMehtodError的方法,但是在eclipse里面就没有报错,可以正常走下去
或者还有一个办法就是用最新的spring-boot版本,2.1.3.RELEASE的话,idea就不会在报错了