spring boot. 1 学习,配置404 错误.

第一天学习spring .

1.按照官方文档搭项目.

https://spring.io/guides/gs/rest-service/#initial   

Building a RESTful Web Service

2.搭建项目. maven  idea   jdk 1.9

选中的maven -web -app/  但是看这选择  manve-quickstart 应该也是可以的.

spring boot. 1 学习,配置404 错误.

创建完成之后 runas 出现两个问题.

 1无法启动,

.Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

 一般都是说tomcat引用冲突的问题.不过我没有用啊.所以就看源码:

spring boot. 1 学习,配置404 错误.

   发现beanNames 为0 ,查看了原来的的代码 启动类.因为是复制的

 spring boot. 1 学习,配置404 错误.

   复制代码用的Application 结果一来的包有这个类就给引入进去了,半天起不起来.用创建的启动类的类对象 xxx.class

2.启动之后是 404 

首先这个项目不需要在路径上写项目名.

spring boot. 1 学习,配置404 错误.

http://localhost:8080/greeting
访问不到.查看加载的mapped 日志 发现{"greeting"}没有加载.

后面查询发现, spring boot 的启动类扫描的是当前包以及子包. 如果要加包的扫描路径才可以.

spring boot. 1 学习,配置404 错误.

解决了 .可以访问.

spring boot. 1 学习,配置404 错误.


? 内嵌的tomcat 如果工作,.