英文:
Jersey 2.32 IllegalArgumentException jersey.repackaged.org.objectweb.asm.ClassVisitor
问题
以下是翻译好的内容:
我正在尝试使用Jersey的JSON/bean验证,但在初始化servlet时发生错误。
完整的堆栈跟踪:
SEVERE: 为servlet [rest-servlet] 初始化Servlet.init() 抛出异常
java.lang.IllegalArgumentException
在 jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
在 jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:64)
在 org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener$AnnotatedClassVisitor.<init>(AnnotationAcceptingListener.java:172)
在 org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener$AnnotatedClassVisitor.<init>(AnnotationAcceptingListener.java:156)
在 org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.<init>(AnnotationAcceptingListener.java:124)
在 org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(AnnotationAcceptingListener.java:96)
在 org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:902)
在 org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:863)
在 org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:772)
在 org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1213)
在 org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1186)
在 org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1182)
在 org.glassfish.jersey.server.ApplicationHandler$RuntimeConfigConfigurator.init(ApplicationHandler.java:182)
在 org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:290)
在 java.util.Arrays$ArrayList.forEach(Arrays.java:3880)
在 org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:290)
在 org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:259)
在 org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
在 org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
在 org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:347)
在 javax.servlet.GenericServlet.init(GenericServlet.java:158)
在 org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134)
在 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089)
在 org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761)
在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
在 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
在 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
在 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
在 org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
在 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
在 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
在 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
在 java.lang.Thread.run(Thread.java:748)
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.itreegroup</groupId>
<artifactId>admin3-iasm</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Admin3-IASM</name>
<properties>
<jackson.version>2.11.3</jackson.version>
<jersey.version>2.32</jersey.version>
</properties>
<prerequisites>
<maven>3.6.3</maven>
</prerequisites>
<repositories>
<repository>
<id>maven-ojdbc6</id>
<name>Maven ojdbc6 Repository</name>
<url>http://www.datanucleus.org/downloads/maven2</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<details>
<summary>英文:</summary>
I am trying to user Jersey's JSON/bean validation however error occurs when initing servlet occurs.
Full stack trace:
SEVERE: Servlet.init() for servlet [rest-servlet] threw exception
java.lang.IllegalArgumentException
at jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:79)
at jersey.repackaged.org.objectweb.asm.ClassVisitor.<init>(ClassVisitor.java:64)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener$AnnotatedClassVisitor.<init>(AnnotationAcceptingListener.java:172)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener$AnnotatedClassVisitor.<init>(AnnotationAcceptingListener.java:156)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.<init>(AnnotationAcceptingListener.java:124)
at org.glassfish.jersey.server.internal.scanning.AnnotationAcceptingListener.newJaxrsResourceAndProviderListener(AnnotationAcceptingListener.java:96)
at org.glassfish.jersey.server.ResourceConfig.scanClasses(ResourceConfig.java:902)
at org.glassfish.jersey.server.ResourceConfig._getClasses(ResourceConfig.java:863)
at org.glassfish.jersey.server.ResourceConfig.getClasses(ResourceConfig.java:772)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1213)
at org.glassfish.jersey.server.ResourceConfig$RuntimeConfig.<init>(ResourceConfig.java:1186)
at org.glassfish.jersey.server.ResourceConfig.createRuntimeConfig(ResourceConfig.java:1182)
at org.glassfish.jersey.server.ApplicationHandler$RuntimeConfigConfigurator.init(ApplicationHandler.java:182)
at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$0(ApplicationHandler.java:290)
at java.util.Arrays$ArrayList.forEach(Arrays.java:3880)
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:290)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:259)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:347)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1134)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1089)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.itreegroup</groupId>
<artifactId>admin3-iasm</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Admin3-IASM</name>
<properties>
<jackson.version>2.11.3</jackson.version>
<jersey.version>2.32</jersey.version>
</properties>
<prerequisites>
<maven>3.6.3</maven>
</prerequisites>
<repositories>
<repository>
<id>maven-ojdbc6</id>
<name>Maven ojdbc6 Repository</name>
<url>http://www.datanucleus.org/downloads/maven2</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>8.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>${jackson.version}</version>
</dependency>
<!--
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>2.0.0-RC1</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0-M1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
-->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<javaEncoding>UTF-8</javaEncoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Line which supposedly throws exception:
...
public ClassVisitor(final int api, final ClassVisitor classVisitor) {
if (api != Opcodes.ASM8
&& api != Opcodes.ASM7
&& api != Opcodes.ASM6
&& api != Opcodes.ASM5
&& api != Opcodes.ASM4
&& api != Opcodes.ASM9_EXPERIMENTAL) {
throw new IllegalArgumentException("Unsupported api " + api);
}
if (api == Opcodes.ASM9_EXPERIMENTAL) {
Constants.checkAsmExperimental(this); // Line which supposedly throws exception
}
this.api = api;
this.cv = classVisitor;
}
...
**UPDATE:**
Using Java 8
some more text so that I could post this question some more text so that I could post this question some more text so that I could post this question some more text so that I could post this question some more text so that I could post this question some more text so that I could post this question
</details>
# 答案1
**得分**: 1
错误在我降级到Jersey 2.27之后不再出现。然而...
...在这个错误消失之后,我遇到了另一个错误:[java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;][1]。我已经检查了我的pom.xml依赖项,它们是正确的。问题是,我之前以非Maven方式设置了一个Eclipse项目,并且只是将`Jersey 1.x`库(最初使用的版本)放在了`/src/main/webapp/WEB-INF/lib`文件夹中,然后在将项目更改为Maven项目并升级`Jersey`到版本`2.32`后,我没有将它们删除(忘记了)。因此,较旧版本的jar文件被复制到了`../ECLIPSE-WORKSPACE/.../org.eclipse.wst.server.core/tmp1/wtpwebapps/MY-APP/WEB-INF/lib`目录中,与`Jersey 2.x`的jar文件一起。真是愚蠢。
记住这一点,并回忆起我之前注意到的:
> 我觉得奇怪的是IllegalArgumentException在这一行被抛出:
> Constants.checkAsmExperimental(this);
我认为最初的问题并不是我当时使用的Jersey版本(2.32),而是Jersey 1.x和Jersey 2.x的jar文件最终出现在了类路径中。目前,我已将Jersey版本升级到2.32,一切都正常工作。所以,可能Jersey 2.3根本没有bug。
[1]: https://stackoverflow.com/questions/30176811/abstractmethoderror-using-uribuilder-on-jax-rs
<details>
<summary>英文:</summary>
The error did not appear anymore after I downgraded to Jersey 2.27. However...
... after this error disappeared, I got another one: [java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;][1]. I had checked my pom.xml dependencies and they were correct. The problem was that I had previously had setup an Eclipse project in non-Maven manner and had simply put `Jersey 1.x` libraries (which I was initially using) in `/src/main/webapp/WEB-INF/lib` folder and I did not remove them (forgot) after I changed the project to Maven one and upgraded `Jersey` to version `2.32`. Therefore older version jars were being copied to `../ECLIPSE-WORKSPACE/.../org.eclipse.wst.server.core/tmp1/wtpwebapps/MY-APP/WEB-INF/lib` directory with `Jersey 2.x` jars. Silly me.
Having that in mind and remembering that I noticed earlier
> I find it strange that IllegalArgumentException is thrown in line
> Constants.checkAsmExperimental(this);
I think the original issue was not with Jersey version I had used at the time (which was 2.32), but with Jersey 1.x and Jersey 2.x jar files ending up in the classpath. Currently, I have upgraded Jersey version to 2.32 and everything works. So, probably there is no bug in Jersey 2.3 at all.
[1]: https://stackoverflow.com/questions/30176811/abstractmethoderror-using-uribuilder-on-jax-rs
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论