Weblogic 12c 上的 Spring-boot War

Spring-boot War on Weblogic 12c

我在使用 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>

我也尝试过使用 prefer-web-inf classes。 StdSerializer class 位于 jackson-datatype-jsr310:2.9.8 jar 中,理论上这应该不是问题,因为 welogic 不包含 Jackson。任何帮助,将不胜感激。

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,将其包含在您的 pom.xml 中,第 92.1 节:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

发生此错误是因为 Spring Boot 正在尝试启动 Tomcat 容器,导致类路径冲突。按照提供的方式设置依赖关系将删除其中的大部分,并且在您的 weblogic.xml 中包含 com.fasterxml.jackson.* 将解决剩余的冲突。