Spring Boot-右键maven build成功但是直接运行main方法出错的解决方案
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... 错误如下:
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

仔细观察了最后一句,应该还有一些问题。
ps:如果你也遇见类似的问题,不要放弃,坚持,一定能解决的。由此纪念我的这个下午,好了,我开测了~
Spring Boot-右键maven build成功但是直接运行main方法出错的解决方案的更多相关文章
- spring boot 使用maven和fat jar/war运行应用程序的对比
文章目录 简介 Spring Boot Maven Plugin 使用Maven命令来运行应用程序 作为fat jar/war包运行应用程序 详解War文件 详解jar文件 如何选择 使用maven和 ...
- Spring Boot项目Maven Build报错的解决方法
问题1, [ERROR]Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (defau ...
- Spring boot项目maven的profile多环境配置不自动替换变量的问题解决
Spring boot项目maven的profile多环境配置不自动替换变量的问题解决 在网上找了好久,配置都很简单,可是我的程序就是不能自动替换变量,最终单独测试,发现原来是引用spring b ...
- Spring Boot使用Maven打包替换资源文件占位符
在Spring Boot开发中,通过Maven构建项目依赖是一件比较舒心的事,可以为我们省去处理冲突等大部分问题,将更多的精力用于业务功能上.近期在项目中,由于项目集成了其他外部系统资源文件,需要根据 ...
- Spring Boot的Maven插件Spring Boot Maven plugin详解
Spring Boot的Maven插件(Spring Boot Maven plugin)能够以Maven的方式为应用提供Spring Boot的支持,即为Spring Boot应用提供了执行Mave ...
- [Java] Spring boot 的maven设置阿里云仓库
Spring boot 的maven设置阿里云仓库 打开根目录下的 pom.xml 文件,在对应为止出加入如下 红色 代码: <build> <plugins> <plu ...
- Spring Boot 项目 Maven 配置
在配置基于Maven的Spring Boot项目的过程中,打包运行出现了一系列错误. 比如: mvn 中没有主清单属性.java.lang.NoClassDefFoundError: org/spri ...
- spring boot和maven的约定大于配置体现在哪些方面
spring boot和maven的约定大于配置体现在哪些方面? 两者都遵从了约定大于配置的路线 约定优于配置体现点: 1.maven的目录文件结构 1)默认有resources文件夹,存放资源配置文 ...
- spring Boot + MyBatis + Maven 项目,日志开启打印 sql
在 spring Boot + MyBatis + Maven 项目中,日志开启打印 sql 的最简单方法,就是在文件 application.properties 中新增: logging.leve ...
随机推荐
- POJ1569 Myacm Triangles
Description There has been considerable archeological work on the ancient Myacm culture. Many artifa ...
- java 栈 最大深度
1. 概述 某公司面试,总监大叔过来,问了图论及栈的最大深度,然后^_^ 一直记着,今天搞一下 2. 代码 package com.goodfan.test; public class JavaS ...
- leetcode19
class Solution { public: ; ; ListNode* removeNthFromEnd(ListNode* head, int n) { ; ListNode* node = ...
- 析构方法(__del__)
析构方法,当对象在内存中被释放时(也就是实例执行完了,实例的内存就会自动释放,这时候就会触发),自动触发执行. 当程序结束时,python只会回收自己的内存空间,即用户态内存,而操作系统的资源则没有被 ...
- TCP与UDP,可靠UDP如何实现
两种协议都是传输层协议,为应用层提供信息载体. TCP协议是基于连接的字节流的可靠协议,有三次握手,四次挥手,超时重传,流量控制(滑动窗口),拥塞控制和差错控制,也正因为有可靠性的保证和控制手段,所以 ...
- Linux网络编程学习(四) -----守护进程的建立(第三章)
本文介绍一个例程daemon_init() #include <sys/types.h> #include <signal.h> #include <unistd.h&g ...
- transform(转)
转自:https://zhuanlan.zhihu.com/p/54356280
- FlannBasedMatcher 立体匹配
#include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #i ...
- 大数据入门到精通9-真正得wordcount
本章节实现一个真正得wordcount 得spark程序. 一.从本地获得一个数据集 val speechRdd= sc.parallelize(scala.io.Source.fromFile(&q ...
- 解决xcode10打包报错:That command depends on command in Target ‘xxx’:scrpit phase"[CP] Copy Pods Resources"
问题:使用xcode10打包报错,提示 error:Multiple commands produce ‘xxxx/xxx.app’ 1)Target ‘xx’ has create director ...