A new Jackson package name was created in the third-party jar package, which caused spring boot to report a json serialization error in tomcat

Insert picture description here
Help a friend to solve a problem. When the serialized object of spring boot returns, an error is reported and the cause is found. A third-party paid jar package is introduced into the project. A jackson package is built in this package. The first reaction is that the code is incomplete Or the version does not match the version of the current boot project, resulting in an error that the serialization cannot find the method.
Insert picture description here
According to the reflection in the development environment, the main method of springboot mode is ok, but it will not work after it is thrown into a war package and dropped into tomcat. The author ’s reaction is that springboot has its own set of jars and class loading methods. As for tomcat, it is On the other hand, it turns out that this is indeed the case after checking the information. Readers are interested in using Baidu or Google to load the different loading modes in two ways. The boot loading isolation is doing very well. The solution is described below.

  1. It is to directly delete all the jackson code in the jar, and then throw the jar back into the project, so that there will be no loading conflicts. The focus is on 2

Insert picture description here

2. Change the name of the gateway-client jar package to zzzz-gateway-client, because the loading method of the jar package in tomcat is loaded by the order of the file name, such as A, B, C… Z, and
A is loaded first in order. Package, then load B package, and so on, and finally load Z package, then each time a package name is loaded, and he will encounter the same package name later, he will not load it again,
so this third party Put the jar at the end, tomcat will not load the package that conflicts with the previous jar package, which solves the problem.

Note that the package that will not be loaded refers to the alibaba and jcraft packages in the jar folder. If it is only the conflict of alibaba, it will not affect it to continue to load the jcraft package and the class. The jar is equivalent to a compressed file. In fact, the jar is decompressed, and then load the class.

Published 38 original articles · won praise 17 · views 9006

Guess you like

Origin blog.csdn.net/cainiao1412/article/details/102492896