在pom.xml文件中添加
<groupId>com.thetransactioncompany</groupId>
<artifactId>java-property-utils</artifactId>
<version>1.9.1</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
com.thetransactioncompany
cors-filter
1.3.2
之后在web.xml中添加
跨域过滤器
CORS
com.thetransactioncompany.cors.CORSFilter
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, HEAD, PUT, DELETE</param-value>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
<param-name>cors.exposedHeaders</param-name>
<param-value>Set-Cookie</param-value>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
即可解决前端访问后端的跨域问题