001/*
002 * Copyright 2002-2020 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.transaction.aspectj;
018
019import org.springframework.beans.factory.config.BeanDefinition;
020import org.springframework.context.annotation.Bean;
021import org.springframework.context.annotation.Configuration;
022import org.springframework.context.annotation.Role;
023import org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration;
024import org.springframework.transaction.annotation.EnableTransactionManagement;
025import org.springframework.transaction.annotation.TransactionManagementConfigurationSelector;
026import org.springframework.transaction.config.TransactionManagementConfigUtils;
027
028/**
029 * {@code @Configuration} class that registers the Spring infrastructure beans necessary
030 * to enable AspectJ-based annotation-driven transaction management for Spring's own
031 * {@link org.springframework.transaction.annotation.Transactional} annotation.
032 *
033 * @author Chris Beams
034 * @author Juergen Hoeller
035 * @since 3.1
036 * @see EnableTransactionManagement
037 * @see TransactionManagementConfigurationSelector
038 * @see AspectJJtaTransactionManagementConfiguration
039 */
040@Configuration
041@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
042public class AspectJTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
043
044        @Bean(name = TransactionManagementConfigUtils.TRANSACTION_ASPECT_BEAN_NAME)
045        @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
046        public AnnotationTransactionAspect transactionAspect() {
047                AnnotationTransactionAspect txAspect = AnnotationTransactionAspect.aspectOf();
048                if (this.txManager != null) {
049                        txAspect.setTransactionManager(this.txManager);
050                }
051                return txAspect;
052        }
053
054}