|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
|
* Copyright 2002-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. |
|
|
|
|
@ -16,8 +16,10 @@
@@ -16,8 +16,10 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.transaction.annotation; |
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.junit.Ignore; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
import org.springframework.aop.support.AopUtils; |
|
|
|
|
@ -34,7 +36,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
@@ -34,7 +36,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.tests.transaction.CallCountingTransactionManager; |
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager; |
|
|
|
|
import org.springframework.transaction.annotation.AnnotationTransactionNamespaceHandlerTests.TransactionalTestBean; |
|
|
|
|
import org.springframework.transaction.config.TransactionManagementConfigUtils; |
|
|
|
|
import org.springframework.transaction.event.TransactionalEventListenerFactory; |
|
|
|
|
|
|
|
|
|
@ -45,6 +46,7 @@ import static org.junit.Assert.*;
@@ -45,6 +46,7 @@ import static org.junit.Assert.*;
|
|
|
|
|
* Tests demonstrating use of @EnableTransactionManagement @Configuration classes. |
|
|
|
|
* |
|
|
|
|
* @author Chris Beams |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Stephane Nicoll |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
* @since 3.1 |
|
|
|
|
@ -132,7 +134,7 @@ public class EnableTransactionManagementTests {
@@ -132,7 +134,7 @@ public class EnableTransactionManagementTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void spr11915() { |
|
|
|
|
public void spr11915TransactionManagerAsManualSingleton() { |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.class); |
|
|
|
|
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class); |
|
|
|
|
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.class); |
|
|
|
|
@ -150,6 +152,52 @@ public class EnableTransactionManagementTests {
@@ -150,6 +152,52 @@ public class EnableTransactionManagementTests {
|
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void spr14322FindsOnInterfaceWithInterfaceProxy() { |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.class); |
|
|
|
|
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class); |
|
|
|
|
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); |
|
|
|
|
|
|
|
|
|
bean.saveFoo(); |
|
|
|
|
assertThat(txManager.begun, equalTo(1)); |
|
|
|
|
assertThat(txManager.commits, equalTo(1)); |
|
|
|
|
assertThat(txManager.rollbacks, equalTo(0)); |
|
|
|
|
|
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test @Ignore // TODO
|
|
|
|
|
public void spr14322FindsOnInterfaceWithCglibProxy() { |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.class); |
|
|
|
|
TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class); |
|
|
|
|
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class); |
|
|
|
|
|
|
|
|
|
bean.saveFoo(); |
|
|
|
|
assertThat(txManager.begun, equalTo(1)); |
|
|
|
|
assertThat(txManager.commits, equalTo(1)); |
|
|
|
|
assertThat(txManager.rollbacks, equalTo(0)); |
|
|
|
|
|
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
public static class TransactionalTestBean { |
|
|
|
|
|
|
|
|
|
@Transactional(readOnly = true) |
|
|
|
|
public Collection<?> findAllFoos() { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Transactional("qualifiedTransactionManager") |
|
|
|
|
public void saveQualifiedFoo() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Transactional(transactionManager = "qualifiedTransactionManager") |
|
|
|
|
public void saveQualifiedFooWithAttributeAlias() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@EnableTransactionManagement |
|
|
|
|
@ -204,6 +252,36 @@ public class EnableTransactionManagementTests {
@@ -204,6 +252,36 @@ public class EnableTransactionManagementTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class TxManagerConfig { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public TransactionalTestBean testBean() { |
|
|
|
|
return new TransactionalTestBean(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public PlatformTransactionManager txManager() { |
|
|
|
|
return new CallCountingTransactionManager(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class MultiTxManagerConfig extends TxManagerConfig implements TransactionManagementConfigurer { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public PlatformTransactionManager txManager2() { |
|
|
|
|
return new CallCountingTransactionManager(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PlatformTransactionManager annotationDrivenTransactionManager() { |
|
|
|
|
return txManager2(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@EnableTransactionManagement |
|
|
|
|
static class Spr11915Config { |
|
|
|
|
@ -221,12 +299,29 @@ public class EnableTransactionManagementTests {
@@ -221,12 +299,29 @@ public class EnableTransactionManagementTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface TransactionalTestInterface { |
|
|
|
|
|
|
|
|
|
@Transactional |
|
|
|
|
void saveFoo(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
public static class TransactionalTestService implements TransactionalTestInterface { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void saveFoo() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class TxManagerConfig { |
|
|
|
|
@EnableTransactionManagement |
|
|
|
|
static class Spr14322ConfigA { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public TransactionalTestBean testBean() { |
|
|
|
|
return new TransactionalTestBean(); |
|
|
|
|
public TransactionalTestInterface testBean() { |
|
|
|
|
return new TransactionalTestService(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
@ -237,16 +332,17 @@ public class EnableTransactionManagementTests {
@@ -237,16 +332,17 @@ public class EnableTransactionManagementTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class MultiTxManagerConfig extends TxManagerConfig implements TransactionManagementConfigurer { |
|
|
|
|
@EnableTransactionManagement(proxyTargetClass = true) |
|
|
|
|
static class Spr14322ConfigB { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
public PlatformTransactionManager txManager2() { |
|
|
|
|
return new CallCountingTransactionManager(); |
|
|
|
|
public TransactionalTestInterface testBean() { |
|
|
|
|
return new TransactionalTestService(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PlatformTransactionManager annotationDrivenTransactionManager() { |
|
|
|
|
return txManager2(); |
|
|
|
|
@Bean |
|
|
|
|
public PlatformTransactionManager txManager() { |
|
|
|
|
return new CallCountingTransactionManager(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|