Skip to content

Commit 154aec7

Browse files
committed
Merge branch '6.0.x'
2 parents a11b803 + 10de295 commit 154aec7

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/expressions/language-ref/types.adoc

+10
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,15 @@ Kotlin::
3838
----
3939
======
4040

41+
[NOTE]
42+
====
43+
If your application or framework manages its own `EvaluationContext`, you may need to
44+
manually configure a `StandardTypeLocator` with a specific `ClassLoader` to ensure that
45+
the SpEL expression parser is able to reliably locate user types.
46+
47+
For example, the `StandardBeanExpressionResolver` in the `spring-context` module
48+
configures a `StandardTypeLocator` using the bean `ClassLoader` of the corresponding
49+
`BeanFactory`.
50+
====
4151

4252

Diff for: spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java

+27-4
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@
4040

4141
/**
4242
* A powerful and highly configurable {@link EvaluationContext} implementation.
43-
* This context uses standard implementations of all applicable strategies,
44-
* based on reflection to resolve properties, methods and fields.
4543
*
46-
* <p>For a simpler builder-style context variant for data-binding purposes,
44+
* <p>This context uses standard implementations of all applicable strategies,
45+
* based on reflection to resolve properties, methods, and fields. Note, however,
46+
* that you may need to manually configure a {@code StandardTypeLocator} with a
47+
* specific {@link ClassLoader} to ensure that the SpEL expression parser is able
48+
* to reliably locate user types. See {@link #setTypeLocator(TypeLocator)} for
49+
* details.
50+
*
51+
* <p>For a simpler, builder-style context variant for data-binding purposes,
4752
* consider using {@link SimpleEvaluationContext} instead which allows for
48-
* opting into several SpEL features as needed by specific evaluation cases.
53+
* opting into several SpEL features as needed by specific use cases.
4954
*
5055
* @author Andy Clement
5156
* @author Juergen Hoeller
@@ -183,11 +188,29 @@ public BeanResolver getBeanResolver() {
183188
return this.beanResolver;
184189
}
185190

191+
/**
192+
* Set the {@link TypeLocator} to use to find types, either by short or
193+
* fully-qualified name.
194+
* <p>By default, a {@link StandardTypeLocator} will be used.
195+
* <p><strong>NOTE</strong>: Even if a {@code StandardTypeLocator} is
196+
* sufficient, you may need to manually configure a {@code StandardTypeLocator}
197+
* with a specific {@link ClassLoader} to ensure that the SpEL expression
198+
* parser is able to reliably locate user types.
199+
* @param typeLocator the {@code TypeLocator} to use
200+
* @see StandardTypeLocator#StandardTypeLocator(ClassLoader)
201+
* @see #getTypeLocator()
202+
*/
186203
public void setTypeLocator(TypeLocator typeLocator) {
187204
Assert.notNull(typeLocator, "TypeLocator must not be null");
188205
this.typeLocator = typeLocator;
189206
}
190207

208+
/**
209+
* Get the configured {@link TypeLocator} that will be used to find types,
210+
* either by short or fully-qualified name.
211+
* <p>See {@link #setTypeLocator(TypeLocator)} for further details.
212+
* @see #setTypeLocator(TypeLocator)
213+
*/
191214
@Override
192215
public TypeLocator getTypeLocator() {
193216
if (this.typeLocator == null) {

Diff for: spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929

3030
/**
3131
* A simple implementation of {@link TypeLocator} that uses the default
32-
* {@link ClassLoader} or a supplied {@link ClassLoader} to locate types.
32+
* {@link #StandardTypeLocator() ClassLoader} or a supplied
33+
* {@link #StandardTypeLocator(ClassLoader) ClassLoader} to locate types.
3334
*
3435
* <p>Supports <em>well-known</em> packages, registered as
3536
* {@linkplain #registerImport(String) import prefixes}. If a type cannot be found,
@@ -51,6 +52,9 @@ public class StandardTypeLocator implements TypeLocator {
5152
/**
5253
* Create a {@code StandardTypeLocator} for the default {@link ClassLoader}
5354
* (typically, the thread context {@code ClassLoader}).
55+
* <p>Favor {@link #StandardTypeLocator(ClassLoader)} over this constructor
56+
* in order to provide a specific {@link ClassLoader} that is able to reliably
57+
* locate user types.
5458
* @see ClassUtils#getDefaultClassLoader()
5559
*/
5660
public StandardTypeLocator() {
@@ -59,6 +63,9 @@ public StandardTypeLocator() {
5963

6064
/**
6165
* Create a {@code StandardTypeLocator} for the given {@link ClassLoader}.
66+
* <p>Favor this constructor over {@link #StandardTypeLocator()} in order
67+
* to provide a specific {@link ClassLoader} that is able to reliably locate
68+
* user types.
6269
* @param classLoader the {@code ClassLoader} to delegate to
6370
*/
6471
public StandardTypeLocator(@Nullable ClassLoader classLoader) {

0 commit comments

Comments
 (0)