Springboot快速入门教程(八) Spring Boot 路径访问问题

版权声明:原创版权为博主所有,博主项目网址www.github.com/994683607,转载请注明出处。 https://blog.csdn.net/qq_35180973/article/details/82318575

#(一)基本问题引入
##(1)当网页中访问错误路径,会出现错误页面,网页中显示错误信息。
从以下四个方面排除:
(1)404 – 确定地址是否输入正确,,此路径非彼路径。
(2)404 – 是否用对注解,此注解非彼注解
(3)404 – 包路径是否正确,此包非彼包
(4)404 – 确认类包是否正确,此类包非彼类包
##(2)RestController注解相当于@Controller+@ResponseBody
##(3)pom.xml是否架包冲突,导入重复的架包,或者两个架包版本冲突.
##(4)默认的访问路径为‘’/“,在application.properties中配置。
##(5)代码中注意层次结构,Application启动类和功能代码的相对位置,功能代码应该在子包层次,如图所示:
这里写图片描述
##(6)排除问题
1.确认访问地址是否正确:在控制台查看访问端口是否是8080
2.确认访问URI地址是否正确
3.注意注解@RestController和@Controller
4.注意导入的包是否正确如不同的date类在不同包中,导致参数功能不同
#最后确定包的路径是否正确
##最重要的一点:Springboot默认情况扫描的包是@SpringbootApplication所在类的同包或者子包下的类。
#(二)配置server
在application中配置,下面是默认配置。

########################################################
###server 配置信息
########################################################
server.port=8080
##默认访问地址为“/”
server.servlet.context-path=/firstboot

其他server配置

#server.port=8080
#server.address= # bind to a specific NIC
#server.session-timeout= # session timeout in seconds
#the context path, defaults to '/'
#server.context-path=/spring-boot
#server.servlet-path= # the servlet path, defaults to '/'
#server.tomcat.access-log-pattern= # log pattern of the access log
#server.tomcat.access-log-enabled=false # is access logging enabled
#server.tomcat.protocol-header=x-forwarded-proto # ssl forward headers
#server.tomcat.remote-ip-header=x-forwarded-for
#server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
#server.tomcat.background-processor-delay=30; # in seconds
#server.tomcat.max-threads = 0 # number of threads in protocol handler
#server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding
----------

专栏目录:

Springboot快速入门教程(一) 搭建Springboot
Springboot快速入门教程(二) 返回JSON
Springboot快速入门教程(三) 热部署
Springboot快速入门教程(四) Spring Boot JPA-Hibernate介绍
Springboot快速入门教程(五) Spring Boot JPA-Hibernate实现
Springboot快速入门教程(六) Spring Boot JdbcTemplate
Springboot快速入门教程(七)全局异常捕捉
Springboot快速入门教程(八) Spring Boot 路径访问问题

猜你喜欢

转载自blog.csdn.net/qq_35180973/article/details/82318575
今日推荐