MorphiaOrg / MorphiaOrg/morphia
ClassNotFoundException during package mapping in application server
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 449
- Avg merge
- 7m
- Merged PRs (30d)
- 10
Description
Duplicate of #4038 for milestone 3.0.0
Describe the bug
Deploying an ear application that uses Morphia 2.5.1 and MongoDB Driver 5.6.1 (as provided in the lib/ext of the domain) into an application server like Payara (5.2022.5).
When the application starts and should map the package de.asheep.classloaderexample then no entities are mapped because line 621 of Mapper.java classes.add(Class.forName(classInfo.getName())); does not find the corresponding classes and throws an ClassNotFoundException which is ignored.
To Reproduce
Steps to reproduce the behavior:
- Build the example with
mvn clean package - Provide the mongodb 5.6.1 jars in the lib/ext directory of the domain of the application sever
- Deploy the ear file into a domain of the application sever
- Start the application
Expected behavior
The entities of the package de.asheep.classloaderexample should be found and mapped.
- Server Version: Payara 5.2022.5
- Driver Version: 5.6.1
- Morphia Version: 2.5.1
Additional context
It seems that the used ClassLoader is not the correct one. Changing the line to classes.add(Class.forName(classInfo.getName(), true, Thread.currentThread().getContextClassLoader())); will result in finding the correct classes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading Mapper.java around line 621 and compare this duplicate with issue #4038, then build the attached example with mvn clean package. Reproduce the Payara deployment using the specified MongoDB driver jars and verify that entities in de.asheep.classloaderexample are found and mapped without the ClassNotFoundException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, mongodb
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100