001/* 002 * Copyright 2002-2017 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.interceptor; 018 019import org.springframework.aop.ClassFilter; 020import org.springframework.aop.Pointcut; 021import org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor; 022import org.springframework.lang.Nullable; 023 024/** 025 * Advisor driven by a {@link TransactionAttributeSource}, used to include 026 * a transaction advice bean for methods that are transactional. 027 * 028 * @author Juergen Hoeller 029 * @since 2.5.5 030 * @see #setAdviceBeanName 031 * @see TransactionInterceptor 032 * @see TransactionAttributeSourceAdvisor 033 */ 034@SuppressWarnings("serial") 035public class BeanFactoryTransactionAttributeSourceAdvisor extends AbstractBeanFactoryPointcutAdvisor { 036 037 @Nullable 038 private TransactionAttributeSource transactionAttributeSource; 039 040 private final TransactionAttributeSourcePointcut pointcut = new TransactionAttributeSourcePointcut() { 041 @Override 042 @Nullable 043 protected TransactionAttributeSource getTransactionAttributeSource() { 044 return transactionAttributeSource; 045 } 046 }; 047 048 049 /** 050 * Set the transaction attribute source which is used to find transaction 051 * attributes. This should usually be identical to the source reference 052 * set on the transaction interceptor itself. 053 * @see TransactionInterceptor#setTransactionAttributeSource 054 */ 055 public void setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource) { 056 this.transactionAttributeSource = transactionAttributeSource; 057 } 058 059 /** 060 * Set the {@link ClassFilter} to use for this pointcut. 061 * Default is {@link ClassFilter#TRUE}. 062 */ 063 public void setClassFilter(ClassFilter classFilter) { 064 this.pointcut.setClassFilter(classFilter); 065 } 066 067 @Override 068 public Pointcut getPointcut() { 069 return this.pointcut; 070 } 071 072}