Skip to content

Commit 50240bb

Browse files
committed
Add runtime hints for tx management
Closes gh-28688
1 parent 729c4e5 commit 50240bb

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

spring-tx/src/main/java/org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.beans.factory.config.BeanDefinition;
2020
import org.springframework.context.annotation.Bean;
2121
import org.springframework.context.annotation.Configuration;
22+
import org.springframework.context.annotation.ImportRuntimeHints;
2223
import org.springframework.context.annotation.Role;
2324
import org.springframework.transaction.config.TransactionManagementConfigUtils;
2425
import org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor;
@@ -37,6 +38,7 @@
3738
*/
3839
@Configuration(proxyBeanMethods = false)
3940
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
41+
@ImportRuntimeHints(TransactionRuntimeHintsRegistrar.class)
4042
public class ProxyTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
4143

4244
@Bean(name = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2002-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+
17+
package org.springframework.transaction.annotation;
18+
19+
import org.springframework.aot.hint.MemberCategory;
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.aot.hint.support.RuntimeHintsUtils;
24+
25+
import static java.util.Arrays.asList;
26+
27+
/**
28+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
29+
* transaction management.
30+
*
31+
* @author Sebastien Deleuze
32+
* @since 6.0
33+
*/
34+
public class TransactionRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
35+
36+
@Override
37+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
38+
RuntimeHintsUtils.registerAnnotation(hints, org.springframework.transaction.annotation.Transactional.class);
39+
40+
hints.reflection()
41+
.registerTypes(asList(
42+
TypeReference.of(org.springframework.transaction.annotation.Isolation.class),
43+
TypeReference.of(org.springframework.transaction.annotation.Propagation.class),
44+
TypeReference.of(org.springframework.transaction.TransactionDefinition.class)),
45+
builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS));
46+
}
47+
}

0 commit comments

Comments
 (0)