|
20 | 20 | import org.junit.jupiter.api.Timeout;
|
21 | 21 |
|
22 | 22 | import org.springframework.beans.factory.ObjectProvider;
|
| 23 | +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
| 24 | +import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
23 | 25 | import org.springframework.beans.testfixture.beans.TestBean;
|
24 | 26 | import org.springframework.context.ConfigurableApplicationContext;
|
| 27 | +import org.springframework.core.SpringProperties; |
25 | 28 | import org.springframework.core.testfixture.EnabledForTestGroups;
|
26 | 29 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
27 | 30 |
|
| 31 | +import static org.assertj.core.api.Assertions.assertThat; |
28 | 32 | import static org.springframework.context.annotation.Bean.Bootstrap.BACKGROUND;
|
29 | 33 | import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
30 | 34 |
|
@@ -56,6 +60,21 @@ void bootstrapWithUnmanagedThreads() {
|
56 | 60 | ctx.close();
|
57 | 61 | }
|
58 | 62 |
|
| 63 | + @Test |
| 64 | + @Timeout(5) |
| 65 | + @EnabledForTestGroups(LONG_RUNNING) |
| 66 | + void bootstrapWithStrictLockingThread() { |
| 67 | + SpringProperties.setFlag(DefaultListableBeanFactory.STRICT_LOCKING_PROPERTY_NAME); |
| 68 | + try { |
| 69 | + ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(StrictLockingBeanConfig.class); |
| 70 | + assertThat(ctx.getBean("testBean2", TestBean.class).getSpouse()).isSameAs(ctx.getBean("testBean1")); |
| 71 | + ctx.close(); |
| 72 | + } |
| 73 | + finally { |
| 74 | + SpringProperties.setProperty(DefaultListableBeanFactory.STRICT_LOCKING_PROPERTY_NAME, null); |
| 75 | + } |
| 76 | + } |
| 77 | + |
59 | 78 | @Test
|
60 | 79 | @Timeout(5)
|
61 | 80 | @EnabledForTestGroups(LONG_RUNNING)
|
@@ -148,6 +167,28 @@ public TestBean testBean4() {
|
148 | 167 | }
|
149 | 168 |
|
150 | 169 |
|
| 170 | + @Configuration(proxyBeanMethods = false) |
| 171 | + static class StrictLockingBeanConfig { |
| 172 | + |
| 173 | + @Bean |
| 174 | + public TestBean testBean1(ObjectProvider<TestBean> testBean2) { |
| 175 | + new Thread(testBean2::getObject).start(); |
| 176 | + try { |
| 177 | + Thread.sleep(1000); |
| 178 | + } |
| 179 | + catch (InterruptedException ex) { |
| 180 | + throw new RuntimeException(ex); |
| 181 | + } |
| 182 | + return new TestBean(); |
| 183 | + } |
| 184 | + |
| 185 | + @Bean |
| 186 | + public TestBean testBean2(ConfigurableListableBeanFactory beanFactory) { |
| 187 | + return new TestBean((TestBean) beanFactory.getSingleton("testBean1")); |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + |
151 | 192 | @Configuration(proxyBeanMethods = false)
|
152 | 193 | static class CircularReferenceBeanConfig {
|
153 | 194 |
|
|
0 commit comments