Spring MVC使用Cors实现跨域

 

在开发APP过程中,APP调用后端接口有跨域的问题,只要在spring-mvc.xml 文件中加入下面的配置即可:

 

	<!-- 解决API接口跨域问题配置 Spring MVC 版本必须是 4.2 及以上 -->
	<mvc:cors>
		<mvc:mapping path="/**" 
		allowed-origins="*" 
		allowed-methods="POST, GET, OPTIONS, DELETE, PUT" 
		allowed-headers="Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With" 
		allow-credentials="true" 
		max-age="3600" />
	</mvc:cors>

  

posted @ 2018-06-24 10:44  mingyue1818  阅读(3997)  评论(0编辑  收藏  举报