Skip to content

Loading data fails with "Specified class is an interface" when invoking repository from worker thread #3908

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

Closed
cstettler opened this issue Dec 8, 2021 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@cstettler
Copy link

Loading data having a property using a type discriminator from a worker thread (i.e. from a rest controller in a parallel stream) sometimes results in the following error:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.foo.Bar]: Specified class is an interface

The following aspects seem to be relevant in order to run into this issue:

  • the entity must contain a field of an interface type that contains several concrete implementations as values
  • the entity has to be loaded from a separate thread other than the http handler thread (e.g. from a worker thread of the common pool)
  • the application has to be run from the Spring Boot jar (e.g. from command line or a Docker image), not from the IDE

Please see https://github.com/cstettler/spring-data-mongo-loading-issue for a minimal sample application based on Spring Boot 2.6.1 and Spring Data Mongo 3.3.0 to reproduce the issue and further explanation / results of the investigation done so far.

Note: I am aware that this issue might not be caused by Spring Data MongoDB directly, but by Spring Data or even by Spring Boot. Please advice in case the issue should be opened in a different Spring project repository. Thank you!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 8, 2021
@mp911de
Copy link
Member

mp911de commented Dec 8, 2021

This is a duplicate of #3905. Please make sure to either use type aliases or set the class loader accordingly. ForkJoin thread pools use the system class loader and not Spring's class loader.

@mp911de mp911de closed this as completed Dec 8, 2021
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants