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
This commit is contained in:
Sébastien Deleuze 2022-07-07 10:27:39 +02:00
parent cdf01ede8d
commit 0387d54607
3 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/*
* Copyright 2002-2012 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.aop;
import org.springframework.aop.framework.Advised;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.core.DecoratingProxy;
/**
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
* AOP proxies.
*
* @author Sebastien Deleuze
* @since 6.0
*/
public class SpringProxyRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.proxies().registerJdkProxy(SpringProxy.class, Advised.class, DecoratingProxy.class);
}
}

View File

@ -1,2 +1,4 @@
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
org.springframework.aop.scope.ScopedProxyBeanRegistrationAotProcessor
org.springframework.aot.hint.RuntimeHintsRegistrar=\
org.springframework.aop.SpringProxyRuntimeHintsRegistrar

View File

@ -23,6 +23,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.aot.hint.annotation.Reflective;
import org.springframework.core.annotation.AliasFor;
import org.springframework.transaction.TransactionDefinition;
@ -117,6 +118,7 @@ import org.springframework.transaction.TransactionDefinition;
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Reflective
public @interface Transactional {
/**