001/* 002 * Copyright 2002-2018 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.event; 018 019import java.lang.reflect.Method; 020 021import org.springframework.context.ApplicationListener; 022import org.springframework.context.event.EventListenerFactory; 023import org.springframework.core.Ordered; 024import org.springframework.core.annotation.AnnotatedElementUtils; 025 026/** 027 * {@link EventListenerFactory} implementation that handles {@link TransactionalEventListener} 028 * annotated methods. 029 * 030 * @author Stephane Nicoll 031 * @since 4.2 032 */ 033public class TransactionalEventListenerFactory implements EventListenerFactory, Ordered { 034 035 private int order = 50; 036 037 038 public void setOrder(int order) { 039 this.order = order; 040 } 041 042 @Override 043 public int getOrder() { 044 return this.order; 045 } 046 047 048 @Override 049 public boolean supportsMethod(Method method) { 050 return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class); 051 } 052 053 @Override 054 public ApplicationListener<?> createApplicationListener(String beanName, Class<?> type, Method method) { 055 return new ApplicationListenerMethodTransactionalAdapter(beanName, type, method); 056 } 057 058}