Skip to content

Commit 9999414

Browse files
committed
Merge branch '5.2.x'
2 parents 212bb7f + c35b21b commit 9999414

File tree

6 files changed

+46
-44
lines changed

6 files changed

+46
-44
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,12 +41,11 @@
4141
* regular constructors: i.e. lookup methods cannot get replaced on beans returned
4242
* from factory methods where we cannot dynamically provide a subclass for them.
4343
*
44-
* <p><b>Concrete limitations in typical Spring configuration scenarios:</b>
45-
* When used with component scanning or any other mechanism that filters out abstract
46-
* beans, provide stub implementations of your lookup methods to be able to declare
47-
* them as concrete classes. And please remember that lookup methods won't work on
48-
* beans returned from {@code @Bean} methods in configuration classes; you'll have
49-
* to resort to {@code @Inject Provider<TargetBean>} or the like instead.
44+
* <p><b>Recommendations for typical Spring configuration scenarios:</b>
45+
* When a concrete class may be needed in certain scenarios, consider providing stub
46+
* implementations of your lookup methods. And please remember that lookup methods
47+
* won't work on beans returned from {@code @Bean} methods in configuration classes;
48+
* you'll have to resort to {@code @Inject Provider<TargetBean>} or the like instead.
5049
*
5150
* @author Juergen Hoeller
5251
* @since 4.1

spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,8 +41,13 @@
4141
* {@link org.springframework.beans.factory.config.BeanExpressionResolver}
4242
* interface, parsing and evaluating Spring EL using Spring's expression module.
4343
*
44+
* <p>All beans in the containing {@code BeanFactory} are made available as
45+
* predefined variables with their common bean name, including standard context
46+
* beans such as "environment", "systemProperties" and "systemEnvironment".
47+
*
4448
* @author Juergen Hoeller
4549
* @since 3.0
50+
* @see BeanExpressionContext#getBeanFactory()
4651
* @see org.springframework.expression.ExpressionParser
4752
* @see org.springframework.expression.spel.standard.SpelExpressionParser
4853
* @see org.springframework.expression.spel.support.StandardEvaluationContext

spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -72,10 +72,7 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
7272

7373
/** Bean factory for this context. */
7474
@Nullable
75-
private DefaultListableBeanFactory beanFactory;
76-
77-
/** Synchronization monitor for the internal BeanFactory. */
78-
private final Object beanFactoryMonitor = new Object();
75+
private volatile DefaultListableBeanFactory beanFactory;
7976

8077

8178
/**
@@ -131,9 +128,7 @@ protected final void refreshBeanFactory() throws BeansException {
131128
beanFactory.setSerializationId(getId());
132129
customizeBeanFactory(beanFactory);
133130
loadBeanDefinitions(beanFactory);
134-
synchronized (this.beanFactoryMonitor) {
135-
this.beanFactory = beanFactory;
136-
}
131+
this.beanFactory = beanFactory;
137132
}
138133
catch (IOException ex) {
139134
throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
@@ -142,21 +137,19 @@ protected final void refreshBeanFactory() throws BeansException {
142137

143138
@Override
144139
protected void cancelRefresh(BeansException ex) {
145-
synchronized (this.beanFactoryMonitor) {
146-
if (this.beanFactory != null) {
147-
this.beanFactory.setSerializationId(null);
148-
}
140+
DefaultListableBeanFactory beanFactory = this.beanFactory;
141+
if (beanFactory != null) {
142+
beanFactory.setSerializationId(null);
149143
}
150144
super.cancelRefresh(ex);
151145
}
152146

153147
@Override
154148
protected final void closeBeanFactory() {
155-
synchronized (this.beanFactoryMonitor) {
156-
if (this.beanFactory != null) {
157-
this.beanFactory.setSerializationId(null);
158-
this.beanFactory = null;
159-
}
149+
DefaultListableBeanFactory beanFactory = this.beanFactory;
150+
if (beanFactory != null) {
151+
beanFactory.setSerializationId(null);
152+
this.beanFactory = null;
160153
}
161154
}
162155

@@ -165,20 +158,17 @@ protected final void closeBeanFactory() {
165158
* i.e. has been refreshed at least once and not been closed yet.
166159
*/
167160
protected final boolean hasBeanFactory() {
168-
synchronized (this.beanFactoryMonitor) {
169-
return (this.beanFactory != null);
170-
}
161+
return (this.beanFactory != null);
171162
}
172163

