gpt4 book ai didi

java - jackson 即使使用相同的版本也会抛出 IllegalAccessError

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:16 31 4
gpt4 key购买 nike

我正在用 jackson 开发软件,但完全卡住了......当我用 java -jar <MY_APPLICATION>.jar 运行 spring-boot 程序时命令,我收到以下错误:

...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'jacksonObjectMapper' threw exception; nested exception is
java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 84 more
Caused by: java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.<init>(JavaTimeModule.java:159)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.springframework.beans.BeanUtils.instantiate(BeanUtils.java:78)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:719)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:572)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:554)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration.jacksonObjectMapper(JacksonAutoConfiguration.java:87)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb.CGLIB$jacksonObjectMapper$0(<generated>)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb$$FastClassBySpringCGLIB$$d685921f.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration$$EnhancerBySpringCGLIB$$2434a0bb.jacksonObjectMapper(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 85 more

错误上面还有更多的错误信息,不过我觉得重要的信息是java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;) ,我知道这通常不会发生。

我确认jackson模块是同一个版本(2.6.5来自spring-boot的依赖),不包括codehaus的jackson:

$ mvn dependency:tree -Dverbose -Dincluces=com.fasterxml.jackson.core | grep -v omitted

...

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ patriot-fdc-web ---
[INFO] <MY_GROUP>:<MY_APPLICATION_A>:war:0.3.9-SNAPSHOT
[INFO] +- <MY_GROUP>:<MY_APPLICATION_B>:jar:0.3.9-SNAPSHOT:compile
[INFO] | \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.6.5:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.6.5:compile
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:1.3.3.RELEASE:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.5:compile (version managed from 2.4.2)
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.5:compile (version managed from 2.6.0)

有人会遇到这样的问题吗?任何人都可以为错误提出任何解决方案或可能性吗?提前谢谢你。

最佳答案

我找到了原因。

依赖项包括 calcite-avartica Artifact ,它在 2.1.1 版本中有一个带阴影的 jackson。这就是为什么我无法通过 mvn dependency:tree 找到依赖项。我通过查看 StdSerializer 的来源,通过远程调试找到了它。 https://issues.apache.org/jira/browse/CALCITE-1110

Avartica 1.9.0 或更高版本可能不会打扰我们。我只是排除了 calcite-corecalcite-avartica,最后它运行良好。

关于java - jackson 即使使用相同的版本也会抛出 IllegalAccessError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42525803/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com