Browse Source

DATACMNS-880 - TransactionalRepositoryFactoryBeanSupport.setBeanFactory(…) now delegates to parent implementation.

Previously TransactionalRepositoryFactoryBeanSupport.setBeanFactory(…) didn't invoke the method of the super class preventing the BeanFactory to be propagated to the repository factory resulting in the ProjectionFactory implementation created being unaware of the BeanFactory and thus no bean references being available in projection interfaces.
pull/171/head
Oliver Gierke 10 years ago
parent
commit
f53795d48e
  1. 4
      src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java
  2. 20
      src/test/java/org/springframework/data/repository/core/support/TransactionRepositoryFactoryBeanSupportUnitTests.java

4
src/main/java/org/springframework/data/repository/core/support/TransactionalRepositoryFactoryBeanSupport.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2008-2015 the original author or authors.
* Copyright 2008-2016 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.
@ -91,6 +91,8 @@ public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Reposi @@ -91,6 +91,8 @@ public abstract class TransactionalRepositoryFactoryBeanSupport<T extends Reposi
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory);
super.setBeanFactory(beanFactory);
ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;
this.txPostProcessor = new TransactionalRepositoryProxyPostProcessor(listableBeanFactory, transactionManagerName,
enableDefaultTransactions);

20
src/test/java/org/springframework/data/repository/core/support/TransactionRepositoryFactoryBeanSupportUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2015-2016 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.
@ -25,6 +25,7 @@ import org.springframework.aop.Advisor; @@ -25,6 +25,7 @@ import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.data.repository.CrudRepository;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.interceptor.TransactionInterceptor;
/**
@ -67,9 +68,22 @@ public class TransactionRepositoryFactoryBeanSupportUnitTests { @@ -67,9 +68,22 @@ public class TransactionRepositoryFactoryBeanSupportUnitTests {
assertThat(found, is(true));
}
/**
* @see DATACMNS-880
*/
@Test
public void propagatesBeanFactoryToSuperClass() {
SampleTransactionalRepositoryFactoryBean factoryBean = new SampleTransactionalRepositoryFactoryBean();
factoryBean.setBeanFactory(new DefaultListableBeanFactory());
assertThat(ReflectionTestUtils.getField(factoryBean, RepositoryFactoryBeanSupport.class, "beanFactory"),
is(notNullValue()));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
static class SampleTransactionalRepositoryFactoryBean extends
TransactionalRepositoryFactoryBeanSupport<CrudRepository<Object, Long>, Object, Long> {
static class SampleTransactionalRepositoryFactoryBean
extends TransactionalRepositoryFactoryBeanSupport<CrudRepository<Object, Long>, Object, Long> {
private final CrudRepository<Object, Long> repository = mock(CrudRepository.class);

Loading…
Cancel
Save