spring boot 请求地址带有.json 兼容处理


项目以前时spring mvc的,现在升级为spring boot ,有些请求地址带有.json后缀,在请求spring boot项目时,无法匹配控制器,spring boot默认选择禁用后缀模式匹配

查询官网:https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/


官网的解决方案:
  1.直接删掉“.json”
  2.可以将/***.json替换为/***?format=json
  3.在application.perproties中增加如下配置,就可以继续使用“/****.json”来匹配控制器了
    spring.mvc.contentnegotiation.favor-path-extension=true
    spring.mvc.pathmatch.use-suffix-pattern=true
  4.第四种解决方案
    spring.mvc.contentnegotiation.favor-path-extension=true
    spring.mvc.pathmatch.use-registered-suffix-pattern=true


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM