|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2015 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.context.support;
|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
| 20 | +import java.util.concurrent.atomic.AtomicBoolean; |
20 | 21 |
|
21 | 22 | import org.springframework.beans.BeansException;
|
22 | 23 | import org.springframework.beans.factory.BeanDefinitionStoreException;
|
23 | 24 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
| 25 | +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; |
24 | 26 | import org.springframework.beans.factory.config.BeanDefinition;
|
25 | 27 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
26 | 28 | import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
@@ -89,7 +91,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
89 | 91 |
|
90 | 92 | private ResourceLoader resourceLoader;
|
91 | 93 |
|
92 |
| - private boolean refreshed = false; |
| 94 | + private final AtomicBoolean refreshed = new AtomicBoolean(); |
93 | 95 |
|
94 | 96 |
|
95 | 97 | /**
|
@@ -235,12 +237,11 @@ public Resource[] getResources(String locationPattern) throws IOException {
|
235 | 237 | */
|
236 | 238 | @Override
|
237 | 239 | protected final void refreshBeanFactory() throws IllegalStateException {
|
238 |
| - if (this.refreshed) { |
| 240 | + if (!this.refreshed.compareAndSet(false, true)) { |
239 | 241 | throw new IllegalStateException(
|
240 | 242 | "GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once");
|
241 | 243 | }
|
242 | 244 | this.beanFactory.setSerializationId(getId());
|
243 |
| - this.refreshed = true; |
244 | 245 | }
|
245 | 246 |
|
246 | 247 | @Override
|
@@ -279,6 +280,12 @@ public final DefaultListableBeanFactory getDefaultListableBeanFactory() {
|
279 | 280 | return this.beanFactory;
|
280 | 281 | }
|
281 | 282 |
|
| 283 | + @Override |
| 284 | + public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException { |
| 285 | + assertBeanFactoryActive(); |
| 286 | + return this.beanFactory; |
| 287 | + } |
| 288 | + |
282 | 289 |
|
283 | 290 | //---------------------------------------------------------------------
|
284 | 291 | // Implementation of BeanDefinitionRegistry
|
|
0 commit comments