控制器
@GetMapping("/api/data")
String response(){
}
應用程式屬性
server.servlet.context-path=/v1
春季安全
http.authorizeRequests().anyMatcher("/v1/**").authenicated()
這里沒有發生身份驗證。我相信,spring-security 忽略了在 application.properties 中配置的背景關系路徑。為什么 spring-security 忽略背景關系路徑。如何解決這個問題?

對于上圖,我預計會出現 401,因為 v1/** 應該被授權
這作業正常,
http.authorizeRequests().anyMatcher("/**").authenicated()
uj5u.com熱心網友回復:
打開 Spring Security 的除錯,然后你就會明白發生了什么。
@EnableWebSecurity(debug = true)
什么時候,
server.servlet.context-path=/v1
生成的請求:
Request received for GET '/api/data':
servletPath:/api/data
pathInfo:null
什么時候,
spring.mvc.servlet.path=/v1
生成的請求:
Request received for GET '/v1/api/data':
servletPath:/v1
pathInfo:/api/data
使用 servlet-path 來實作您要實作的內容...
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/395176.html
