Resolved cyclic dependency between handler.invocation and handler.annotation
Issue: SPR-12696
This commit is contained in:
parent
e83d495cbb
commit
49c600b234
|
@ -41,7 +41,6 @@ import org.springframework.messaging.handler.DestinationPatternsMessageCondition
|
|||
import org.springframework.messaging.handler.HandlerMethod;
|
||||
import org.springframework.messaging.handler.HandlerMethodSelector;
|
||||
import org.springframework.messaging.handler.MessagingAdviceBean;
|
||||
import org.springframework.messaging.handler.annotation.support.AnnotationExceptionHandlerMethodResolver;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
@ -333,18 +332,8 @@ public abstract class AbstractMethodMessageHandler<T>
|
|||
* (e.g. to support "global" {@code @MessageExceptionHandler}).
|
||||
* @since 4.2
|
||||
*/
|
||||
protected void initMessagingAdviceCache(List<MessagingAdviceBean> beans) {
|
||||
if (beans == null) {
|
||||
return;
|
||||
}
|
||||
for (MessagingAdviceBean bean : beans) {
|
||||
Class<?> beanType = bean.getBeanType();
|
||||
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(beanType);
|
||||
if (resolver.hasExceptionMappings()) {
|
||||
this.exceptionHandlerAdviceCache.put(bean, resolver);
|
||||
logger.info("Detected @MessageExceptionHandler methods in " + bean);
|
||||
}
|
||||
}
|
||||
protected void registerExceptionHandlerAdvice(MessagingAdviceBean bean, AbstractExceptionHandlerMethodResolver resolver) {
|
||||
this.exceptionHandlerAdviceCache.put(bean, resolver);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket.messaging;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -22,6 +23,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
|||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.handler.MessagingAdviceBean;
|
||||
import org.springframework.messaging.handler.annotation.support.AnnotationExceptionHandlerMethodResolver;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
import org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler;
|
||||
import org.springframework.web.method.ControllerAdviceBean;
|
||||
|
@ -36,7 +38,6 @@ import org.springframework.web.method.ControllerAdviceBean;
|
|||
*/
|
||||
public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMethodMessageHandler {
|
||||
|
||||
|
||||
public WebSocketAnnotationMethodMessageHandler(SubscribableChannel clientInChannel, MessageChannel clientOutChannel,
|
||||
SimpMessageSendingOperations brokerTemplate) {
|
||||
|
||||
|
@ -62,6 +63,20 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
|
|||
initMessagingAdviceCache(MessagingControllerAdviceBean.createFromList(controllerAdvice));
|
||||
}
|
||||
|
||||
private void initMessagingAdviceCache(List<MessagingAdviceBean> beans) {
|
||||
if (beans == null) {
|
||||
return;
|
||||
}
|
||||
for (MessagingAdviceBean bean : beans) {
|
||||
Class<?> beanType = bean.getBeanType();
|
||||
AnnotationExceptionHandlerMethodResolver resolver = new AnnotationExceptionHandlerMethodResolver(beanType);
|
||||
if (resolver.hasExceptionMappings()) {
|
||||
registerExceptionHandlerAdvice(bean, resolver);
|
||||
logger.info("Detected @MessageExceptionHandler methods in " + bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adapt ControllerAdviceBean to MessagingAdviceBean.
|
||||
|
@ -70,7 +85,6 @@ public class WebSocketAnnotationMethodMessageHandler extends SimpAnnotationMetho
|
|||
|
||||
private final ControllerAdviceBean adviceBean;
|
||||
|
||||
|
||||
private MessagingControllerAdviceBean(ControllerAdviceBean adviceBean) {
|
||||
this.adviceBean = adviceBean;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue