Spring 问题定位

概述

对于spring框架,我们通常不需要关心内部原理,但是可能会用一些稀奇古怪的问题时,就需要定义是不是Spring框架本身的问题。

定位手段

打开日志

通常我们的spring日志都是info或者error级别的,一些细节的问题我们无法判断是哪里出现了问题。
这个时候就需要把日志级别改的更低,比如debug。

        <AsyncRoot level="debug" includeLocation="true" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="service_appender"/>
        </AsyncRoot>

问题案例

Request method ‘POST’ not supported问题。
这个问题在经过常规方法已经找不到问题时,可以调整日志级别,发现保存信息如下。

 {org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:310}-Looking up handler method for path /test/student
 {org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:320}-Did not find handler method for [/test/student]
 {org.springframework.web.servlet.handler.SimpleUrlHandlerMapping:192}-Matching patterns for request [/test/student] are [/**]
 {org.springframework.web.servlet.handler.SimpleUrlHandlerMapping:226}-URI Template variables for request [/test/student] are {}
 {org.springframework.web.servlet.handler.SimpleUrlHandlerMapping:140}-Mapping [/file1/upload] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@4c4c7d6c]]] and 1 interceptor
 {org.springframework.web.servlet.DispatcherServlet:1044}-Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
  • 通过日志发现Did not find handler method for [/test/student],可以知道没有找到这个方法。
    但是检查过代码,这个方法肯定是有的。
  • 排查application.properties文件,发现配置如下:
server.servlet.context-path=/test
  • 检查springboot版本是1.5.2,没有该配置,这个配置是高版本才有的。
    在这里插入图片描述
    在这里插入图片描述
  • 配置项替换成server.context-path,文件解决。
server.context-path=/test

总结

这个案例是因为springboot版本太低造成的,配置项在低版本不适用。
我们可以通过打开spring的日志,查看更多细节,从而找到问题到底是哪里出现的,细心一点就可以解决问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

融极

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值