17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
20
+ import java .lang .reflect .TypeVariable ;
20
21
import java .util .List ;
21
22
import java .util .Optional ;
22
23
import java .util .UUID ;
39
40
import org .springframework .context .annotation .ComponentScan .Filter ;
40
41
import org .springframework .context .annotation .FilterType ;
41
42
import org .springframework .context .support .GenericApplicationContext ;
43
+ import org .springframework .core .ResolvableType ;
42
44
import org .springframework .core .env .StandardEnvironment ;
43
45
import org .springframework .core .metrics .ApplicationStartup ;
44
46
import org .springframework .core .type .AnnotationMetadata ;
@@ -232,6 +234,38 @@ void registersAotPostProcessorForDifferentConfigurations() {
232
234
assertThat (context .getBeanNamesForType (RepositoryRegistrationAotProcessor .class )).hasSize (2 );
233
235
}
234
236
237
+ @ Test // GH-3074
238
+ void registersGenericsForIdConstrainingRepositoryFactoryBean () {
239
+
240
+ ResolvableType it = registerBeanDefinition (IdConstrainingRepositoryFactoryBean .class );
241
+
242
+ assertThat (it .getGenerics ()).hasSize (2 );
243
+ assertThat (it .getGeneric (0 ).resolve ()).isEqualTo (MyAnnotatedRepository .class );
244
+ assertThat (it .getGeneric (1 ).resolve ()).isEqualTo (Person .class );
245
+ }
246
+
247
+ @ Test // GH-3074
248
+ void registersGenericsForDomainTypeConstrainingRepositoryFactoryBean () {
249
+
250
+ ResolvableType it = registerBeanDefinition (DomainTypeConstrainingRepositoryFactoryBean .class );
251
+
252
+ assertThat (it .getGenerics ()).hasSize (2 );
253
+ assertThat (it .getGeneric (0 ).resolve ()).isEqualTo (MyAnnotatedRepository .class );
254
+ assertThat (it .getGeneric (1 ).resolve ()).isEqualTo (String .class );
255
+ }
256
+
257
+ @ Test // GH-3074
258
+ void registersGenericsForAdditionalGenericsRepositoryFactoryBean () {
259
+
260
+ ResolvableType it = registerBeanDefinition (AdditionalGenericsRepositoryFactoryBean .class );
261
+
262
+ assertThat (it .getGenerics ()).hasSize (4 );
263
+ assertThat (it .getGeneric (0 ).resolve ()).isEqualTo (MyAnnotatedRepository .class );
264
+ assertThat (it .getGeneric (1 ).resolve ()).isEqualTo (Person .class );
265
+ assertThat (it .getGeneric (2 ).resolve ()).isEqualTo (String .class );
266
+ assertThat (it .getGeneric (3 ).getType ()).isInstanceOf (TypeVariable .class );
267
+ }
268
+
235
269
private static ListableBeanFactory assertLazyRepositoryBeanSetup (Class <?> configClass ) {
236
270
237
271
var context = new AnnotationConfigApplicationContext (configClass );
@@ -289,8 +323,7 @@ protected String getModulePrefix() {
289
323
}
290
324
}
291
325
292
- @ Test // GH-3074
293
- void registersGenericsForConstrainingRepositoryFactoryBean () {
326
+ private ResolvableType registerBeanDefinition (Class <?> repositoryFactoryType ) {
294
327
295
328
AnnotationMetadata metadata = AnnotationMetadata .introspect (AnnotatedBeanNamesConfig .class );
296
329
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
@@ -301,7 +334,7 @@ void registersGenericsForConstrainingRepositoryFactoryBean() {
301
334
302
335
@ Override
303
336
public Optional <String > getRepositoryFactoryBeanClassName () {
304
- return Optional .of (IdConstrainingRepositoryFactoryBean . class .getName ());
337
+ return Optional .of (repositoryFactoryType .getName ());
305
338
}
306
339
};
307
340
@@ -313,11 +346,9 @@ public Optional<String> getRepositoryFactoryBeanClassName() {
313
346
assertThat (repositories ).hasSize (1 ).element (0 )
314
347
.extracting (BeanComponentDefinition ::getBeanDefinition )
315
348
.extracting (BeanDefinition ::getResolvableType )
316
- .satisfies (it -> {
317
- assertThat (it .getGenerics ()).hasSize (2 );
318
- assertThat (it .getGeneric (0 ).resolve ()).isEqualTo (MyAnnotatedRepository .class );
319
- assertThat (it .getGeneric (1 ).resolve ()).isEqualTo (Person .class );
320
- });
349
+ .isNotNull ();
350
+
351
+ return repositories .get (0 ).getBeanDefinition ().getResolvableType ();
321
352
}
322
353
323
354
static abstract class IdConstrainingRepositoryFactoryBean <T extends Repository <S , UUID >, S >
@@ -327,4 +358,20 @@ protected IdConstrainingRepositoryFactoryBean(Class<? extends T> repositoryInter
327
358
super (repositoryInterface );
328
359
}
329
360
}
361
+
362
+ static abstract class DomainTypeConstrainingRepositoryFactoryBean <T extends Repository <Person , ID >, ID >
363
+ extends RepositoryFactoryBeanSupport <T , Person , ID > {
364
+
365
+ protected DomainTypeConstrainingRepositoryFactoryBean (Class <? extends T > repositoryInterface ) {
366
+ super (repositoryInterface );
367
+ }
368
+ }
369
+
370
+ static abstract class AdditionalGenericsRepositoryFactoryBean <T extends Repository <S , ID >, S , ID , R >
371
+ extends RepositoryFactoryBeanSupport <T , S , ID > {
372
+
373
+ protected AdditionalGenericsRepositoryFactoryBean (Class <? extends T > repositoryInterface ) {
374
+ super (repositoryInterface );
375
+ }
376
+ }
330
377
}
0 commit comments