Spring跨域攔截註解方式配置

Spring跨域攔截註解方式配置

1、spring版本至少在4.2以上,本人使用的是4.3

 

2、跨區沒配置之前請求訪問會報錯

請求方式:

當前域地址:http://192.168.1.78:9080/testGit/

 

(index):1 Failed toload http://192.168.1.78:8800/bronzecoll/share/shareNews?id=1: No'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://192.168.1.78:9080' is therefore not allowed access.

請求服務端地址:http://192.168.1.78:8800/bronzecoll/share/shareNews?id=1

服務端配置:

Controller頭部配置註解:@CrossOrigin(origins = "*", maxAge = 3600)//跨越請求配置

3、配置後請求訪問


數據獲取就正常了

怎麼樣,很簡單吧!第一次使用記錄下來。