Spring Boot右键maven build成功但是直接运行main方法出错的解决方案
2019-08-08 14:26
1896 查看
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
仔细观察了最后一句,应该还有一些问题。
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- eclipse 中的Android不能直接运行java main方法
- java.lang.OutOfMemoryError:Java heap space解决方法(项目中直接运行main方法,做案例,没有启动tomcat的情况)
- 关于Hibernate 在Junit测试中可以成功但是在Web下却无法运行的处理方法
- 在Android项目中创建一个包含main()方法的类,直接右键运行该类时会报如下错误:ShouldNotReachHere()
- 关于matlab代码DeepLearnToolbox-CNN卷积神经网络手写数字识别实例源码直接运行出错的解决方法
- eclipse打jar直接运行main方法
- myeclipse 下一个类有main方法直接运行提示找不到的解决方法
- 在命令行中直接运行带main方法的java
- VC++6.0的大bug(运行成功,调试出错,溢出)的解决方案
- 调用$.ajax成功但是success方法不响应的解决方案
- Error: ShouldNotReachHere() android工程类中main方法运行出错问题解决
- appium安装成功,appium-doctor运行成功,但是运行appium出错
- Visual Studio 继续并运行上次的成功生成,未提示直接运行上一个版本解决方案!
- IDE下多次运行main方法
- 一个java包中有两个含Main的类的运行方法
- 试图运行项目时出错:无法启动调试,绑定句柄无效 解决方案
- VS下运行和直接双击exe运行结果不同的解决方法
- 用 eclipse 创建javafx 可以运行但是报错的解决方法
- hadoop yarn运行jar包 出错 RunJar jarFile [mainClass] args...
- Visual Studio 2005 提示”试图运行项目时出错:无法启动调试。绑定句柄无效”的解决方案