dimanche 5 juin 2022

Not able to get class with ClassLoader once SpringBoot app completely initialized

I run Spring Boot project in jar and I try to get class by class name from external library with ClassLoader:

Thread.currentThread().getContextClassLoader().loadClass(className)

When I call this from @PostConstruct method it returns correct result but when I call it after app initialization I am getting java.lang.ClassNotFoundException.

I also tried to get class like this but it didn't work correctly once app started:

Class.forName(className, true, Thread.currentThread().getContextClassLoader())

Can somebody please explain what the issue is?





Aucun commentaire:

Enregistrer un commentaire