diff --git a/src/main/java/org/springframework/data/redis/repository/RedisRepository.java b/src/main/java/org/springframework/data/redis/repository/RedisRepository.java new file mode 100644 index 0000000000..7575e02f8f --- /dev/null +++ b/src/main/java/org/springframework/data/redis/repository/RedisRepository.java @@ -0,0 +1,12 @@ +package org.springframework.data.redis.repository; + +import org.springframework.data.keyvalue.repository.KeyValueRepository; + +/** + * Redis specific {@link org.springframework.data.repository.Repository} interface. + * + * @author Junghoon Ban + * @param + * @param + */ +public interface RedisRepository extends KeyValueRepository {} diff --git a/src/main/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtension.java b/src/main/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtension.java index 1fea6ba25b..ca719bf231 100644 --- a/src/main/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtension.java +++ b/src/main/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtension.java @@ -19,12 +19,14 @@ import java.util.Collection; import java.util.Collections; +import java.util.List; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.data.keyvalue.repository.KeyValueRepository; import org.springframework.data.keyvalue.repository.config.KeyValueRepositoryConfigurationExtension; import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.RedisKeyValueAdapter; @@ -35,6 +37,7 @@ import org.springframework.data.redis.core.convert.MappingRedisConverter; import org.springframework.data.redis.core.convert.RedisCustomConversions; import org.springframework.data.redis.core.mapping.RedisMappingContext; +import org.springframework.data.redis.repository.RedisRepository; import org.springframework.data.repository.config.RepositoryConfigurationExtension; import org.springframework.data.repository.config.RepositoryConfigurationSource; import org.springframework.util.StringUtils; @@ -44,6 +47,7 @@ * * @author Christoph Strobl * @author Mark Paluch + * @author Junghoon Ban * @since 1.7 */ public class RedisRepositoryConfigurationExtension extends KeyValueRepositoryConfigurationExtension { @@ -69,6 +73,11 @@ protected String getDefaultKeyValueTemplateRef() { return "redisKeyValueTemplate"; } + @Override + protected Collection> getIdentifyingTypes() { + return List.of(RedisRepository.class, KeyValueRepository.class); + } + @Override public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configuration) { diff --git a/src/main/java/org/springframework/data/redis/repository/support/RedisRepositoryFactory.java b/src/main/java/org/springframework/data/redis/repository/support/RedisRepositoryFactory.java index 2ce06cbd3d..8d434c1322 100644 --- a/src/main/java/org/springframework/data/redis/repository/support/RedisRepositoryFactory.java +++ b/src/main/java/org/springframework/data/redis/repository/support/RedisRepositoryFactory.java @@ -38,6 +38,7 @@ * @author Christoph Strobl * @author Oliver Gierke * @author Mark Paluch + * @author Junghoon Ban * @since 1.7 */ public class RedisRepositoryFactory extends KeyValueRepositoryFactory { @@ -75,6 +76,11 @@ public RedisRepositoryFactory(KeyValueOperations keyValueOperations, this.operations = keyValueOperations; } + @Override + protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { + return SimpleRedisRepository.class; + } + @Override protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) { diff --git a/src/main/java/org/springframework/data/redis/repository/support/SimpleRedisRepository.java b/src/main/java/org/springframework/data/redis/repository/support/SimpleRedisRepository.java new file mode 100644 index 0000000000..61e4e57724 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/repository/support/SimpleRedisRepository.java @@ -0,0 +1,22 @@ +package org.springframework.data.redis.repository.support; + +import org.springframework.data.keyvalue.core.KeyValueOperations; +import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository; +import org.springframework.data.redis.repository.RedisRepository; +import org.springframework.data.repository.NoRepositoryBean; +import org.springframework.data.repository.core.EntityInformation; + +/** + * Redis specific repository implementation. + * + * @author Junghoon Ban + * @param + * @param + */ +@NoRepositoryBean +public class SimpleRedisRepository extends SimpleKeyValueRepository implements RedisRepository { + + public SimpleRedisRepository(EntityInformation metadata, KeyValueOperations operations) { + super(metadata, operations); + } +} diff --git a/src/test/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtensionUnitTests.java b/src/test/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtensionUnitTests.java index 34b0efaa78..33ea7d85d6 100644 --- a/src/test/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtensionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/repository/configuration/RedisRepositoryConfigurationExtensionUnitTests.java @@ -33,6 +33,7 @@ import org.springframework.data.keyvalue.repository.KeyValueRepository; import org.springframework.data.redis.core.RedisHash; import org.springframework.data.redis.core.RedisKeyValueAdapter.EnableKeyspaceEvents; +import org.springframework.data.redis.repository.RedisRepository; import org.springframework.data.repository.Repository; import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; import org.springframework.data.repository.config.RepositoryConfiguration; @@ -117,6 +118,11 @@ void explicitlyEmptyKeyspaceNotificationsConfigParameterShouldBeCapturedCorrectl assertThat(getKeyspaceNotificationsConfigParameter(beanDefintionRegistry)).isEqualTo(""); } + @Test // GH-2816 + void shouldConsiderModuleSpecificRepository() { + assertHasRepo(ModuleSpecificRepository.class, extension.getRepositoryConfigurations(configurationSource, loader, true)); + } + private static void assertDoesNotHaveRepo(Class repositoryInterface, Collection> configs) { @@ -198,4 +204,6 @@ interface SampleRepository extends Repository {} interface UnannotatedRepository extends Repository {} interface StoreRepository extends KeyValueRepository {} + + interface ModuleSpecificRepository extends RedisRepository {} }