Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folsom - Spring Boot DevTools class loader #188

Open
CallMeSweets opened this issue Nov 16, 2021 · 3 comments
Open

Folsom - Spring Boot DevTools class loader #188

CallMeSweets opened this issue Nov 16, 2021 · 3 comments

Comments

@CallMeSweets
Copy link

Hi,
When using the spring boot dev tools library the are some problems with class loaders, mainly:
Screenshot from 2021-11-16 12-57-48 (1)

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

@protocol7
Copy link
Contributor

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.

@CallMeSweets
Copy link
Author

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.

@protocol7
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants