Gemfire: Caused by: java.lang.ClassCastException: Application fails to start with error "class org.jboss.modules.LocalModuleLoader cannot be cast to class com.vmware.gemfire.bootstrap.internal.GemFireModuleLoader"
search cancel

Gemfire: Caused by: java.lang.ClassCastException: Application fails to start with error "class org.jboss.modules.LocalModuleLoader cannot be cast to class com.vmware.gemfire.bootstrap.internal.GemFireModuleLoader"

book

Article ID: 407455

calendar_today

Updated On:

Products

VMware Tanzu Greenplum / Gemfire

Issue/Introduction

While trying to load the application context from a Spring application as shown: 

 final ApplicationContext context =
                new ClassPathXmlApplicationContext("<application context configuration filename>");

you get the error below:

Caused by: java.lang.ClassCastException: class org.jboss.modules.LocalModuleLoader cannot be cast to class com.vmware.gemfire.bootstrap.internal.GemFireModuleLoader (org.jboss.modules.LocalModuleLoader and com.vmware.gemfire.bootstrap.internal.GemFireModuleLoader are in unnamed module of loader 'app')\
\'a0 \'a0 \'a0 \'a0 at com.vmware.gemfire.deployment.modules.internal.service.GemFireJBossModuleService.<init>(GemFireJBossModuleService.java:31)\
\'a0 \'a0 \'a0 \'a0 at com.vmware.gemfire.deployment.modules.internal.ModularJarDeploymentService.

 

 

Resolution

Options to resolve the issue are to 

1. Fix the classpath from the application.

or

2. As a workaround, modify the code as shown below.

Some classes that are required for the application to startup can be loaded during runtime using the context class loader (thread classloader), which bypasses the default parent delegation model of the default classloader.

 

Add the line

Thread.currentThread().setContextClassLoader(
        GemFireModuleLoader.getInstance()

before

final ApplicationContext context =
                new ClassPathXmlApplicationContext("loader_account_context.xml");

in your application.