开始接触spring boot遇到的小坑
-
问题一:在eclipse中的控制台提示端口被占用
Action: Identify and stop the process that's listening on port 8080 or configure this application to listen on another port.
可能原因一:
多次重复运行BookworkApplication即
再次运行BookworkApplication时没有停止之前正在运行的BookworkApplication解决方法:
(作者使用的是eclipse,当中的tomcat此时显示处于停止状态)
重新启动eclipse
再次运行BookworkApplication可能原因二:
此时端口确实被其他进程占用,可以在application.properties中添加
server.port=相应端口号
指定端口号。
-
问题二:
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. There was an unexpected error (type=Not Found, status=404). No message available
可能原因一:
BookworkApplication类所在路劲没有与相应子包同级
即
BookworkApplication所在的包是其他包的父级正确路径设定(举例):
注意两个包名解决方法:修改包名
可能原因二:
此时application.properties中没有指定server.servlet.context-path=/路径
的情况下,context-path的路劲默认为空
而不是如同eclipse新建maven文件时工程名称即为context-path即
在网址栏中的映射地址直接就是controller中设定的映射名举例:
在application.properties中没有指定server.servlet.context-path=/路径
的情况下
若controller中指定的映射名为/run
端口假设为8080
那么网页地址栏中填写的应该就是localhost:8080/run
解决办法:
在application.properties中指定server.servlet.context-path=/路径