diff --git a/spring-boot-project/spring-boot-autoconfigure/build.gradle b/spring-boot-project/spring-boot-autoconfigure/build.gradle index 3a789899d710..2360f1ba8fb9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-autoconfigure/build.gradle @@ -139,11 +139,12 @@ dependencies { optional("org.opensaml:opensaml-saml-api:4.0.1") optional("org.opensaml:opensaml-saml-impl:4.0.1") optional("org.quartz-scheduler:quartz") - optional("org.springframework:spring-jdbc") optional("org.springframework.integration:spring-integration-core") optional("org.springframework.integration:spring-integration-jdbc") optional("org.springframework.integration:spring-integration-jmx") optional("org.springframework.integration:spring-integration-rsocket") + optional("org.springframework:spring-aspects") + optional("org.springframework:spring-jdbc") optional("org.springframework:spring-jms") optional("org.springframework:spring-orm") optional("org.springframework:spring-tx") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java index 2c605e050a75..d0c7e7910d88 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.autoconfigure.transaction; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.LazyInitializationExcludeFilter; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -31,6 +32,7 @@ import org.springframework.transaction.TransactionManager; import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.aspectj.AbstractTransactionAspect; import org.springframework.transaction.reactive.TransactionalOperator; import org.springframework.transaction.support.TransactionOperations; import org.springframework.transaction.support.TransactionTemplate; @@ -95,4 +97,15 @@ public static class CglibAutoProxyConfiguration { } + @Configuration(proxyBeanMethods = false) + @ConditionalOnBean(AbstractTransactionAspect.class) + static class AspectJTransactionManagementConfiguration { + + @Bean + static LazyInitializationExcludeFilter eagerTransactionAspect() { + return LazyInitializationExcludeFilter.forBeanTypes(AbstractTransactionAspect.class); + } + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfigurationTests.java index 502124eb177a..f8f17332db17 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfigurationTests.java @@ -22,11 +22,15 @@ import org.junit.jupiter.api.Test; +import org.springframework.boot.LazyInitializationExcludeFilter; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener; import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.boot.logging.LogLevel; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.context.annotation.AdviceMode; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -35,6 +39,7 @@ import org.springframework.transaction.ReactiveTransactionManager; import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.aspectj.AbstractTransactionAspect; import org.springframework.transaction.reactive.TransactionalOperator; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionTemplate; @@ -177,6 +182,16 @@ void customEnableTransactionManagementTakesPrecedence() { }); } + @Test + void excludesAbstractTransactionAspectFromLazyInit() { + this.contextRunner.withUserConfiguration(AspectJTransactionManagementConfiguration.class) + .withInitializer(new ConditionEvaluationReportLoggingListener(LogLevel.INFO)) + .run((context) -> { + LazyInitializationExcludeFilter filter = context.getBean(LazyInitializationExcludeFilter.class); + assertThat(filter.isExcluded(null, null, AbstractTransactionAspect.class)).isTrue(); + }); + } + @Configuration static class SinglePlatformTransactionManagerConfiguration { @@ -293,6 +308,12 @@ static class CustomTransactionManagementConfiguration { } + @Configuration(proxyBeanMethods = false) + @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) + static class AspectJTransactionManagementConfiguration { + + } + interface TransactionalService { @Transactional