下面列出了怎么用org.springframework.context.event.ApplicationListenerMethodAdapter的API类实例代码及写法,或者点击链接到github查看源代码。
public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
ApplicationEvent event, TransactionPhase phase) {
this.listener = listener;
this.event = event;
this.phase = phase;
}
public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
ApplicationEvent event, TransactionPhase phase) {
this.listener = listener;
this.event = event;
this.phase = phase;
}
public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
ApplicationEvent event, TransactionPhase phase) {
this.listener = listener;
this.event = event;
this.phase = phase;
}
/**
* Creates a {@link PublicationTargetIdentifier} for the given listener instance.
*
* @param listener
* @return
*/
public static PublicationTargetIdentifier forListener(Object listener) {
return IDENTIFIERS.computeIfAbsent(listener, it -> {
if (it instanceof ApplicationListenerMethodAdapter) {
Method method = (Method) ReflectionUtils.getField(LISTENER_METHOD_FIELD, it);
return PublicationTargetIdentifier.forMethod(method);
}
throw new IllegalStateException("Unsupported listener implementation!");
});
}
public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener,
ApplicationEvent event, TransactionPhase phase) {
this.listener = listener;
this.event = event;
this.phase = phase;
}
private void supportsEventType(boolean match, Method method, ResolvableType eventType) {
ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals("Wrong match for event '" + eventType + "' on " + method,
match, adapter.supportsEventType(eventType));
}
private void supportsEventType(boolean match, Method method, ResolvableType eventType) {
ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals("Wrong match for event '" + eventType + "' on " + method,
match, adapter.supportsEventType(eventType));
}
private void supportsEventType(boolean match, Method method, ResolvableType eventType) {
ApplicationListenerMethodAdapter adapter = createTestInstance(method);
assertEquals("Wrong match for event '" + eventType + "' on " + method,
match, adapter.supportsEventType(eventType));
}
private static boolean isTransactionalApplicationEventListener(ApplicationListener<?> listener) {
Class<?> targetClass = AopUtils.getTargetClass(listener);
return TX_EVENT_LISTENERS.computeIfAbsent(targetClass, it -> {
if (!ApplicationListenerMethodAdapter.class.isAssignableFrom(targetClass)) {
return false;
}
Method method = (Method) ReflectionUtils.getField(LISTENER_METHOD_FIELD, listener);
return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class);
});
}