3838import org .springframework .core .annotation .MergedAnnotation ;
3939import org .springframework .data .annotation .Id ;
4040import org .springframework .data .aot .AotContext ;
41+ import org .springframework .data .mongodb .repository .ReactivePersonRepository ;
4142import org .springframework .data .mongodb .repository .support .SimpleMongoRepository ;
43+ import org .springframework .data .mongodb .repository .support .SimpleReactiveMongoRepository ;
4244import org .springframework .data .repository .Repository ;
4345import org .springframework .data .repository .config .AotRepositoryContextSupport ;
4446import org .springframework .data .repository .config .AotRepositoryInformation ;
@@ -102,13 +104,32 @@ void shouldDisableAotRepositoriesWhenJpaGeneratedRepositoriesIsFalse() {
102104 assertThat (contributor ).isNull ();
103105 }
104106
107+ @ Test // GH-5068
108+ void shouldNotAttemptToContributeCodeForReactiveRepository (){
109+ 110+ GenericApplicationContext context = new GenericApplicationContext ();
111+ context .refresh ();
112+ 113+ MongoRepositoryContributor contributor = createContributorForReactiveRepo (context );
114+ 115+ assertThat (contributor ).isNull ();
116+ }
117+ 105118 private GenerationContext createGenerationContext () {
106119 return new DefaultGenerationContext (new ClassNameGenerator (ClassName .OBJECT ), new InMemoryGeneratedFiles ());
107120 }
108121
122+ private MongoRepositoryContributor createContributorForReactiveRepo (GenericApplicationContext context ) {
123+ return createContributorWithPersonTypes (context , true );
124+ }
125+ 109126 private MongoRepositoryContributor createContributorWithPersonTypes (GenericApplicationContext context ) {
127+ return createContributorWithPersonTypes (context , false );
128+ }
110129
111- return new AotMongoRepositoryPostProcessor ().contributeAotRepository (new DummyAotRepositoryContext (context ) {
130+ private MongoRepositoryContributor createContributorWithPersonTypes (GenericApplicationContext context , boolean reactive ) {
131+ 132+ return new AotMongoRepositoryPostProcessor ().contributeAotRepository (new DummyAotRepositoryContext (context , reactive ) {
112133 @ Override
113134 public Set <Class <?>> getResolvedTypes () {
114135 return Collections .singleton (Person .class );
@@ -125,8 +146,11 @@ interface PersonRepository extends Repository<Person, Long> {}
125146
126147 static class DummyAotRepositoryContext extends AotRepositoryContextSupport {
127148
128- DummyAotRepositoryContext (AbstractApplicationContext applicationContext ) {
149+ boolean reactive ;
150+ 151+ DummyAotRepositoryContext (AbstractApplicationContext applicationContext , boolean reactive ) {
129152 super (AotContext .from (applicationContext , applicationContext .getEnvironment ()));
153+ this .reactive = reactive ;
130154 }
131155
132156 @ Override
@@ -151,6 +175,10 @@ public Set<Class<? extends Annotation>> getIdentifyingAnnotations() {
151175
152176 @ Override
153177 public RepositoryInformation getRepositoryInformation () {
178+ if (reactive ) {
179+ return new AotRepositoryInformation (AbstractRepositoryMetadata .getMetadata (ReactivePersonRepository .class ),
180+ SimpleReactiveMongoRepository .class , List .of ());
181+ }
154182 return new AotRepositoryInformation (AbstractRepositoryMetadata .getMetadata (PersonRepository .class ),
155183 SimpleMongoRepository .class , List .of ());
156184 }
0 commit comments