Merge pull request #9724 from Gytis Trikleris

* gh-9724:
  Polish "Make NarayanaRecoveryManagerBean conditional on missing bean"
  Make NarayanaRecoveryManagerBean conditional on missing bean
pull/9758/merge
Andy Wilkinson 7 years ago
commit 94ea3e8618

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,6 +119,7 @@ public class NarayanaJtaConfiguration {
} }
@Bean @Bean
@ConditionalOnMissingBean
public NarayanaRecoveryManagerBean narayanaRecoveryManager( public NarayanaRecoveryManagerBean narayanaRecoveryManager(
RecoveryManagerService recoveryManagerService) { RecoveryManagerService recoveryManagerService) {
return new NarayanaRecoveryManagerBean(recoveryManagerService); return new NarayanaRecoveryManagerBean(recoveryManagerService);

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; 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.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jta.XAConnectionFactoryWrapper; import org.springframework.boot.jta.XAConnectionFactoryWrapper;
import org.springframework.boot.jta.XADataSourceWrapper; 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.bitronix.PoolingDataSourceBean;
import org.springframework.boot.jta.narayana.NarayanaBeanFactoryPostProcessor; import org.springframework.boot.jta.narayana.NarayanaBeanFactoryPostProcessor;
import org.springframework.boot.jta.narayana.NarayanaConfigurationBean; import org.springframework.boot.jta.narayana.NarayanaConfigurationBean;
import org.springframework.boot.jta.narayana.NarayanaRecoveryManagerBean;
import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -294,6 +296,16 @@ public class JtaAutoConfigurationTests {
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue(); 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 @Configuration
@EnableConfigurationProperties(JtaProperties.class) @EnableConfigurationProperties(JtaProperties.class)
public static class JtaPropertiesConfiguration { 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);
}
}
}
} }

Loading…
Cancel
Save