diff --git a/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHints.java b/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHints.java new file mode 100644 index 000000000..0a891b5b7 --- /dev/null +++ b/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHints.java @@ -0,0 +1,138 @@ +/* + * Copyright 2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.redis.aot; + +import java.util.Arrays; + +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.hint.TypeReference; +import org.springframework.data.keyvalue.annotation.KeySpace; +import org.springframework.data.keyvalue.core.AbstractKeyValueAdapter; +import org.springframework.data.keyvalue.core.KeyValueAdapter; +import org.springframework.data.keyvalue.core.KeyValueOperations; +import org.springframework.data.keyvalue.core.KeyValueTemplate; +import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext; +import org.springframework.data.keyvalue.repository.KeyValueRepository; +import org.springframework.data.keyvalue.repository.config.QueryCreatorType; +import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery; +import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean; +import org.springframework.data.redis.connection.*; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.core.convert.KeyspaceConfiguration; +import org.springframework.data.redis.core.convert.MappingConfiguration; +import org.springframework.data.redis.core.convert.MappingRedisConverter; +import org.springframework.data.redis.core.convert.RedisConverter; +import org.springframework.data.redis.core.convert.RedisCustomConversions; +import org.springframework.data.redis.core.convert.ReferenceResolver; +import org.springframework.data.redis.core.convert.ReferenceResolverImpl; +import org.springframework.data.redis.core.index.ConfigurableIndexDefinitionProvider; +import org.springframework.data.redis.core.index.IndexConfiguration; +import org.springframework.data.redis.core.mapping.RedisMappingContext; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; +import org.springframework.data.redis.repository.query.RedisQueryCreator; +import org.springframework.data.redis.repository.support.RedisRepositoryFactoryBean; +import org.springframework.lang.Nullable; + +/** + * {@link RuntimeHintsRegistrar} for Redis operations and repository support. + * + * @author Christoph Strobl + * @since 3.0 + */ +class RedisRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + + // REFLECTION + hints.reflection().registerTypes(Arrays.asList(TypeReference.of(RedisConnection.class), + TypeReference.of(StringRedisConnection.class), TypeReference.of(DefaultedRedisConnection.class), + TypeReference.of(DefaultedRedisClusterConnection.class), TypeReference.of(RedisKeyCommands.class), + TypeReference.of(RedisStringCommands.class), TypeReference.of(RedisListCommands.class), + TypeReference.of(RedisSetCommands.class), TypeReference.of(RedisZSetCommands.class), + TypeReference.of(RedisHashCommands.class), TypeReference.of(RedisTxCommands.class), + TypeReference.of(RedisPubSubCommands.class), TypeReference.of(RedisConnectionCommands.class), + TypeReference.of(RedisServerCommands.class), TypeReference.of(RedisStreamCommands.class), + TypeReference.of(RedisScriptingCommands.class), TypeReference.of(RedisGeoCommands.class), + TypeReference.of(RedisHyperLogLogCommands.class), TypeReference.of(RedisClusterCommands.class), + TypeReference.of(ReactiveRedisConnection.class), TypeReference.of(ReactiveKeyCommands.class), + TypeReference.of(ReactiveStringCommands.class), TypeReference.of(ReactiveListCommands.class), + TypeReference.of(ReactiveSetCommands.class), TypeReference.of(ReactiveZSetCommands.class), + TypeReference.of(ReactiveHashCommands.class), TypeReference.of(ReactivePubSubCommands.class), + TypeReference.of(ReactiveServerCommands.class), TypeReference.of(ReactiveStreamCommands.class), + TypeReference.of(ReactiveScriptingCommands.class), TypeReference.of(ReactiveGeoCommands.class), + TypeReference.of(ReactiveHyperLogLogCommands.class), TypeReference.of(ReactiveClusterKeyCommands.class), + TypeReference.of(ReactiveClusterStringCommands.class), TypeReference.of(ReactiveClusterListCommands.class), + TypeReference.of(ReactiveClusterSetCommands.class), TypeReference.of(ReactiveClusterZSetCommands.class), + TypeReference.of(ReactiveClusterHashCommands.class), TypeReference.of(ReactiveClusterServerCommands.class), + TypeReference.of(ReactiveClusterStreamCommands.class), TypeReference.of(ReactiveClusterScriptingCommands.class), + TypeReference.of(ReactiveClusterGeoCommands.class), TypeReference.of(ReactiveClusterHyperLogLogCommands.class), + TypeReference.of(ReactiveRedisOperations.class), TypeReference.of(ReactiveRedisTemplate.class), + TypeReference.of(RedisOperations.class), TypeReference.of(RedisTemplate.class), + TypeReference.of(StringRedisTemplate.class), TypeReference.of(KeyspaceConfiguration.class), + TypeReference.of(MappingConfiguration.class), TypeReference.of(MappingRedisConverter.class), + TypeReference.of(RedisConverter.class), TypeReference.of(RedisCustomConversions.class), + TypeReference.of(ReferenceResolver.class), TypeReference.of(ReferenceResolverImpl.class), + TypeReference.of(IndexConfiguration.class), TypeReference.of(ConfigurableIndexDefinitionProvider.class), + TypeReference.of(RedisMappingContext.class), TypeReference.of(RedisRepositoryFactoryBean.class), + TypeReference.of(RedisQueryCreator.class), TypeReference.of(MessageListener.class), + TypeReference.of(RedisMessageListenerContainer.class), + + TypeReference.of(RedisKeyValueAdapter.class), TypeReference.of(RedisKeyValueTemplate.class), + + // Key-Value + TypeReference.of(KeySpace.class), TypeReference.of(AbstractKeyValueAdapter.class), + TypeReference.of(KeyValueAdapter.class), TypeReference.of(KeyValueOperations.class), + TypeReference.of(KeyValueTemplate.class), TypeReference.of(KeyValueMappingContext.class), + TypeReference.of(KeyValueRepository.class), TypeReference.of(KeyValueRepositoryFactoryBean.class), + TypeReference.of(QueryCreatorType.class), TypeReference.of(KeyValuePartTreeQuery.class)), + + hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS)); + + // PROXIES + hints.proxies().registerJdkProxy(TypeReference.of(RedisConnection.class)); + hints.proxies().registerJdkProxy(TypeReference.of(DefaultedRedisConnection.class)); + hints.proxies().registerJdkProxy(TypeReference.of(ReactiveRedisConnection.class)); + hints.proxies().registerJdkProxy(TypeReference.of(StringRedisConnection.class), + TypeReference.of(DecoratedRedisConnection.class)); + + // keys are bound by a proxy + boundOperationsProxy(BoundGeoOperations.class, hints); + boundOperationsProxy(BoundHashOperations.class, hints); + boundOperationsProxy(BoundKeyOperations.class, hints); + boundOperationsProxy(BoundListOperations.class, hints); + boundOperationsProxy(BoundSetOperations.class, hints); + boundOperationsProxy(BoundStreamOperations.class, hints); + boundOperationsProxy(BoundValueOperations.class, hints); + boundOperationsProxy(BoundZSetOperations.class, hints); + boundOperationsProxy( + TypeReference.of("org.springframework.data.redis.core.BoundOperationsProxyFactory$DefaultBoundKeyOperations"), + hints); + } + + private void boundOperationsProxy(Class type, RuntimeHints hints) { + boundOperationsProxy(TypeReference.of(type), hints); + } + + private void boundOperationsProxy(TypeReference typeReference, RuntimeHints hints) { + hints.proxies().registerJdkProxy(typeReference, // + TypeReference.of("org.springframework.aop.SpringProxy"), // + TypeReference.of("org.springframework.aop.framework.Advised"), // + TypeReference.of("org.springframework.core.DecoratingProxy")); + } +} diff --git a/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHintsRegistrar.java b/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHintsRegistrar.java deleted file mode 100644 index e04be4967..000000000 --- a/src/main/java/org/springframework/data/redis/aot/RedisRuntimeHintsRegistrar.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.redis.aot; - -import java.util.Arrays; - -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeReference; -import org.springframework.data.redis.core.BoundGeoOperations; -import org.springframework.data.redis.core.BoundHashOperations; -import org.springframework.data.redis.core.BoundKeyOperations; -import org.springframework.data.redis.core.BoundListOperations; -import org.springframework.data.redis.core.BoundSetOperations; -import org.springframework.data.redis.core.BoundStreamOperations; -import org.springframework.data.redis.core.BoundValueOperations; -import org.springframework.data.redis.core.BoundZSetOperations; -import org.springframework.lang.Nullable; - -/** - * @author Christoph Strobl - * @since 3.0 - */ -public class RedisRuntimeHintsRegistrar implements RuntimeHintsRegistrar { - - @Override - public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { - - // REFLECTION - hints.reflection() - .registerTypes( - Arrays.asList(TypeReference.of(org.springframework.data.redis.connection.RedisConnection.class), - TypeReference.of(org.springframework.data.redis.connection.StringRedisConnection.class), - TypeReference.of(org.springframework.data.redis.connection.DefaultedRedisConnection.class), - TypeReference.of(org.springframework.data.redis.connection.DefaultedRedisClusterConnection.class), - TypeReference.of(org.springframework.data.redis.connection.RedisKeyCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisStringCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisListCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisZSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisHashCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisTxCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisPubSubCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisConnectionCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisServerCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisStreamCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisScriptingCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisGeoCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisHyperLogLogCommands.class), - TypeReference.of(org.springframework.data.redis.connection.RedisClusterCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveRedisConnection.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveKeyCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveStringCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveListCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveZSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveHashCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactivePubSubCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveServerCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveStreamCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveScriptingCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveGeoCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveHyperLogLogCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterKeyCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterStringCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterListCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterZSetCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterHashCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterServerCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterStreamCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterScriptingCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterGeoCommands.class), - TypeReference.of(org.springframework.data.redis.connection.ReactiveClusterHyperLogLogCommands.class), - TypeReference.of(org.springframework.data.redis.core.ReactiveRedisOperations.class), - TypeReference.of(org.springframework.data.redis.core.ReactiveRedisTemplate.class), - TypeReference.of(org.springframework.data.redis.core.RedisOperations.class), - TypeReference.of(org.springframework.data.redis.core.RedisTemplate.class), - TypeReference.of(org.springframework.data.redis.core.StringRedisTemplate.class), - TypeReference.of(org.springframework.data.keyvalue.annotation.KeySpace.class), - TypeReference.of(org.springframework.data.keyvalue.core.AbstractKeyValueAdapter.class), - TypeReference.of(org.springframework.data.keyvalue.core.KeyValueAdapter.class), - TypeReference.of(org.springframework.data.keyvalue.core.KeyValueOperations.class), - TypeReference.of(org.springframework.data.keyvalue.core.KeyValueTemplate.class), - TypeReference.of(org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext.class), - TypeReference.of(org.springframework.data.keyvalue.repository.KeyValueRepository.class), - TypeReference - .of(org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactoryBean.class), - TypeReference.of(org.springframework.data.keyvalue.repository.config.QueryCreatorType.class), - TypeReference.of(org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery.class), - TypeReference.of(org.springframework.data.redis.core.RedisKeyValueAdapter.class), - TypeReference.of(org.springframework.data.redis.core.RedisKeyValueTemplate.class), - TypeReference.of(org.springframework.data.redis.core.convert.KeyspaceConfiguration.class), - TypeReference.of(org.springframework.data.redis.core.convert.MappingConfiguration.class), - TypeReference.of(org.springframework.data.redis.core.convert.MappingRedisConverter.class), - TypeReference.of(org.springframework.data.redis.core.convert.RedisConverter.class), - TypeReference.of(org.springframework.data.redis.core.convert.RedisCustomConversions.class), - TypeReference.of(org.springframework.data.redis.core.convert.ReferenceResolver.class), - TypeReference.of(org.springframework.data.redis.core.convert.ReferenceResolverImpl.class), - TypeReference.of(org.springframework.data.redis.core.index.IndexConfiguration.class), - TypeReference.of(org.springframework.data.redis.core.index.ConfigurableIndexDefinitionProvider.class), - TypeReference.of(org.springframework.data.redis.core.mapping.RedisMappingContext.class), - TypeReference.of(org.springframework.data.redis.repository.support.RedisRepositoryFactoryBean.class), - TypeReference.of(org.springframework.data.redis.repository.query.RedisQueryCreator.class), - TypeReference.of(org.springframework.data.redis.connection.MessageListener.class), - TypeReference.of(org.springframework.data.redis.listener.RedisMessageListenerContainer.class)), - hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, - MemberCategory.INVOKE_PUBLIC_METHODS)); - - // PROXIES - hints.proxies().registerJdkProxy(TypeReference.of(org.springframework.data.redis.connection.RedisConnection.class)); - hints.proxies() - .registerJdkProxy(TypeReference.of(org.springframework.data.redis.connection.DefaultedRedisConnection.class)); - hints.proxies() - .registerJdkProxy(TypeReference.of(org.springframework.data.redis.connection.ReactiveRedisConnection.class)); - hints.proxies().registerJdkProxy( - TypeReference.of(org.springframework.data.redis.connection.StringRedisConnection.class), - TypeReference.of(org.springframework.data.redis.connection.DecoratedRedisConnection.class)); - - // keys are bound by a proxy - boundOperationsProxy(BoundGeoOperations.class, hints); - boundOperationsProxy(BoundHashOperations.class, hints); - boundOperationsProxy(BoundKeyOperations.class, hints); - boundOperationsProxy(BoundListOperations.class, hints); - boundOperationsProxy(BoundSetOperations.class, hints); - boundOperationsProxy(BoundStreamOperations.class, hints); - boundOperationsProxy(BoundValueOperations.class, hints); - boundOperationsProxy(BoundZSetOperations.class, hints); - boundOperationsProxy( - TypeReference.of("org.springframework.data.redis.core.BoundOperationsProxyFactory$DefaultBoundKeyOperations"), - hints); - } - - private void boundOperationsProxy(Class type, RuntimeHints hints) { - boundOperationsProxy(TypeReference.of(type), hints); - } - - private void boundOperationsProxy(TypeReference typeReference, RuntimeHints hints) { - hints.proxies().registerJdkProxy(typeReference, // - TypeReference.of("org.springframework.aop.SpringProxy"), // - TypeReference.of("org.springframework.aop.framework.Advised"), // - TypeReference.of("org.springframework.core.DecoratingProxy")); - } -} diff --git a/src/main/resources/META-INF/spring/aot.factories b/src/main/resources/META-INF/spring/aot.factories index 173ad9f2f..e64209ea6 100644 --- a/src/main/resources/META-INF/spring/aot.factories +++ b/src/main/resources/META-INF/spring/aot.factories @@ -1,2 +1,2 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\ - org.springframework.data.redis.aot.RedisRuntimeHintsRegistrar + org.springframework.data.redis.aot.RedisRuntimeHints