更改类装入器以进行流组装

时间:2019-03-12 10:31:18

标签: spring-webflow-2

我在Spring版本4.3.11中使用Spring Web flow 2.4.8.RELEASE。流文件中使用的某些类不是标准类加载器的一部分。使用特定于应用程序的类加载器加载它们。

如何更改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调用getLocalContext()。getApplicationContext()。getClassLoader()以获取类加载器。它返回ParallelWebappClassLoader的实例。

我正在寻找一种让FlowModelFlowBuilder指定自定义类加载器的方法。是否可以自定义FlowModelFlowBuilder?

1 个答案:

答案 0 :(得分:0)

找到了另一种方法。与其尝试找到自定义Flow细节的方法,不如使用ContextRefreshedEvent Listener并更改了类加载器。在刷新上下文后加载Bean时,以下方法有效

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() );
        }
    }

}