|
|
|
@ -126,10 +126,10 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static List<ResolvableType> resolveDeclaredEventTypes(Method method, @Nullable EventListener ann) { |
|
|
|
private static List<ResolvableType> resolveDeclaredEventTypes(Method method, @Nullable EventListener ann) { |
|
|
|
int count = (KotlinDetector.isSuspendingFunction(method) ? method.getParameterCount() - 1 : method.getParameterCount()); |
|
|
|
int count = (KotlinDetector.isSuspendingFunction(method) ? method.getParameterCount() - 1 : |
|
|
|
|
|
|
|
method.getParameterCount()); |
|
|
|
if (count > 1) { |
|
|
|
if (count > 1) { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException("Maximum one parameter is allowed for event listener method: " + method); |
|
|
|
"Maximum one parameter is allowed for event listener method: " + method); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ann != null) { |
|
|
|
if (ann != null) { |
|
|
|
@ -156,6 +156,35 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the target listener method. |
|
|
|
|
|
|
|
* @since 7.0.7 in public form (with protected visibility since 5.3) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public final Method getTargetMethod() { |
|
|
|
|
|
|
|
return this.targetMethod; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the condition to use. |
|
|
|
|
|
|
|
* <p>Matches the {@code condition} attribute of the {@link EventListener} |
|
|
|
|
|
|
|
* annotation or any matching attribute on a composed annotation that |
|
|
|
|
|
|
|
* is meta-annotated with {@code @EventListener}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected final @Nullable String getCondition() { |
|
|
|
|
|
|
|
return this.condition; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return whether default execution is applicable for the target listener. |
|
|
|
|
|
|
|
* @since 6.2 |
|
|
|
|
|
|
|
* @see #onApplicationEvent |
|
|
|
|
|
|
|
* @see EventListener#defaultExecution() |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected final boolean isDefaultExecution() { |
|
|
|
|
|
|
|
return this.defaultExecution; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initialize this instance. |
|
|
|
* Initialize this instance. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -167,7 +196,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
public void onApplicationEvent(ApplicationEvent event) { |
|
|
|
if (isDefaultExecution()) { |
|
|
|
if (this.defaultExecution) { |
|
|
|
processEvent(event); |
|
|
|
processEvent(event); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -222,22 +251,11 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
* @see #getListenerId() |
|
|
|
* @see #getListenerId() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getDefaultListenerId() { |
|
|
|
protected String getDefaultListenerId() { |
|
|
|
Method method = getTargetMethod(); |
|
|
|
|
|
|
|
StringJoiner sj = new StringJoiner(",", "(", ")"); |
|
|
|
StringJoiner sj = new StringJoiner(",", "(", ")"); |
|
|
|
for (Class<?> paramType : method.getParameterTypes()) { |
|
|
|
for (Class<?> paramType : this.targetMethod.getParameterTypes()) { |
|
|
|
sj.add(paramType.getName()); |
|
|
|
sj.add(paramType.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return ClassUtils.getQualifiedMethodName(method) + sj; |
|
|
|
return ClassUtils.getQualifiedMethodName(this.targetMethod) + sj; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return whether default execution is applicable for the target listener. |
|
|
|
|
|
|
|
* @since 6.2 |
|
|
|
|
|
|
|
* @see #onApplicationEvent |
|
|
|
|
|
|
|
* @see EventListener#defaultExecution() |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected boolean isDefaultExecution() { |
|
|
|
|
|
|
|
return this.defaultExecution; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -274,11 +292,10 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
if (args == null) { |
|
|
|
if (args == null) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
String condition = getCondition(); |
|
|
|
if (StringUtils.hasText(this.condition)) { |
|
|
|
if (StringUtils.hasText(condition)) { |
|
|
|
|
|
|
|
Assert.notNull(this.evaluator, "EventExpressionEvaluator must not be null"); |
|
|
|
Assert.notNull(this.evaluator, "EventExpressionEvaluator must not be null"); |
|
|
|
return this.evaluator.condition( |
|
|
|
return this.evaluator.condition( |
|
|
|
condition, event, this.targetMethod, this.methodKey, args); |
|
|
|
this.condition, event, this.targetMethod, this.methodKey, args); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -402,24 +419,6 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
return this.applicationContext.getBean(this.beanName); |
|
|
|
return this.applicationContext.getBean(this.beanName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the target listener method. |
|
|
|
|
|
|
|
* @since 5.3 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected Method getTargetMethod() { |
|
|
|
|
|
|
|
return this.targetMethod; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the condition to use. |
|
|
|
|
|
|
|
* <p>Matches the {@code condition} attribute of the {@link EventListener} |
|
|
|
|
|
|
|
* annotation or any matching attribute on a composed annotation that |
|
|
|
|
|
|
|
* is meta-annotated with {@code @EventListener}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
protected @Nullable String getCondition() { |
|
|
|
|
|
|
|
return this.condition; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Add additional details such as the bean type and method signature to |
|
|
|
* Add additional details such as the bean type and method signature to |
|
|
|
* the given error message. |
|
|
|
* the given error message. |
|
|
|
@ -427,7 +426,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected String getDetailedErrorMessage(Object bean, @Nullable String message) { |
|
|
|
protected String getDetailedErrorMessage(Object bean, @Nullable String message) { |
|
|
|
StringBuilder sb = (StringUtils.hasLength(message) ? new StringBuilder(message).append('\n') : new StringBuilder()); |
|
|
|
StringBuilder sb = (StringUtils.hasLength(message) ? new StringBuilder(message).append('\n') : new StringBuilder()); |
|
|
|
sb.append("HandlerMethod details: \n"); |
|
|
|
sb.append("ApplicationListenerMethodAdapter details: \n"); |
|
|
|
sb.append("Bean [").append(bean.getClass().getName()).append("]\n"); |
|
|
|
sb.append("Bean [").append(bean.getClass().getName()).append("]\n"); |
|
|
|
sb.append("Method [").append(this.method.toGenericString()).append("]\n"); |
|
|
|
sb.append("Method [").append(this.method.toGenericString()).append("]\n"); |
|
|
|
return sb.toString(); |
|
|
|
return sb.toString(); |
|
|
|
|