Changing class loader for flow assembly

146 Views Asked by At

I am using Spring Web flow 2.4.8.RELEASE with Spring version 4.3.11. There are certain classes being used in the flow file that are not part of standard class loader. They are being loaded using application specific class loader.

How can I change change the class loader used by FlowModelFlowBuilder?

java.lang.IllegalArgumentException: Unable to load class '<CLASS TO LOAD USING DIFFERENT CLASS LOADER>'
at org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder.toClass(FlowModelFlowBuilder.java:977)
at org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder.parseFlowVariable(FlowModelFlowBuilder.java:402)
at org.springframework.webflow.engine.builder.model.FlowModelFlowBuilder.buildVariables(FlowModelFlowBuilder.java:181)
at org.springframework.webflow.engine.builder.FlowAssembler.directAssembly(FlowAssembler.java:103)
at org.springframework.webflow.engine.builder.FlowAssembler.assembleFlow(FlowAssembler.java:91)
at org.springframework.webflow.engine.builder.DefaultFlowHolder.assembleFlow(DefaultFlowHolder.java:109)
at org.springframework.webflow.engine.builder.DefaultFlowHolder.getFlowDefinition(DefaultFlowHolder.java:84)
at org.springframework.webflow.definition.registry.FlowDefinitionRegistryImpl.getFlowDefinition(FlowDefinitionRegistryImpl.java:60)
at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:138)
at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:263)
at org.springframework.faces.webflow.JsfFlowHandlerAdapter.handle(JsfFlowHandlerAdapter.java:57)

FlowModelFlowBuilder calls getLocalContext().getApplicationContext().getClassLoader() to get the class loader. It return instance of ParallelWebappClassLoader.

I am looking for a way to let FlowModelFlowBuilder to specify custom class loader. Is it possible to customize FlowModelFlowBuilder?

1

There are 1 best solutions below

0
Sujay On

Found another way. Instead of trying to find way to customize the Flow specifics, used ContextRefreshedEvent Listener and changed the class loader. As the beans are loaded after the context refreshed, following approach worked

public class WebflowApplicationContextListener implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent( final ContextRefreshedEvent p_event ) {
        ApplicationContext l_appContext = p_event.getApplicationContext();
        if ( l_appContext instanceof GenericWebApplicationContext ) {
            ( (GenericWebApplicationContext) l_appContext ).setClassLoader( getSpecificContextClassLoader() );
        }
    }

}