@@ -206,15 +206,24 @@ void invokeAwareMethodsInImportGroup() {
206
206
207
207
@ Test
208
208
void importAnnotationOnImplementedInterfaceIsRespected () {
209
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
210
- context .register (InterfaceBasedConfig .class );
211
- context .refresh ();
209
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
210
+ InterfaceBasedConfig .class );
212
211
213
212
assertThat (context .getBean (ImportedConfig .class )).isNotNull ();
214
213
assertThat (context .getBean (ImportedBean .class )).isNotNull ();
215
214
assertThat (context .getBean (ImportedBean .class ).name ()).isEqualTo ("imported" );
216
215
}
217
216
217
+ @ Test
218
+ void localImportShouldOverrideInterfaceImport () {
219
+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
220
+ OverridingConfig .class );
221
+
222
+ assertThat (context .getBean (ImportedConfig .class )).isNotNull ();
223
+ assertThat (context .getBean (ImportedBean .class )).isNotNull ();
224
+ assertThat (context .getBean (ImportedBean .class ).name ()).isEqualTo ("from class" );
225
+ }
226
+
218
227
@ Import (ImportedConfig .class )
219
228
interface ConfigImportMarker {
220
229
}
@@ -223,9 +232,28 @@ interface ConfigImportMarker {
223
232
static class InterfaceBasedConfig implements ConfigImportMarker {
224
233
}
225
234
235
+ @ Configuration
236
+ static class OverridingConfig implements ConfigImportMarker {
237
+ @ Bean
238
+ ImportedBean importedBean () {
239
+ return new ImportedBean ("from class" );
240
+ }
241
+ }
242
+
226
243
static class ImportedBean {
244
+
245
+ private final String name ;
246
+
247
+ ImportedBean () {
248
+ this .name = "imported" ;
249
+ }
250
+
251
+ ImportedBean (String name ) {
252
+ this .name = name ;
253
+ }
254
+
227
255
String name () {
228
- return "imported" ;
256
+ return name ;
229
257
}
230
258
}
231
259
@@ -540,7 +568,7 @@ public static class ChildDeferredImportSelector1 implements DeferredImportSelect
540
568
@ Override
541
569
public String [] selectImports (AnnotationMetadata importingClassMetadata ) {
542
570
ImportSelectorTests .importFrom .put (getClass (), importingClassMetadata .getClassName ());
543
- return new String [] { DeferredImportedSelector3 .class .getName () };
571
+ return new String []{ DeferredImportedSelector3 .class .getName ()};
544
572
}
545
573
546
574
@ Override
0 commit comments