2626import org .springframework .context .annotation .AdviceMode ;
2727import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
2828import org .springframework .context .annotation .Bean ;
29+ import org .springframework .context .annotation .ConditionContext ;
30+ import org .springframework .context .annotation .Conditional ;
2931import org .springframework .context .annotation .Configuration ;
32+ import org .springframework .context .annotation .ConfigurationCondition ;
33+ import org .springframework .core .type .AnnotatedTypeMetadata ;
3034import org .springframework .stereotype .Service ;
3135import org .springframework .tests .transaction .CallCountingTransactionManager ;
3236import org .springframework .transaction .PlatformTransactionManager ;
@@ -49,7 +53,8 @@ public class EnableTransactionManagementTests {
4953
5054 @ Test
5155 public void transactionProxyIsCreated () {
52- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (EnableTxConfig .class , TxManagerConfig .class );
56+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (
57+ EnableTxConfig .class , TxManagerConfig .class );
5358 TransactionalTestBean bean = ctx .getBean (TransactionalTestBean .class );
5459 assertTrue ("testBean is not a proxy" , AopUtils .isAopProxy (bean ));
5560 Map <?,?> services = ctx .getBeansWithAnnotation (Service .class );
@@ -59,7 +64,19 @@ public void transactionProxyIsCreated() {
5964
6065 @ Test
6166 public void transactionProxyIsCreatedWithEnableOnSuperclass () {
62- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (InheritedEnableTxConfig .class , TxManagerConfig .class );
67+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (
68+ InheritedEnableTxConfig .class , TxManagerConfig .class );
69+ TransactionalTestBean bean = ctx .getBean (TransactionalTestBean .class );
70+ assertTrue ("testBean is not a proxy" , AopUtils .isAopProxy (bean ));
71+ Map <?,?> services = ctx .getBeansWithAnnotation (Service .class );
72+ assertTrue ("Stereotype annotation not visible" , services .containsKey ("testBean" ));
73+ ctx .close ();
74+ }
75+
76+ @ Test
77+ public void transactionProxyIsCreatedWithEnableOnExcludedSuperclass () {
78+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (
79+ ParentEnableTxConfig .class , ChildEnableTxConfig .class , TxManagerConfig .class );
6380 TransactionalTestBean bean = ctx .getBean (TransactionalTestBean .class );
6481 assertTrue ("testBean is not a proxy" , AopUtils .isAopProxy (bean ));
6582 Map <?,?> services = ctx .getBeansWithAnnotation (Service .class );
@@ -69,7 +86,8 @@ public void transactionProxyIsCreatedWithEnableOnSuperclass() {
6986
7087 @ Test
7188 public void txManagerIsResolvedOnInvocationOfTransactionalMethod () {
72- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (EnableTxConfig .class , TxManagerConfig .class );
89+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (
90+ EnableTxConfig .class , TxManagerConfig .class );
7391 TransactionalTestBean bean = ctx .getBean (TransactionalTestBean .class );
7492
7593 // invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
@@ -79,7 +97,8 @@ public void txManagerIsResolvedOnInvocationOfTransactionalMethod() {
7997
8098 @ Test
8199 public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent () {
82- AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (EnableTxConfig .class , MultiTxManagerConfig .class );
100+ AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext (
101+ EnableTxConfig .class , MultiTxManagerConfig .class );
83102 TransactionalTestBean bean = ctx .getBean (TransactionalTestBean .class );
84103
85104 // invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
@@ -95,7 +114,7 @@ public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent() {
95114 @ SuppressWarnings ("resource" )
96115 public void proxyTypeAspectJCausesRegistrationOfAnnotationTransactionAspect () {
97116 try {
98- new AnnotationConfigApplicationContext (EnableAspectJTxConfig .class , TxManagerConfig .class );
117+ new AnnotationConfigApplicationContext (EnableAspectjTxConfig .class , TxManagerConfig .class );
99118 fail ("should have thrown CNFE when trying to load AnnotationTransactionAspect. " +
100119 "Do you actually have org.springframework.aspects on the classpath?" );
101120 }
@@ -137,15 +156,54 @@ public void spr11915() {
137156 static class EnableTxConfig {
138157 }
139158
159+
140160 @ Configuration
141161 static class InheritedEnableTxConfig extends EnableTxConfig {
142162 }
143163
164+
165+ @ Configuration
166+ @ EnableTransactionManagement
167+ @ Conditional (NeverCondition .class )
168+ static class ParentEnableTxConfig {
169+
170+ @ Bean
171+ Object someBean () {
172+ return new Object ();
173+ }
174+ }
175+
176+
177+ @ Configuration
178+ static class ChildEnableTxConfig extends ParentEnableTxConfig {
179+
180+ @ Override
181+ Object someBean () {
182+ return "X" ;
183+ }
184+ }
185+
186+
187+ private static class NeverCondition implements ConfigurationCondition {
188+
189+ @ Override
190+ public boolean matches (ConditionContext context , AnnotatedTypeMetadata metadata ) {
191+ return false ;
192+ }
193+
194+ @ Override
195+ public ConfigurationPhase getConfigurationPhase () {
196+ return ConfigurationPhase .REGISTER_BEAN ;
197+ }
198+ }
199+
200+
144201 @ Configuration
145- @ EnableTransactionManagement (mode = AdviceMode .ASPECTJ )
146- static class EnableAspectJTxConfig {
202+ @ EnableTransactionManagement (mode = AdviceMode .ASPECTJ )
203+ static class EnableAspectjTxConfig {
147204 }
148205
206+
149207 @ Configuration
150208 @ EnableTransactionManagement
151209 static class Spr11915Config {
@@ -162,6 +220,7 @@ public TransactionalTestBean testBean() {
162220 }
163221 }
164222
223+
165224 @ Configuration
166225 static class TxManagerConfig {
167226
@@ -174,9 +233,9 @@ public TransactionalTestBean testBean() {
174233 public PlatformTransactionManager txManager () {
175234 return new CallCountingTransactionManager ();
176235 }
177-
178236 }
179237
238+
180239 @ Configuration
181240 static class MultiTxManagerConfig extends TxManagerConfig implements TransactionManagementConfigurer {
182241
0 commit comments