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 36672767b1..66e081adc2 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 @@ -34,6 +34,7 @@ import org.springframework.core.convert.ConversionService; import org.springframework.expression.BeanResolver; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypeConverter; +import org.springframework.expression.TypeLocator; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.integration.context.IntegrationContextUtils; @@ -78,6 +79,8 @@ public class IntegrationEvaluationContextFactoryBean implements FactoryBean(functionsArg); } + public void setTypeLocator(TypeLocator typeLocator) { + this.typeLocator = typeLocator; + } + @Override public void afterPropertiesSet() throws Exception { @@ -158,6 +165,9 @@ public class IntegrationEvaluationContextFactoryBean implements FactoryBean + + + + + + + + + + + + + + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/expression/ForeignClassloaderTests.java b/spring-integration-core/src/test/java/org/springframework/integration/expression/ForeignClassloaderTests.java new file mode 100644 index 0000000000..3d71e64dde --- /dev/null +++ b/spring-integration-core/src/test/java/org/springframework/integration/expression/ForeignClassloaderTests.java @@ -0,0 +1,84 @@ +/* + * Copyright 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.expression; + +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Gary Russell + * @since 3.0.2 + * + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@DirtiesContext +public class ForeignClassloaderTests { + + @Autowired + private MessageChannel foo; + + @Autowired + private PollableChannel bar; + + /** + * Sends a message on a thread that has a ClassLoader that doesn't have visibility to Foo. + * Fails without a custom TypeLocator in the evaluation context factory bean. + */ + @Test + public void testThreadHasWrongClassLoader() { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + try { + foo.send(new GenericMessage("foo")); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + }); + t.setContextClassLoader(new ClassLoader() { + + @Override + public Class loadClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException("Foo not found"); + } + }); + t.start(); + Message reply = bar.receive(10000); + assertThat(reply.getPayload(), instanceOf(Foo.class)); + } + + public static class Foo { + + } + +} diff --git a/src/reference/docbook/spel.xml b/src/reference/docbook/spel.xml index 6518653bb5..d067548483 100644 --- a/src/reference/docbook/spel.xml +++ b/src/reference/docbook/spel.xml @@ -53,13 +53,13 @@ described in the following sections, and the framework will automatically configure the factory bean on your behalf. - - - "/> - + + + @@ -89,6 +89,20 @@ and configure a custom property accessor to do so. So, your final expression might be "#barcalc(payload.myBar)". + + The factory bean has another property typeLocator which allows you to customize + the TypeLocator used during SpEL evaluation. This might be + necessary when running in some environments that use a non-standard ClassLoader. + In the following example, SpEL expressions will always use the bean factory's class loader: + + + + + + + +]]>
SpEL Functions