Skip to content

Commit f2f5ce9

Browse files
Prevent AOT code generation for Reactive repositories.
Closes: #1611
1 parent b7494f6 commit f2f5ce9

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ public static class CassandraRepositoryRegistrationAotProcessor extends Reposito
133133
return null;
134134
}
135135

136+
if(repositoryContext.getRepositoryInformation().isReactiveRepository()) {
137+
return null;
138+
}
139+
136140
return new CassandraRepositoryContributor(repositoryContext);
137141
}
138142

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.cassandra.repository.config;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import org.junit.jupiter.api.Test;
21+
import org.mockito.Mockito;
22+
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
23+
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
24+
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
25+
import org.springframework.core.env.StandardEnvironment;
26+
import org.springframework.core.io.DefaultResourceLoader;
27+
import org.springframework.core.type.AnnotationMetadata;
28+
import org.springframework.data.cassandra.repository.aot.TestCassandraAotRepositoryContext;
29+
import org.springframework.data.cassandra.repository.config.CassandraRepositoryConfigurationExtension.CassandraRepositoryRegistrationAotProcessor;
30+
import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource;
31+
import org.springframework.data.repository.core.support.RepositoryComposition;
32+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
33+
34+
/**
35+
* @author Christoph Strobl
36+
*/
37+
class CassandraRepositoryRegistrationAotProcessorUnitTests {
38+
39+
@Test // GH-1611
40+
void shouldNotAttemptToProcessReactiveRepository() {
41+
42+
AnnotationRepositoryConfigurationSource configSource = new AnnotationRepositoryConfigurationSource(
43+
AnnotationMetadata.introspect(ReactiveCassandraRepositoryConfiguration.class), EnableReactiveCassandraRepositories.class, new DefaultResourceLoader(),
44+
new StandardEnvironment(), Mockito.mock(BeanDefinitionRegistry.class), DefaultBeanNameGenerator.INSTANCE);
45+
46+
TestCassandraAotRepositoryContext<?> context = new TestCassandraAotRepositoryContext<>(new DefaultListableBeanFactory(), ReactiveCassandraRepo.class, RepositoryComposition.empty(), configSource);
47+
48+
CassandraRepositoryRegistrationAotProcessor processor = new CassandraRepositoryRegistrationAotProcessor();
49+
assertThat(processor.contributeAotRepository(context)).isNull();
50+
}
51+
52+
interface ReactiveCassandraRepo extends ReactiveCrudRepository<SampleEntity, Long> {
53+
54+
}
55+
56+
static class SampleEntity {
57+
58+
}
59+
60+
@EnableReactiveCassandraRepositories
61+
static class ReactiveCassandraRepositoryConfiguration {
62+
63+
}
64+
}

0 commit comments

Comments
 (0)