Different spring boot startup methods, thread context classloader loading problem

Recently, when the framework is encapsulated and the class is enhanced and loaded into the classloader, an
exception problem of interface XXX is not visible from class loader occurs.

When starting Main in eclipse, everything is normal, but when packaging or starting with spring-boot:run, an error occurs.
After a long period of exploration, it was found that
multiple classloaders were loaded because of the spring-boot-devtools dependency in the project.


The results obtained through Junittest​starting and Application starting the project are different. After investigation, the isAssignableFrom method is called in the program, and it is found that the same class A.isAssignableFrom(A) returns false. After debug comparison, it is found that although the class A looks the same, But loaded by different classloaders, one is AppClassLoader and the other is restartClassLoader, in this case, the bottom layer thinks that two different classes A are being compared.

     Problem solving: ​restartClassLoader is in the spring-boot-devtools package. It is only used for hot deployment during development. After deprecating this package, the program runs normally.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326225713&siteId=291194637