From b7b49862d3fe3f965582f87200b06c1b6e07dbdc Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 9 Jan 2025 16:27:38 -0500 Subject: [PATCH] GH-9745: IntEvalCtxFB: Use `BeanFactory`'s `ClassLoader` Fixes: #9745 Issue link: https://github.com/spring-projects/spring-integration/issues/9745 The `IntegrationEvaluationContextFactoryBean` does not provide a `TypeLocator` by default. That may lead to a class-not-found problem from different `ClassLoader` in the parallel Java `Stream` executor. * Fix `IntegrationEvaluationContextFactoryBean` to use a `StandardTypeLocator` based on the `applicationContext.getClassLoader()` (cherry picked from commit 6184c4082ae523c416069ba1fb311bb5df3e6e30) --- .../IntegrationEvaluationContextFactoryBean.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationEvaluationContextFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationEvaluationContextFactoryBean.java index 8101a522c5..c9c7b8258c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationEvaluationContextFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationEvaluationContextFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2024 the original author or authors. + * Copyright 2013-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.util.Map.Entry; import org.springframework.beans.factory.FactoryBean; +import org.springframework.context.ApplicationContext; import org.springframework.context.expression.BeanFactoryResolver; import org.springframework.context.expression.MapAccessor; import org.springframework.expression.BeanResolver; @@ -27,7 +28,9 @@ import org.springframework.expression.IndexAccessor; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypeLocator; import org.springframework.expression.spel.support.StandardEvaluationContext; +import org.springframework.expression.spel.support.StandardTypeLocator; import org.springframework.integration.context.IntegrationContextUtils; +import org.springframework.lang.Nullable; /** *

@@ -66,7 +69,8 @@ import org.springframework.integration.context.IntegrationContextUtils; public class IntegrationEvaluationContextFactoryBean extends AbstractEvaluationContextFactoryBean implements FactoryBean { - private volatile TypeLocator typeLocator; + @Nullable + private TypeLocator typeLocator; private BeanResolver beanResolver; @@ -81,8 +85,12 @@ public class IntegrationEvaluationContextFactoryBean extends AbstractEvaluationC @Override public void afterPropertiesSet() { - if (getApplicationContext() != null) { - this.beanResolver = new BeanFactoryResolver(getApplicationContext()); + ApplicationContext applicationContext = getApplicationContext(); + if (applicationContext != null) { + this.beanResolver = new BeanFactoryResolver(applicationContext); + if (this.typeLocator == null) { + this.typeLocator = new StandardTypeLocator(applicationContext.getClassLoader()); + } } initialize(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME); }