Skip to content

Commit 0387d54

Browse files
committed
Add support for Transactional in native-image
This commit annotates @transactional with @Reflective and registers proxy hints for SpringProxy. Injection of proxied beans via their interfaces still fails in native images with a "No qualifying bean of type MyInterface" error. See gh-28717
1 parent cdf01ed commit 0387d54

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2002-2012 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.aop;
18+
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.core.DecoratingProxy;
23+
24+
/**
25+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
26+
* AOP proxies.
27+
*
28+
* @author Sebastien Deleuze
29+
* @since 6.0
30+
*/
31+
public class SpringProxyRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
32+
33+
@Override
34+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
35+
hints.proxies().registerJdkProxy(SpringProxy.class, Advised.class, DecoratingProxy.class);
36+
}
37+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
22
org.springframework.aop.scope.ScopedProxyBeanRegistrationAotProcessor
3+
org.springframework.aot.hint.RuntimeHintsRegistrar=\
4+
org.springframework.aop.SpringProxyRuntimeHintsRegistrar

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import org.springframework.aot.hint.annotation.Reflective;
2627
import org.springframework.core.annotation.AliasFor;
2728
import org.springframework.transaction.TransactionDefinition;
2829

@@ -117,6 +118,7 @@
117118
@Retention(RetentionPolicy.RUNTIME)
118119
@Inherited
119120
@Documented
121+
@Reflective
120122
public @interface Transactional {
121123

122124
/**

0 commit comments

Comments
 (0)