Consistently throw IllegalStateException from getAutowireCapableBeanFactory()
Issue: SPR-12932
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 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.
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.springframework.context.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
@@ -89,7 +91,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private boolean refreshed = false;
|
||||
private final AtomicBoolean refreshed = new AtomicBoolean();
|
||||
|
||||
|
||||
/**
|
||||
@@ -235,12 +237,11 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
*/
|
||||
@Override
|
||||
protected final void refreshBeanFactory() throws IllegalStateException {
|
||||
if (this.refreshed) {
|
||||
if (!this.refreshed.compareAndSet(false, true)) {
|
||||
throw new IllegalStateException(
|
||||
"GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once");
|
||||
}
|
||||
this.beanFactory.setSerializationId(getId());
|
||||
this.refreshed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -279,6 +280,12 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
|
||||
assertBeanFactoryActive();
|
||||
return this.beanFactory;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Implementation of BeanDefinitionRegistry
|
||||
|
||||
Reference in New Issue
Block a user