寄语:
学习的路途各种文章只是给你提供一个思路,适不适合自己还是要自己去总结,以下是我的项目遇到同样的问题但是尝试了多种方法,未果,特将这些方法总结如下,希望过往僧侣能尽快取得真经!
这是有问题,也是创建SpringBoot项目后原始的pom.xml文件依赖
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-test
test
这是启动报的错误:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.4.RELEASE)
2018-07-31 10:13:41.552 INFO 6588 --- [ main] t.w.s.s.SpringbootdemoApplication : Starting SpringbootdemoApplication on Action with PID 6588 (D:\WorkSpace_Idea\top.wj\springbootdemo\target\classes started by hp in D:\WorkSpace_Idea\top.wj)
2018-07-31 10:13:41.552 INFO 6588 --- [ main] t.w.s.s.SpringbootdemoApplication : No active profile set, falling back to default profiles: default
2018-07-31 10:13:41.568 INFO 6588 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Tue Jul 31 10:13:41 CST 2018]; root of context hierarchy
2018-07-31 10:13:41.896 INFO 6588 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-07-31 10:13:41.911 INFO 6588 --- [ main] t.w.s.s.SpringbootdemoApplication : Started SpringbootdemoApplication in 0.499 seconds (JVM running for 0.922)
2018-07-31 10:13:41.911 INFO 6588 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@11c20519: startup date [Tue Jul 31 10:13:41 CST 2018]; root of context hierarchy
2018-07-31 10:13:41.911 INFO 6588 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
Process finished with exit code 0
网上普罗大众的解决方案都是在pom.xml文件中添加
org.springframework.boot
spring-boot-starter-tomcat
//provided
//compire
注意:
这里要把
原因:该依赖默认scope 为provided,编译直接运行后,无法确定一个容器,项目无法启动。
在POM 4中,
* compile,缺省值,适用于所有阶段,会随着项目一起发布。
* provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
* runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
* test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
* system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。
但是这里就有一个问题,希望知道的同学留言交流。
//TODO
问题:SpringBoot是使用的内置tomcat,为什么还要引入来解决tomcat的问题?是SpringBoot的漏洞还是有其他原因?
解决方法 二:
因为我的项目创建以后
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
那么问题来了,这里的版本是2.0.3.RELEASE如果把版本号修改了,代码提示提示不出该版本号
把版本号降一级降到Idea可以提示的版本号,问题解决!
解决方法 三、
在pom.xml文件中引入
org.springframework.boot
spring-boot-starter-web
这个是因为创建SpringBoot项目时,我勾选的是SQL,所以缺少web的依赖
亲测有效,这三种方法可独立操作也可并用!问题是根据自己的问题来解决!个人随笔,只做记录,希望能帮到各位!