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 ...
随机推荐
- Flask--SQLAlchemy--基本查询备忘
SQLAlchemy查询过滤器: 查询所有用户数据 User.query.all() 查询有多少个用户 User.query.count() 查询第1个用户 User.query.first() 查询 ...
- 经典笔试题型----IT经理(IT Manager)
一般企业设置IT部门都是服务性质,虽然谈IT需要成为战略部门许多年,但用脑子想下,这概率有多少?企业存在的第一目标是:赚取利润.贸易型企业最重要的部门为销售部,生产型企业最重要的部门为销售部与生产部, ...
- 这可能是目前最新的 Vue 相关开源项目库汇总(转)
访问地址:https://juejin.im/entry/58bf745fa22b9d0058895a58 原文链接:https://github.com/opendigg/awesome-githu ...
- ios7自定义返回按钮后,右滑返回功能失效解决方法
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //开启ios右滑返回 if ([ ...
- 【函数】isinstance内建函数(小窗help)
#学到了第八天,还有很多没有理解,不过,没关系,相信任何复杂的问题都是由简单的组成,只有将每一个细节理解到位,自然问题迎刃而解 今天遇到了isinstace函数,忘了,先看一下语法 查百度附上链接:h ...
- jQuery入门基础(动画效果)
一.隐藏显示 1.show()--显示隐藏的被选择元素 例:$(selector).show(speed,callback); 2.hide()--隐藏被选元素的内容 例:$(selector).hi ...
- Music Recommendation System with User-based and Item-based Collaborative Filtering Technique(使用基于用户及基于物品的协同过滤技术的音乐推荐系统)【更新】
摘要: 大数据催生了互联网,电子商务,也导致了信息过载.信息过载的问题可以由推荐系统来解决.推荐系统可以提供选择新产品(电影,音乐等)的建议.这篇论文介绍了一个音乐推荐系统,它会根据用户的历史行为和口 ...
- Android开发中常见的设计模式(四)——策略模式
策略模式定义了一些列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变换. 假设我们要出去旅游,而去旅游出行的方式有很多,有步行,有坐火车,有坐飞机等等 ...
- leetcode300
本题使用回溯法,深度优先搜索.使用隐式条件来进行加速. public class Solution { ; int[] x; Dictionary<int, int> dic = new ...
- leetcode1026
public class Solution { Stack<int> S = new Stack<int>(); ; public void Trace(TreeNode ro ...