diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java index 495354aa20..0fca4f3316 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2020 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. @@ -41,12 +41,11 @@ import java.lang.annotation.Target; * regular constructors: i.e. lookup methods cannot get replaced on beans returned * from factory methods where we cannot dynamically provide a subclass for them. * - *
Concrete limitations in typical Spring configuration scenarios:
- * When used with component scanning or any other mechanism that filters out abstract
- * beans, provide stub implementations of your lookup methods to be able to declare
- * them as concrete classes. And please remember that lookup methods won't work on
- * beans returned from {@code @Bean} methods in configuration classes; you'll have
- * to resort to {@code @Inject Provider Recommendations for typical Spring configuration scenarios:
+ * When a concrete class may be needed in certain scenarios, consider providing stub
+ * implementations of your lookup methods. And please remember that lookup methods
+ * won't work on beans returned from {@code @Bean} methods in configuration classes;
+ * you'll have to resort to {@code @Inject Provider All beans in the containing {@code BeanFactory} are made available as
+ * predefined variables with their common bean name, including standard context
+ * beans such as "environment", "systemProperties" and "systemEnvironment".
+ *
* @author Juergen Hoeller
* @since 3.0
+ * @see BeanExpressionContext#getBeanFactory()
* @see org.springframework.expression.ExpressionParser
* @see org.springframework.expression.spel.standard.SpelExpressionParser
* @see org.springframework.expression.spel.support.StandardEvaluationContext
diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
index 173ef62ecb..9c87844e9d 100644
--- a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
+++ b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2018 the original author or authors.
+ * Copyright 2002-2020 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.
@@ -72,10 +72,7 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
/** Bean factory for this context. */
@Nullable
- private DefaultListableBeanFactory beanFactory;
-
- /** Synchronization monitor for the internal BeanFactory. */
- private final Object beanFactoryMonitor = new Object();
+ private volatile DefaultListableBeanFactory beanFactory;
/**
@@ -131,9 +128,7 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
beanFactory.setSerializationId(getId());
customizeBeanFactory(beanFactory);
loadBeanDefinitions(beanFactory);
- synchronized (this.beanFactoryMonitor) {
- this.beanFactory = beanFactory;
- }
+ this.beanFactory = beanFactory;
}
catch (IOException ex) {
throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
@@ -142,21 +137,19 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
@Override
protected void cancelRefresh(BeansException ex) {
- synchronized (this.beanFactoryMonitor) {
- if (this.beanFactory != null) {
- this.beanFactory.setSerializationId(null);
- }
+ DefaultListableBeanFactory beanFactory = this.beanFactory;
+ if (beanFactory != null) {
+ beanFactory.setSerializationId(null);
}
super.cancelRefresh(ex);
}
@Override
protected final void closeBeanFactory() {
- synchronized (this.beanFactoryMonitor) {
- if (this.beanFactory != null) {
- this.beanFactory.setSerializationId(null);
- this.beanFactory = null;
- }
+ DefaultListableBeanFactory beanFactory = this.beanFactory;
+ if (beanFactory != null) {
+ beanFactory.setSerializationId(null);
+ this.beanFactory = null;
}
}
@@ -165,20 +158,17 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
* i.e. has been refreshed at least once and not been closed yet.
*/
protected final boolean hasBeanFactory() {
- synchronized (this.beanFactoryMonitor) {
- return (this.beanFactory != null);
- }
+ return (this.beanFactory != null);
}
@Override
public final ConfigurableListableBeanFactory getBeanFactory() {
- synchronized (this.beanFactoryMonitor) {
- if (this.beanFactory == null) {
- throw new IllegalStateException("BeanFactory not initialized or already closed - " +
- "call 'refresh' before accessing beans via the ApplicationContext");
- }
- return this.beanFactory;
+ DefaultListableBeanFactory beanFactory = this.beanFactory;
+ if (beanFactory == null) {
+ throw new IllegalStateException("BeanFactory not initialized or already closed - " +
+ "call 'refresh' before accessing beans via the ApplicationContext");
}
+ return beanFactory;
}
/**
diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java
index c933757d33..40d6a09899 100644
--- a/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java
+++ b/spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2019 the original author or authors.
+ * Copyright 2002-2020 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.
@@ -87,17 +87,20 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep
@Override
public void setInterceptors(List