在使用Spring-boot 2.1.2.RELEASE进行部署期间,我遇到了错误 WebLogic 12.2.1.2.0。
这是堆栈跟踪:
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:168)
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 org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:122)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:760)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:639)
at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:623)
at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59)
at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:76)
at org.springframework.web.filter.FormContentFilter.<init>(FormContentFilter.java:60)
at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.<init>(OrderedFormContentFilter.java:29)
at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.formContentFilter(WebMvcAutoConfiguration.java:166)
我尝试将其添加到weblogic.xml:
<wls:package-name>com.fasterxml.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.databind.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.datatype.jsr310.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.datatype.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.module.*</wls:package-name>
我也尝试过使用preferred-web-inf类。 StdSerializer类位于jackson-datatype-jsr310:2.9.8 jar中,从理论上讲这不是问题,因为welogic没有包含Jackson。任何帮助,将不胜感激。
答案 0 :(得分:1)
1)仅将这些软件包保留在weblogic.xml文件中,其他软件包则不必要:
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>org.springframeworks.*</wls:package-name>
<wls:package-name>com.fasterxml.jackson.*</wls:package-name>
</wls:prefer-application-packages>
2)按照Spring Docs,第92.1节,将此内容包含在pom.xml中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
发生此错误是因为Spring Boot试图启动Tomcat容器,从而导致类路径冲突。设置提供的依赖关系将删除大多数依赖关系,并在weblogic.xml中包含com.fasterxml.jackson。*将解决其余的冲突。