173164
@Override
174165
public final ConfigurableListableBeanFactory getBeanFactory() {
175-
synchronized (this.beanFactoryMonitor) {
176-
if (this.beanFactory == null) {
177-
throw new IllegalStateException("BeanFactory not initialized or already closed - " +
178-
"call 'refresh' before accessing beans via the ApplicationContext");
179-
}
180-
return this.beanFactory;
166+
DefaultListableBeanFactory beanFactory = this.beanFactory;
167+
if (beanFactory == null) {
168+
throw new IllegalStateException("BeanFactory not initialized or already closed - " +
169+
"call 'refresh' before accessing beans via the ApplicationContext");
181170
}
171+
return beanFactory;
182172
}
183173

184174
/**

spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,17 +87,20 @@ public String getBeanName() {
8787

8888
@Override
8989
public void setInterceptors(List<ChannelInterceptor> interceptors) {
90+
Assert.noNullElements(interceptors, "'interceptors' must not contain null elements");
9091
this.interceptors.clear();
9192
this.interceptors.addAll(interceptors);
9293
}
9394

9495
@Override
9596
public void addInterceptor(ChannelInterceptor interceptor) {
97+
Assert.notNull(interceptor, "'interceptor' must not be null");
9698
this.interceptors.add(interceptor);
9799
}
98100

99101
@Override
100102
public void addInterceptor(int index, ChannelInterceptor interceptor) {
103+
Assert.notNull(interceptor, "'interceptor' must not be null");
101104
this.interceptors.add(index, interceptor);
102105
}
103106

spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import org.springframework.http.client.ClientHttpRequestInterceptor;
2525
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
2626
import org.springframework.lang.Nullable;
27+
import org.springframework.util.Assert;
2728
import org.springframework.util.CollectionUtils;
2829

2930
/**
@@ -57,6 +58,7 @@ public abstract class InterceptingHttpAccessor extends HttpAccessor {
5758
* @see AnnotationAwareOrderComparator
5859
*/
5960
public void setInterceptors(List<ClientHttpRequestInterceptor> interceptors) {
61+
Assert.noNullElements(interceptors, "'interceptors' must not contain null elements");
6062
// Take getInterceptors() List as-is when passed in here
6163
if (this.interceptors != interceptors) {
6264
this.interceptors.clear();

src/docs/asciidoc/core/core-expressions.adoc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,12 @@ example shows:
539539
</bean>
540540
----
541541

542-
The `systemProperties` variable is predefined, so you can use it in your expressions, as
543-
the following example shows:
542+
All beans in the application context are available as predefined variables with their
543+
common bean name. This includes standard context beans such as `environment` (of type
544+
`org.springframework.core.env.Environment`) as well as `systemProperties` and
545+
`systemEnvironment` (of type `Map<String, Object>`) for access to the runtime environment.
546+
547+
The following example shows access to the `systemProperties` bean as a SpEL variable:
544548

545549
[source,xml,indent=0,subs="verbatim"]
546550
----
@@ -551,8 +555,7 @@ the following example shows:
551555
</bean>
552556
----
553557

554-
Note that you do not have to prefix the predefined variable with the `#`
555-
symbol in this context.
558+
Note that you do not have to prefix the predefined variable with the `#` symbol here.
556559

557560
You can also refer to other bean properties by name, as the following example shows:
558561

@@ -576,8 +579,8 @@ You can also refer to other bean properties by name, as the following example sh
576579
[[expressions-beandef-annotation-based]]
577580
=== Annotation Configuration
578581

579-
To specify a default value, you can place the `@Value` annotation on fields, methods, and method or constructor
580-
parameters.
582+
To specify a default value, you can place the `@Value` annotation on fields, methods,
583+
and method or constructor parameters.
581584

582585
The following example sets the default value of a field variable:
583586

@@ -1675,15 +1678,15 @@ The following example shows how to use the Elvis operator:
16751678
----
16761679
ExpressionParser parser = new SpelExpressionParser();
16771680
1678-
String name = parser.parseExpression("name?:'Unknown'").getValue(String.class);
1681+
String name = parser.parseExpression("name?:'Unknown'").getValue(new Inventor(), String.class);
16791682
System.out.println(name); // 'Unknown'
16801683
----
16811684
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
16821685
.Kotlin
16831686
----
16841687
val parser = SpelExpressionParser()
16851688
1686-
val name = parser.parseExpression("name?:'Unknown'").getValue(String::class.java)
1689+
val name = parser.parseExpression("name?:'Unknown'").getValue(Inventor(), String::class.java)
16871690
println(name) // 'Unknown'
16881691
----
16891692

0 commit comments

Comments
 (0)