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>

  

猜你喜欢

转载自www.cnblogs.com/mingyue1818/p/9219821.html