我正在使用 Maven 和 Jetty 作为服务器开发 RestEasy Web 服务。其中一项服务应使用扩展 javax.servlet.http.HttpServletResponseWrapper 的过滤器。问题出在来自 servlet-api 2.3 的接口 javax.servlet.ServletResponse 的方法 setCharacterEncoding 中。我收到以下异常
java.lang.NoSuchMethodError: com.webapp.rest.jsonp.HttpServletResponseContentWrapper.setCharacterEncoding(Ljava/lang/String;)V
我已经指定了 servlet-api 2.4 依赖项,但也尝试使用 2.5:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
Servlet-api 2.4 是这样指定的:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
我正在使用 Maven 码头插件:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.15</version>
<configuration>
....
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
我的 RestEasy 配置:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jettison-provider</artifactId>
<version>2.2.2.GA</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
但是,在 Maven 存储库中,始终有 2.3 和 2.4(或 2.5)版本。我不知道这个 2.3 版本是否带有其他依赖项。有什么建议我怎么能找到这个以及如何强制使用 servlet-api 2.4。
我的依赖树看起来如下:
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.inextweb.ai:inextweb-ai:war:1.0.0-SNAPSHOT
[INFO] +- org.htmlparser:htmlparser:jar:2.1:compile
[INFO] +- org.htmlparser:htmllexer:jar:2.1:compile
[INFO] +- org.htmlparser:thumbelina:jar:2.1:compile
[INFO] +- org.htmlparser:sitecapturer:jar:2.1:compile
[INFO] +- org.htmlparser:filterbuilder:jar:2.1:compile
[INFO] +- net.sf.jung:jung-api:jar:2.0.1:compile
[INFO] | \- net.sourceforge.collections:collections-generic:jar:4.01:compile
[INFO] +- net.sf.jung:jung-algorithms:jar:2.0.1:compile
[INFO] | \- colt:colt:jar:1.2.0:compile
[INFO] | \- concurrent:concurrent:jar:1.3.4:compile
[INFO] +- net.sf.jung:jung-graph-impl:jar:2.0.1:compile
[INFO] +- net.sf.jung:jung-visualization:jar:2.0.1:compile
[INFO] +- org.apache.opennlp:opennlp-tools:jar:1.5.2-incubating:compile
[INFO] | +- org.apache.opennlp:opennlp-maxent:jar:3.0.2-incubating:compile
[INFO] | \- jwnl:jwnl:jar:1.3.3:compile
[INFO] +- net.sf.jwordnet:jwnl:jar:1.4_rc3:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.testng:testng:jar:6.1.1:test
[INFO] | +- org.beanshell:bsh:jar:2.0b4:test
[INFO] | +- com.beust:jcommander:jar:1.12:test
[INFO] | \- org.yaml:snakeyaml:jar:1.6:test
[INFO] +- commons-pool:commons-pool:jar:1.6:compile
[INFO] +- commons-codec:commons-codec:jar:1.7:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.10.1:compile
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:2.3.5.Final:compile
[INFO] | +- org.jboss.resteasy:jaxrs-api:jar:2.3.5.Final:compile
[INFO] | +- org.scannotation:scannotation:jar:1.0.3:compile
[INFO] | | \- javassist:javassist:jar:3.12.1.GA:compile
[INFO] | +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] | +- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.1.2:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.1.2:compile
[INFO] | \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-jackson-provider:jar:2.2.2.GA:compile
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.6.3:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.6.3:compile
[INFO] | +- org.codehaus.jackson:jackson-jaxrs:jar:1.6.3:compile
[INFO] | \- org.codehaus.jackson:jackson-xc:jar:1.6.3:compile
[INFO] +- org.jboss.resteasy:resteasy-jettison-provider:jar:2.2.2.GA:compile
[INFO] | +- org.jboss.resteasy:resteasy-jaxb-provider:jar:2.2.2.GA:compile
[INFO] | | \- com.sun.xml.stream:sjsxp:jar:1.0.1:compile
[INFO] | \- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] +- org.simpleframework:simple-xml:jar:2.3.6:compile
[INFO] | +- stax:stax-api:jar:1.0.1:compile
[INFO] | \- stax:stax:jar:1.2.0:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- com.google.code.gson:gson:jar:2.2.2:system
[INFO] +- junit:junit:jar:3.8.2:compile
[INFO] +- xalan:serializer:jar:2.7.1:compile
[INFO] +- bouncycastle:bcprov-jdk15:jar:140:compile
[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- xom:xom:jar:1.1:compile
[INFO] | +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] | +- xerces:xercesImpl:jar:2.6.2:compile
[INFO] | +- xalan:xalan:jar:2.7.0:compile
[INFO] | \- jaxen:jaxen:jar:1.1-beta-8:compile
[INFO] | \- jdom:jdom:jar:1.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.6.6:compile
[INFO] +- org.slf4j:jul-to-slf4j:jar:1.6.6:compile
[INFO] \- org.slf4j:jcl-over-slf4j:jar:1.6.6:runtime
[INFO] ------------------------------------------------------------------------
谢谢