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>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM