folsom
folsom copied to clipboard
Folsom - Spring Boot DevTools class loader
Hi,
When using the spring boot dev tools library the are some problems with class loaders, mainly:
The problem is that there are two class loaders for dedicated class. When load the class from memcache and map/cast to object of class there is an exception like: java.lang.ClassCastException: class xxx.api.cache.CachedResponse cannot be cast to class xxx.api.cache.CachedResponse (xxx.api.cache.CachedResponse is in unnamed module of loader 'app'; xxx.api.cache.CachedResponse is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @2f6f8549)
I have tried to exclude CachedResponse class from restart or some how from RestartClassLoader but i did not manage to me. I have used "restart.exclude.classes=file:/app/build/classes/java/main/" property but it exclude all classed in classpath. I have tried to exclude specific class "CachedResponse" but no results. Also I have tried to include the folsom jar to RestartClassLoader but did not work.
The question is: Is it possible to implement functionality in folsom to use RestartClassLoader? Or is there possibility to exclude that CachedResponse class from RestartClassLoader
Been looking at this, but not sure how it relates to Folsom. Folsom does not have any class named CachedResponse, so that class must come from other part of the code base.
Could you clarify what you mean by "load the class from memcache and map/cast to object of class"?
I'm not very familiar with RestartClassLoader, but Folsom does not do anything special with respect to class loading, so should work with most regular class loaders. Also, given this, I don't think it would make much sense for Folsom to treat any specific class loader differently.
Sorry, I did not present problem well.
A little explanation: First case: The spring boot dev tools lib is used to make hot-swap/hot reloading in java applications. That library has implemented the RestarClassLoader. That class loader is used for all classes in the classpath of project.
Second case: The class with the name CachedResponse is my custom class which represents the stored data in Memcache. So when I load data from Memcache I want to map them to the object of class CachedResponse.
The problem: Like on the image in the post. There is a situation when I load a class from Memcache using Folsom there is always used the basic class loader (AppClassLoader). But at the same time to this class was assigned the RestartClassLoader what makes a conflict.
Folsom does not consider that might be another class loader and that not allow making a hot-swap of that library.
I am absolutely sure that this is not a problem of Folsom because it works very well without devtools. But in such a situation the hot-swap is not possible.
Thanks for elaborating, that's helpful. Yeah, I think this is not a problem with Folsom as such. You could investigate implementing a custom transcoder for Folsom that is aware of your classloaders, or try to make sure that Folsom is loaded in the same classloader as your class.