Skip to content

Commit 5821272

Browse files
Guard optional runtime hints.
This commit adds a guard to types that must not be present at AOT build time. See: #2497
1 parent 9c75766 commit 5821272

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/aot/DataJpaRuntimeHints.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import org.springframework.aot.hint.RuntimeHints;
2222
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2323
import org.springframework.aot.hint.TypeReference;
24-
import org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect;
2524
import org.springframework.data.jpa.domain.support.AuditingBeanFactoryPostProcessor;
2625
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
2726
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
2827
import org.springframework.lang.Nullable;
28+
import org.springframework.util.ClassUtils;
2929

3030
/**
3131
* @author Christoph Strobl
@@ -36,14 +36,24 @@ public class DataJpaRuntimeHints implements RuntimeHintsRegistrar {
3636
@Override
3737
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3838

39-
hints.proxies().registerJdkProxy(org.springframework.data.jpa.repository.support.CrudMethodMetadata.class,
40-
org.springframework.aop.SpringProxy.class, org.springframework.aop.framework.Advised.class,
39+
hints.proxies().registerJdkProxy(org.springframework.data.jpa.repository.support.CrudMethodMetadata.class, //
40+
org.springframework.aop.SpringProxy.class, //
41+
org.springframework.aop.framework.Advised.class, //
4142
org.springframework.core.DecoratingProxy.class);
42-
hints.reflection().registerTypes(
43-
Arrays.asList(TypeReference.of(AnnotationBeanConfigurerAspect.class),
44-
TypeReference.of(AuditingBeanFactoryPostProcessor.class), TypeReference.of(AuditingEntityListener.class)),
43+
44+
if (ClassUtils.isPresent("org.springframework.beans.factory.aspectj.ConfigurableObject", classLoader)) {
45+
46+
hints.reflection().registerType(
47+
TypeReference.of("org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"), hint -> hint
48+
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS));
49+
}
50+
51+
hints.reflection().registerTypes(Arrays.asList( //
52+
TypeReference.of(AuditingBeanFactoryPostProcessor.class), //
53+
TypeReference.of(AuditingEntityListener.class)),
4554
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS));
46-
hints.reflection().registerTypes(Arrays.asList(TypeReference.of(SimpleJpaRepository.class)),
55+
56+
hints.reflection().registerType(TypeReference.of(SimpleJpaRepository.class),
4757
hint -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS));
4858
}
4959
}

0 commit comments

Comments
 (0)