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 ;
23
22
import org .springframework .beans .factory .ObjectProvider ;
24
23
import org .springframework .beans .testfixture .beans .TestBean ;
25
24
import org .springframework .context .ConfigurableApplicationContext ;
26
25
import org .springframework .core .testfixture .EnabledForTestGroups ;
27
26
import org .springframework .scheduling .concurrent .ThreadPoolTaskExecutor ;
28
27
29
- import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
30
28
import static org .springframework .context .annotation .Bean .Bootstrap .BACKGROUND ;
31
29
import static org .springframework .core .testfixture .TestGroup .LONG_RUNNING ;
32
30
@@ -42,8 +40,19 @@ class BackgroundBootstrapTests {
42
40
void bootstrapWithUnmanagedThread () {
43
41
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext (UnmanagedThreadBeanConfig .class );
44
42
ctx .getBean ("testBean1" , TestBean .class );
45
- assertThatExceptionOfType (BeanCurrentlyInCreationException .class ).isThrownBy ( // late - not during refresh
46
- () -> ctx .getBean ("testBean2" , TestBean .class ));
43
+ ctx .getBean ("testBean2" , TestBean .class );
44
+ ctx .close ();
45
+ }
46
+
47
+ @ Test
48
+ @ Timeout (5 )
49
+ @ EnabledForTestGroups (LONG_RUNNING )
50
+ void bootstrapWithUnmanagedThreads () {
51
+ ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext (UnmanagedThreadsBeanConfig .class );
52
+ ctx .getBean ("testBean1" , TestBean .class );
53
+ ctx .getBean ("testBean2" , TestBean .class );
54
+ ctx .getBean ("testBean3" , TestBean .class );
55
+ ctx .getBean ("testBean4" , TestBean .class );
47
56
ctx .close ();
48
57
}
49
58
@@ -55,6 +64,7 @@ void bootstrapWithCustomExecutor() {
55
64
ctx .getBean ("testBean1" , TestBean .class );
56
65
ctx .getBean ("testBean2" , TestBean .class );
57
66
ctx .getBean ("testBean3" , TestBean .class );
67
+ ctx .getBean ("testBean4" , TestBean .class );
58
68
ctx .close ();
59
69
}
60
70
@@ -87,6 +97,45 @@ public TestBean testBean2() {
87
97
}
88
98
89
99
100
+ @ Configuration (proxyBeanMethods = false )
101
+ static class UnmanagedThreadsBeanConfig {
102
+
103
+ @ Bean
104
+ public TestBean testBean1 (ObjectProvider <TestBean > testBean3 , ObjectProvider <TestBean > testBean4 ) {
105
+ new Thread (testBean3 ::getObject ).start ();
106
+ new Thread (testBean4 ::getObject ).start ();
107
+ try {
108
+ Thread .sleep (1000 );
109
+ }
110
+ catch (InterruptedException ex ) {
111
+ throw new RuntimeException (ex );
112
+ }
113
+ return new TestBean ();
114
+ }
115
+
116
+ @ Bean
117
+ public TestBean testBean2 (TestBean testBean4 ) {
118
+ return new TestBean (testBean4 );
119
+ }
120
+
121
+ @ Bean
122
+ public TestBean testBean3 (TestBean testBean4 ) {
123
+ return new TestBean (testBean4 );
124
+ }
125
+
126
+ @ Bean
127
+ public TestBean testBean4 () {
128
+ try {
129
+ Thread .sleep (2000 );
130
+ }
131
+ catch (InterruptedException ex ) {
132
+ throw new RuntimeException (ex );
133
+ }
134
+ return new TestBean ();
135
+ }
136
+ }
137
+
138
+
90
139
@ Configuration (proxyBeanMethods = false )
91
140
static class CustomExecutorBeanConfig {
92
141
@@ -117,8 +166,8 @@ public TestBean testBean3() {
117
166
}
118
167
119
168
@ Bean
120
- public String dependent (@ Lazy TestBean testBean1 , @ Lazy TestBean testBean2 , @ Lazy TestBean testBean3 ) {
121
- return "" ;
169
+ public TestBean testBean4 (@ Lazy TestBean testBean1 , @ Lazy TestBean testBean2 , @ Lazy TestBean testBean3 ) {
170
+ return new TestBean () ;
122
171
}
123
172
}
124
173
0 commit comments