Skip to content

ClassNotFoundException during package mapping in application server #4066

@github-actions

Description

@github-actions

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:

  1. Build the example with mvn clean package
  2. Provide the mongodb 5.6.1 jars in the lib/ext directory of the domain of the application sever
  3. Deploy the ear file into a domain of the application sever
  4. 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.

ClassloaderExample.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugforward-portIssues automatically duplicated from other versions via an action

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions