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