前言
在请求tomcat上的字体文件的时候,遇到了以下错误
Access to Font at “xxx” from origin “xxx” has been by CORS plicy:
No ‘Access-Control-Allow-Origin’header is present on the requested resource.
Origin “xxx” is therefore not allowed access.
解决方法
在api服务器的tomcat的web.xml中添加CorsFilter过滤器
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
下载cors-filter-<version>.jar
和java-property-utils-<version>.jar
两个jar文件下,放在tomcat的lib中。
下载地址:
cors-filter-2.4.jar
http://search.maven.org/remotecontent?filepath=com/thetransactioncompany/cors-filter/2.4/cors-filter-2.4.jar
java-property-utils-1.9.1.jar
http://search.maven.org/remotecontent?filepath=com/thetransactioncompany/java-property-utils/1.9.1/java-property-utils-1.9.1.jar
重启tomcat。