Skip to content

Commit 175ed04

Browse files
move static hints to aot.hint package
1 parent b09f84d commit 175ed04

File tree

6 files changed

+98
-99
lines changed

6 files changed

+98
-99
lines changed

src/main/java/org/springframework/data/aot/DataAuditingRuntimeHints.java

-38
This file was deleted.

src/main/java/org/springframework/data/aot/DataReactiveAuditingRuntimeHints.java

-38
This file was deleted.

src/main/java/org/springframework/data/aot/PublicMethodReflectiveProcessor.java

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public class PublicMethodReflectiveProcessor extends SimpleReflectiveProcessor {
2626

2727
@Override
2828
protected void registerTypeHint(ReflectionHints hints, Class<?> type) {
29-
System.out.println("invoking reflective hint annotation for : " + type);
3029
hints.registerType(type, builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
31-
3230
}
3331
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2022 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.aot.hint;
17+
18+
import org.springframework.aop.SpringProxy;
19+
import org.springframework.aop.framework.Advised;
20+
import org.springframework.aot.hint.RuntimeHints;
21+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
22+
import org.springframework.aot.hint.TypeReference;
23+
import org.springframework.core.DecoratingProxy;
24+
import org.springframework.data.domain.AuditorAware;
25+
import org.springframework.data.domain.ReactiveAuditorAware;
26+
import org.springframework.lang.Nullable;
27+
28+
/**
29+
* @author Christoph Strobl
30+
* @since 3.0
31+
*/
32+
public class AuditingHints {
33+
34+
/**
35+
* {@link RuntimeHintsRegistrar} to be applied when auditing is enabled. Can be used along with
36+
* {@link org.springframework.context.annotation.ImportRuntimeHints @ImportRuntimeHints} for conditional registration.
37+
*
38+
* @author Christoph Strobl
39+
* @since 3.0
40+
*/
41+
public static class AuditingRuntimeHints implements RuntimeHintsRegistrar {
42+
43+
@Override
44+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
45+
registerSpringProxy(AuditorAware.class, hints);
46+
}
47+
}
48+
49+
/**
50+
* {@link RuntimeHintsRegistrar} to be applied when reactive auditing is enabled. Can be used along with
51+
* {@link org.springframework.context.annotation.ImportRuntimeHints @ImportRuntimeHints} for conditional registration.
52+
*
53+
* @author Christoph Strobl
54+
* @since 3.0
55+
*/
56+
public static class ReactiveAuditingRuntimeHints implements RuntimeHintsRegistrar {
57+
58+
@Override
59+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
60+
registerSpringProxy(ReactiveAuditorAware.class, hints);
61+
}
62+
}
63+
64+
private static void registerSpringProxy(Class<?> type, RuntimeHints runtimeHints) {
65+
66+
runtimeHints.proxies().registerJdkProxy(TypeReference.of(type), TypeReference.of(SpringProxy.class),
67+
TypeReference.of(Advised.class), TypeReference.of(DecoratingProxy.class));
68+
}
69+
}

src/main/java/org/springframework/data/aot/DataRuntimeHints.java renamed to src/main/java/org/springframework/data/aot/hint/RepositoryRuntimeHints.java

+28-20
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.springframework.data.aot;
16+
package org.springframework.data.aot.hint;
1717

1818
import java.util.Arrays;
1919
import java.util.Properties;
2020

21-
import org.springframework.aop.SpringProxy;
22-
import org.springframework.aop.framework.Advised;
2321
import org.springframework.aot.hint.MemberCategory;
2422
import org.springframework.aot.hint.RuntimeHints;
2523
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2624
import org.springframework.aot.hint.TypeReference;
2725
import org.springframework.beans.factory.BeanFactory;
28-
import org.springframework.core.DecoratingProxy;
2926
import org.springframework.core.io.InputStreamSource;
30-
import org.springframework.data.domain.AuditorAware;
3127
import org.springframework.data.mapping.context.MappingContext;
3228
import org.springframework.data.repository.core.RepositoryMetadata;
3329
import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport;
@@ -38,38 +34,50 @@
3834
import org.springframework.lang.Nullable;
3935

4036
/**
37+
* {@link RuntimeHintsRegistrar} holding required hints to bootstrap data repositories. <br />
38+
* Already registered via {@literal aot.factories}.
39+
*
4140
* @author Christoph Strobl
4241
* @since 3.0
4342
*/
44-
public class DataRuntimeHints implements RuntimeHintsRegistrar {
43+
public class RepositoryRuntimeHints implements RuntimeHintsRegistrar {
4544

4645
@Override
4746
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
4847

49-
System.out.println("Spring data Runtime Hints");
48+
// repository infrastructure
49+
hints.reflection().registerTypes(Arrays.asList( //
50+
TypeReference.of(RepositoryFactoryBeanSupport.class), //
51+
TypeReference.of(RepositoryFragmentsFactoryBean.class), //
52+
TypeReference.of(RepositoryFragment.class), //
53+
TypeReference.of(TransactionalRepositoryFactoryBeanSupport.class), //
54+
TypeReference.of(QueryByExampleExecutor.class), //
55+
TypeReference.of(MappingContext.class), //
56+
TypeReference.of(RepositoryMetadata.class) //
57+
), builder -> {
58+
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
59+
});
5060

51-
hints.reflection()
52-
.registerTypes(Arrays.asList(TypeReference.of(RepositoryFactoryBeanSupport.class),
53-
TypeReference.of(RepositoryFragmentsFactoryBean.class), TypeReference.of(RepositoryFragment.class),
54-
TypeReference.of(TransactionalRepositoryFactoryBeanSupport.class),
55-
TypeReference.of(QueryByExampleExecutor.class), TypeReference.of(MappingContext.class),
56-
TypeReference.of(RepositoryMetadata.class)), builder -> {
57-
builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS);
58-
});
59-
hints.reflection().registerTypes(
60-
Arrays.asList(TypeReference.of(Properties.class), TypeReference.of(BeanFactory.class),
61-
TypeReference.of(InputStreamSource[].class)),
62-
builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
61+
// named queries
62+
hints.reflection().registerTypes(Arrays.asList( //
63+
TypeReference.of(Properties.class), //
64+
TypeReference.of(BeanFactory.class), //
65+
TypeReference.of(InputStreamSource[].class) //
66+
), builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_METHODS));
6367

68+
//
6469
hints.reflection().registerType(Throwable.class,
6570
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.DECLARED_FIELDS));
6671

72+
// SpEL support
6773
hints.reflection().registerType(
6874
TypeReference.of("org.springframework.data.projection.SpelEvaluatingMethodInterceptor$TargetWrapper"),
6975
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
7076
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_PUBLIC_METHODS));
7177

72-
hints.proxies().registerJdkProxy(TypeReference.of("org.springframework.data.annotation.QueryAnnotation"),
78+
// annotated queries
79+
hints.proxies().registerJdkProxy( //
80+
TypeReference.of("org.springframework.data.annotation.QueryAnnotation"), //
7381
TypeReference.of("org.springframework.core.annotation.SynthesizedAnnotation"));
7482
}
7583
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\
22
org.springframework.data.aot.SpringDataBeanFactoryInitializationAotProcessor
33
org.springframework.aot.hint.RuntimeHintsRegistrar=\
4-
org.springframework.data.aot.DataRuntimeHints
4+
org.springframework.data.aot.hint.RepositoryRuntimeHints

0 commit comments

Comments
 (0)