From d8a6954744e31c1eaa817b401225822294aba504 Mon Sep 17 00:00:00 2001 From: Gytis Trikleris Date: Tue, 11 Jul 2017 14:59:27 +0200 Subject: [PATCH 1/2] Make NarayanaRecoveryManagerBean conditional on missing bean See gh-9724 --- .../autoconfigure/transaction/jta/NarayanaJtaConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java index da219ffc333..12d4b57040c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java @@ -119,6 +119,7 @@ public class NarayanaJtaConfiguration { } @Bean + @ConditionalOnMissingBean public NarayanaRecoveryManagerBean narayanaRecoveryManager( RecoveryManagerService recoveryManagerService) { return new NarayanaRecoveryManagerBean(recoveryManagerService); From bb35e772c27a66d1c6a00e12745fbba64d434900 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 24 Jul 2017 11:16:21 +0100 Subject: [PATCH 2/2] Polish "Make NarayanaRecoveryManagerBean conditional on missing bean" Closes gh-9724 --- .../jta/NarayanaJtaConfiguration.java | 2 +- .../jta/JtaAutoConfigurationTests.java | 35 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java index 12d4b57040c..89b7ba3b86b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/NarayanaJtaConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java index e057ce8917b..e1d0027a322 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/transaction/jta/JtaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -44,6 +44,7 @@ import org.junit.rules.ExpectedException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; +import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfigurationTests.CustomNarayanaRecoveryManagerConfiguration.CustomNarayanaRecoveryManagerBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jta.XAConnectionFactoryWrapper; import org.springframework.boot.jta.XADataSourceWrapper; @@ -55,6 +56,7 @@ import org.springframework.boot.jta.bitronix.PoolingConnectionFactoryBean; import org.springframework.boot.jta.bitronix.PoolingDataSourceBean; import org.springframework.boot.jta.narayana.NarayanaBeanFactoryPostProcessor; import org.springframework.boot.jta.narayana.NarayanaConfigurationBean; +import org.springframework.boot.jta.narayana.NarayanaRecoveryManagerBean; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -294,6 +296,16 @@ public class JtaAutoConfigurationTests { assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); } + @Test + public void narayanaRecoveryManagerBeanCanBeCustomized() { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(CustomNarayanaRecoveryManagerConfiguration.class, + JtaProperties.class, NarayanaJtaConfiguration.class); + this.context.refresh(); + assertThat(this.context.getBean(NarayanaRecoveryManagerBean.class)) + .isInstanceOf(CustomNarayanaRecoveryManagerBean.class); + } + @Configuration @EnableConfigurationProperties(JtaProperties.class) public static class JtaPropertiesConfiguration { @@ -336,4 +348,25 @@ public class JtaAutoConfigurationTests { } + @Configuration + public static class CustomNarayanaRecoveryManagerConfiguration { + + @Bean + public NarayanaRecoveryManagerBean customRecoveryManagerBean( + RecoveryManagerService recoveryManagerService) { + return new CustomNarayanaRecoveryManagerBean(recoveryManagerService); + } + + static final class CustomNarayanaRecoveryManagerBean + extends NarayanaRecoveryManagerBean { + + private CustomNarayanaRecoveryManagerBean( + RecoveryManagerService recoveryManagerService) { + super(recoveryManagerService); + } + + } + + } + }