Spring Boot右键maven build成功但是直接运行main方法出错的解决方案
作者:youreyebows 时间:2021-08-22 00:21:26
1、代码就一个Controller,从官网复制过来的,如下
package com.springboot.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
public class SampleController {
@RequestMapping("/index")
@ResponseBody
String home() {
return "Hello World";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(SampleController.class, args);
}
}
2、在项目上右键,maven build,输入 spring-boot:run,过几秒后控制台能看见success,也能看见Hello World,但是没有传说中的那个用字符拼拼出来的spring图案,而且http://localhost:8080/也打不开,于是我机智的在上面的SampleController类中右键->java Application,果真,出错了,还more than 18... 错误如下:
1 Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
等等之类的,就是找不到类的error
3、我的解决办法
之前我的pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
百度、搜狗、谷歌找了2个小时的方法,自己手动引入其他dependency等等都不行,但是更改了springboot的版本就好了,更改后如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.7.RELEASE</version>
</parent>
4、最后在SampleController类中右键->java Application,终于再console中输出了:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.7.RELEASE)
2017-11-03 16:17:14.954 INFO 6416 --- [ main] c.s.controller.SampleController : Starting SampleController on USER-20170626MT with PID 6416 (D:\j2ee_workspace\SpringTest\target\classes started by Administrator in D:\j2ee_workspace\SpringTest)
2017-11-03 16:17:14.956 INFO 6416 --- [ main] c.s.controller.SampleController : No active profile set, falling back to default profiles: default
2017-11-03 16:17:15.005 INFO 6416 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@411f53a0: startup date [Fri Nov 03 16:17:15 CST 2017]; root of context hierarchy
2017-11-03 16:17:16.688 INFO 6416 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-11-03 16:17:16.702 INFO 6416 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
打开http://localhost:8080/也能看见我的Hello World
仔细观察了最后一句,应该还有一些问题。
来源:https://www.cnblogs.com/youreyebows/p/7778973.html
标签:spring,boot,maven,build,成功,运行,main,出错
0
投稿
猜你喜欢
Android 虚拟按键与沉浸式的适配方法
2021-11-27 22:03:02
Java深入浅出讲解String类常见方法
2021-05-28 06:56:20
C#实现贪吃蛇小游戏
2022-09-28 17:17:59
android多线程断点下载-带进度条和百分比进度显示效果
2022-03-20 14:30:43
Log4j.properties配置及其使用
2023-05-14 21:06:18
android activity设置无标题实现全屏
2023-04-22 15:56:52
java 二分法算法的实例
2023-04-25 05:04:05
学习Android自定义Spinner适配器
2022-12-15 01:28:31
Java详细分析梳理垃圾回收机制
2023-10-30 04:02:33
C# TabControl控件中TabPage选项卡切换时的触发事件问题
2022-10-30 08:11:13
spring mvc中的@ModelAttribute注解示例介绍
2023-10-15 07:07:06
unity实现弧形移动 可角度自定
2022-12-16 22:38:19
java原生序列化和Kryo序列化性能实例对比分析
2023-11-26 16:04:20
c# 制作gif的四种方法
2023-03-17 20:01:08
Java数据结构之顺序表和链表精解
2021-07-01 14:30:39
Java之Algorithm_analysis案例详解
2022-03-07 01:34:50
WinForm通过操作注册表实现限制软件使用次数的方法
2023-07-27 15:39:57
Java控制台输入数组并逆序输出的方法实例 <font color=red>原创</font>
2023-07-13 23:32:26
Quartz与Spring集成的两种方法示例
2022-05-22 05:15:41
Android自定义scrollView实现顶部图片下拉放大
2021-05-26 09:55:36