Spring Boot 2.0 新人会踩的坑--启动报404错误
转载自:http://www.javaman.cn/channels/sb2
启动程序,验证效果
根据图示,点击按钮,来启动 Spring Boot Web 程序, 查看控制台输出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.4.RELEASE)
2019-04-14 19:57:59.795 INFO 3680 --- [ main] com.example.demo.DemoApplication : Starting DemoApplication on 192.168.0.100 with PID 3680 (/Users/a123123/Work/IdeaProjects/demo/target/classes started by allen-jiang in /Users/a123123/Work/IdeaProjects/demo)
2019-04-14 19:57:59.798 INFO 3680 --- [ main] com.example.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-04-14 19:58:00.666 INFO 3680 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-04-14 19:58:00.689 INFO 3680 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-04-14 19:58:00.689 INFO 3680 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-04-14 19:58:00.756 INFO 3680 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-04-14 19:58:00.757 INFO 3680 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 920 ms
2019-04-14 19:58:00.978 INFO 3680 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-04-14 19:58:01.183 INFO 3680 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-04-14 19:58:01.186 INFO 3680 --- [ main] com.example.demo.DemoApplication : Started DemoApplication in 1.678 seconds (JVM running for 2.176)
当控制台日志中输出了 Tomcat started on port(s): 8888 (http) with context path ''时,表示内嵌的 Tomcat 容器已经启动成功了,端口为 8080 !
接下来,我们在浏览器上访问 http://localhost:8888/hello 接口,验证一下,接口是否能够正常访问:
返回了我们想要的 Hello, Spring Boot ! 字符串,接口访问正常,大工告成!
SpringbootApplication.png
注意!!!: @SpringBootApplication注解的类必须要放在包扫描的最外层才可以。
否则页面会报404错误。
四、总结
本文中,我们首先了解了什么是 Spring Boot, 以及Spring Boot 的相关特性,最后我们手把手学习了如何搭建一个 Spring Boot 项目,并编写了第一个接口且访问成功。
通过实际操作,真切地感受到了 Spring Boot 的魅力所在!老铁,双击 666!