java 严重:异常启动过滤器 CORS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16394669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SEVERE: Exception starting filter CORS
提问by pointer
I have RESTful web service deployed on tomcat' the web service is working fine in the client/server on same domain scenario' but I am required to make the Web Service available from cross domain' for this purpose I have used CORS filter.
我在 tomcat 上部署了 RESTful Web 服务'该 Web 服务在同一域场景的客户端/服务器中工作正常'但我需要使 Web 服务从跨域可用'为此目的,我使用了 CORS 过滤器。
I have included filter's jars in both myProjects/lib and tomcat/lib' and also have included following in my web.xml file of web service project'
我在 myProjects/lib 和 tomcat/lib' 中都包含了过滤器的 jar,并且还在我的 web 服务项目的 web.xml 文件中包含了以下内容
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
</filter>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
But when I try to start the web service I get following error regarding CORS filter:
但是,当我尝试启动 Web 服务时,出现以下有关 CORS 过滤器的错误:
SEVERE: Exception starting filter CORS
java.lang.NoClassDefFoundError: com/thetransactioncompany/util/PropertyParseException
at com.thetransactioncompany.cors.CORSFilter.init(CORSFilter.java:100)
kindly guide me to figure out what is wrong with this situation'
请指导我弄清楚这种情况有什么问题'
回答by EvenStevens
You need to add java-properties-utils-1.7.1.jar file to the classpath too as the cors filter has a dependancy on it.
您还需要将 java-properties-utils-1.7.1.jar 文件添加到类路径中,因为 cors 过滤器依赖于它。
回答by FAZIL MAHAMMOOD ABDULLAH
In my case, adding these 2 jar files in the tomcat lib folder solved the issue:
就我而言,在 tomcat lib 文件夹中添加这 2 个 jar 文件解决了该问题:
- cors-filter-2.5.jar
- java-property-utils-1.10.jar
- cors-filter-2.5.jar
- java-property-utils-1.10.jar
回答by jmjm
I had same prob but in ma case, first, my server status was unbound, so I changed it through 'Build path' But still didn't work.. my friend checked and he found Eclipse's 'Build Automatically' function. then it worked well !
我有同样的问题,但在 ma 的情况下,首先,我的服务器状态未绑定,所以我通过“构建路径”对其进行了更改,但仍然无效..我的朋友检查并发现了 Eclipse 的“自动构建”功能。那么它运作良好!
回答by a1an
It might have been a version issue. I had the same problem and it turns out this filter requires at minimum Tomcat version 7.0.41 to work, according to: http://enable-cors.org/server_tomcat.html
可能是版本问题。我遇到了同样的问题,结果证明这个过滤器至少需要 Tomcat 7.0.41 版本才能工作,根据:http://enable-cors.org/server_tomcat.html
As reference, Debian 7.8 ships Tomcat 7.0.28, which does not support native CORS.
作为参考,Debian 7.8 附带不支持原生 CORS 的 Tomcat 7.0.28。
回答by user1419243
I had the same problem. In my case, the problem was that the maven dependencies had been deleted from the Deployment Assembly
section in project properties
. Hope it helps someone.
我有同样的问题。就我而言,问题是 maven 依赖项已从Deployment Assembly
project 中的部分删除properties
。希望它可以帮助某人。