Digest:今天Spring Boot 应用启动成功,访问接口出现如下错误,不知到导致问题关键所在,记录一下这个问题。

浏览器报500错误

项目代码如下

Controller.java

package com.lints.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; /**
* @Author Lints
* @Date 2019/10/31 9:06
* @Description This is description of class
* @Since version-1.0
*/
@RestController
public class HelloController {
/**
* @Author Lints
* @Date 2019/10/31 9:06
* @Description 这用于处理浏览器hello请求
* @Param null
* @Return java.lang.String
* @Since version-1.0
*/
@ResponseBody
@RequestMapping("/hello")
public String helloWorld(){
return "Hello World!";
}
}

HelloWorldApp.java

package com.lints;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; /**
* @Author Lints
* @Date 20:47
* @Description This is a Spring Boot application
* @Since version-1.0
*/ @SpringBootApplication
public class HelloWorldApp {
/**
* @Author Lints
* @Date 2019/10/30 21:25
* @Description This is description of method
* @Param [args]
* @Return void
* @Since version-1.0
*/
public static void main(String[] args) {
//启动Spring应用
SpringApplication.run(HelloWorldApp.class,args);
}
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<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> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/>
</parent> <groupId>com.lints</groupId>
<artifactId>spring-boot-helloworld</artifactId>
<version>1.0-SNAPSHOT</version> <name>spring-boot-helloworld</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.8.RELEASE</version>
</dependency>
</dependencies> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

解决办法

将pom.xml中 Spring版本换成 2.1.6 问题解决

<?xml version="1.0" encoding="UTF-8"?>

<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> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <!--- 把Spring版本换成 2.1.6 问题解决 <version>2.2.0.RELEASE</version> ---> <version>2.1.6.RELEASE</version>
<relativePath/>
</parent>

最新文章

  1. 手机端访问web调用数字键盘。
  2. 网络流EK
  3. python 培训之Django
  4. github神器--Atom编辑器初体验
  5. 记录下 QT Linux 静态编译遇到的坑
  6. dedecms二级菜单实现
  7. HDU 4433 locker
  8. 基于CAShapeLayer以及UIBezierPath的语音输入效果动画封装
  9. jquery登录验证插件
  10. rails总结
  11. java之Set源代码浅析
  12. ssh无密码登录设置方法以及出现问题 ECDSA host key 和IP地址对应的key不同的解决
  13. UNIX 系统概述
  14. 【编程技巧】addSubview和insertSubview的区别
  15. 在CentOS 6.x上配合Windows客户端搭建 git(gitosis)服务器
  16. centos7安装mysql8
  17. Nginx配置跨域支持功能
  18. DAY14(PYTHONS)生成器进阶
  19. CentOS7 Windows双系统 修复引导
  20. java socket编程中backlog的含义(zz)

热门文章

  1. nginx的ngx_http_geoip2模块以精准禁止特定地区IP访问
  2. 基于vue-cli、elementUI的Vue超简单入门小例子
  3. Webstorm轻松部署项目至服务器
  4. css 实现图片灰度
  5. Java面向对象程序设计第6章1-12
  6. 死磕 java线程系列之自己动手写一个线程池(续)
  7. ORM查询简化
  8. 05-04 scikit-learn库之主成分分析
  9. 运维自动化神器ansible之group模块
  10. GUI篇 tkinter (Label,Button)之一