First of all, let me explain that my jdk is 1.8tomcat is 8.0, and my project is ssm+maven.
The framework of spring is 4.3. When using it, you only need to annotate @CrossOrigin before the controller's @controller annotation, and then add it in the springmvc.xml configuration file.
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">//Configurations that are not related to this operation are omitted <mvc:cors> <mvc:mapping path="/**" allowed-origins="" allowed-methods="POST,GET,OPTIONS,DELETE,PUT"//The userName and password in the header are the contents of my custom request header due to the project's needs. allowed-headers="Origin,X-Mx-ReqToken,x-requested-with,userName,passWord,Authorization,Accept,content-type" allow-credentials="true"/> </mvc:cors></beans>
Here is a screenshot of the controller layer adding annotations
The above method of implementing cross-domain CORS in spring 4.3 is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.