|
19 | 19 | import org.junit.jupiter.api.Test;
|
20 | 20 | import org.junit.jupiter.api.Timeout;
|
21 | 21 |
|
| 22 | +import org.springframework.beans.factory.BeanCurrentlyInCreationException; |
22 | 23 | import org.springframework.beans.factory.ObjectProvider;
|
| 24 | +import org.springframework.beans.factory.UnsatisfiedDependencyException; |
23 | 25 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
24 | 26 | import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
25 | 27 | import org.springframework.beans.testfixture.beans.TestBean;
|
|
29 | 31 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
30 | 32 |
|
31 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
| 34 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
32 | 35 | import static org.springframework.context.annotation.Bean.Bootstrap.BACKGROUND;
|
33 | 36 | import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
34 | 37 |
|
@@ -85,6 +88,15 @@ void bootstrapWithCircularReference() {
|
85 | 88 | ctx.close();
|
86 | 89 | }
|
87 | 90 |
|
| 91 | + @Test |
| 92 | + @Timeout(5) |
| 93 | + @EnabledForTestGroups(LONG_RUNNING) |
| 94 | + void bootstrapWithCircularReferenceInSameThread() { |
| 95 | + assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
| 96 | + .isThrownBy(() -> new AnnotationConfigApplicationContext(CircularReferenceInSameThreadBeanConfig.class)) |
| 97 | + .withRootCauseInstanceOf(BeanCurrentlyInCreationException.class); |
| 98 | + } |
| 99 | + |
88 | 100 | @Test
|
89 | 101 | @Timeout(5)
|
90 | 102 | @EnabledForTestGroups(LONG_RUNNING)
|
@@ -179,7 +191,7 @@ public TestBean testBean1(ObjectProvider<TestBean> testBean2) {
|
179 | 191 | catch (InterruptedException ex) {
|
180 | 192 | throw new RuntimeException(ex);
|
181 | 193 | }
|
182 |
| - return new TestBean(); |
| 194 | + return new TestBean("testBean1"); |
183 | 195 | }
|
184 | 196 |
|
185 | 197 | @Bean
|
@@ -217,6 +229,39 @@ public TestBean testBean2(TestBean testBean1) {
|
217 | 229 | }
|
218 | 230 |
|
219 | 231 |
|
| 232 | + @Configuration(proxyBeanMethods = false) |
| 233 | + static class CircularReferenceInSameThreadBeanConfig { |
| 234 | + |
| 235 | + @Bean |
| 236 | + public TestBean testBean1(ObjectProvider<TestBean> testBean2) { |
| 237 | + new Thread(testBean2::getObject).start(); |
| 238 | + try { |
| 239 | + Thread.sleep(1000); |
| 240 | + } |
| 241 | + catch (InterruptedException ex) { |
| 242 | + throw new RuntimeException(ex); |
| 243 | + } |
| 244 | + return new TestBean(); |
| 245 | + } |
| 246 | + |
| 247 | + @Bean |
| 248 | + public TestBean testBean2(TestBean testBean3) { |
| 249 | + try { |
| 250 | + Thread.sleep(2000); |
| 251 | + } |
| 252 | + catch (InterruptedException ex) { |
| 253 | + throw new RuntimeException(ex); |
| 254 | + } |
| 255 | + return new TestBean(); |
| 256 | + } |
| 257 | + |
| 258 | + @Bean |
| 259 | + public TestBean testBean3(TestBean testBean2) { |
| 260 | + return new TestBean(); |
| 261 | + } |
| 262 | + } |
| 263 | + |
| 264 | + |
220 | 265 | @Configuration(proxyBeanMethods = false)
|
221 | 266 | static class CustomExecutorBeanConfig {
|
222 | 267 |
|
|
0 commit comments