1 /* 2 * Copyright 2002-2011 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.transaction.aspectj; 18 19 import org.springframework.beans.factory.config.BeanDefinition; 20 import org.springframework.context.annotation.Bean; 21 import org.springframework.context.annotation.Configuration; 22 import org.springframework.context.annotation.Role; 23 import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration; 24 import org.springframework.transaction.annotation.EnableTransactionManagement; 25 import org.springframework.transaction.annotation.TransactionManagementConfigurationSelector; 26 import org.springframework.transaction.config.TransactionManagementConfigUtils; 27 28 /** 29 * {@code @Configuration} class that registers the Spring infrastructure beans necessary 30 * to enable AspectJ-based annotation-driven transaction management. 31 * 32 * @author Chris Beams 33 * @since 3.1 34 * @see EnableTransactionManagement 35 * @see TransactionManagementConfigurationSelector 36 */ 37 @Configuration 38 public class AspectJTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration { 39 40 @Bean(name=TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME) 41 @Role(BeanDefinition.ROLE_INFRASTRUCTURE) transactionAspect()42 public AnnotationTransactionAspect transactionAspect() { 43 AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf(); 44 if (this.txManager != null) { 45 txAspect.setTransactionManager(this.txManager); 46 } 47 return txAspect; 48 } 49 } 50