@@ -82,6 +82,22 @@ public void indirectlyAnnotatedWithImport() {
82
82
assertThat (foo , is ("xyz" ));
83
83
}
84
84
85
+ @ Test
86
+ public void directlyAnnotatedWithImportLite () {
87
+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext ();
88
+ ctx .register (ImportingConfigLite .class );
89
+ ctx .refresh ();
90
+ assertNotNull (ctx .getBean ("importedConfigBean" ));
91
+
92
+ ImportedConfigLite importAwareConfig = ctx .getBean (ImportedConfigLite .class );
93
+ AnnotationMetadata importMetadata = importAwareConfig .importMetadata ;
94
+ assertThat ("import metadata was not injected" , importMetadata , notNullValue ());
95
+ assertThat (importMetadata .getClassName (), is (ImportingConfigLite .class .getName ()));
96
+ AnnotationAttributes importAttribs = AnnotationConfigUtils .attributesFor (importMetadata , Import .class );
97
+ Class <?>[] importedClasses = importAttribs .getClassArray ("value" );
98
+ assertThat (importedClasses [0 ].getName (), is (ImportedConfigLite .class .getName ()));
99
+ }
100
+
85
101
@ Test
86
102
public void importRegistrar () {
87
103
ImportedRegistrar .called = false ;
@@ -135,7 +151,7 @@ static class ImportingConfig {
135
151
136
152
137
153
@ Configuration
138
- @ EnableImportedConfig (foo = "xyz" )
154
+ @ EnableImportedConfig (foo = "xyz" )
139
155
static class IndirectlyImportingConfig {
140
156
}
141
157
@@ -180,6 +196,34 @@ public String otherImportedConfigBean() {
180
196
}
181
197
182
198
199
+ @ Configuration
200
+ @ Import (ImportedConfigLite .class )
201
+ static class ImportingConfigLite {
202
+ }
203
+
204
+
205
+ @ Configuration (proxyBeanMethods = false )
206
+ static class ImportedConfigLite implements ImportAware {
207
+
208
+ AnnotationMetadata importMetadata ;
209
+
210
+ @ Override
211
+ public void setImportMetadata (AnnotationMetadata importMetadata ) {
212
+ this .importMetadata = importMetadata ;
213
+ }
214
+
215
+ @ Bean
216
+ public BPP importedConfigBean () {
217
+ return new BPP ();
218
+ }
219
+
220
+ @ Bean
221
+ public AsyncAnnotationBeanPostProcessor asyncBPP () {
222
+ return new AsyncAnnotationBeanPostProcessor ();
223
+ }
224
+ }
225
+
226
+
183
227
static class BPP implements BeanPostProcessor , BeanFactoryAware {
184
228
185
229
@ Override
@@ -274,6 +318,32 @@ public MetadataHolder holder() {
274
318
}
275
319
276
320
321
+ @ Import (LiteConfiguration .class )
322
+ @ Target (ElementType .TYPE )
323
+ @ Retention (RetentionPolicy .RUNTIME )
324
+ public @interface EnableLiteConfiguration {
325
+
326
+ String value () default "" ;
327
+ }
328
+
329
+
330
+ @ Configuration (proxyBeanMethods = false )
331
+ public static class LiteConfiguration implements ImportAware {
332
+
333
+ private AnnotationMetadata importMetadata ;
334
+
335
+ @ Override
336
+ public void setImportMetadata (AnnotationMetadata importMetadata ) {
337
+ this .importMetadata = importMetadata ;
338
+ }
339
+
340
+ @ Bean
341
+ public MetadataHolder holder () {
342
+ return new MetadataHolder (this .importMetadata );
343
+ }
344
+ }
345
+
346
+
277
347
public static class MetadataHolder {
278
348
279
349
private final AnnotationMetadata importMetadata ;
0 commit comments