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、配置后请求访问
数据获取就正常了
怎么样,很简单吧!第一次使用记录下来。