中的IllegalArgumentException

中的IllegalArgumentException

本文介绍了Spring引导websocket 1.2.1.RELEASE - bean'subProtocolWebSocketHandler'中的IllegalArgumentException:无处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我希望将我的项目从spring boot 1.1.9.RELEASE升级到1.2.1.RELEASE。

So I'm looking to upgrade my projects from spring boot 1.1.9.RELEASE to 1.2.1.RELEASE.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>

然而,在启动时,我获得了:

However, on startup, I gained:

Exception in thread "Thread-0" org.springframework.context.ApplicationContextException: Failed to start bean 'subProtocolWebSocketHandler'; nested exception is java.lang.IllegalArgumentException: No handlers
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:770)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
        at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:95)
        at com.springagain.Application.run(Application.java:17)
Caused by: java.lang.IllegalArgumentException: No handlers
        at org.springframework.util.Assert.isTrue(Assert.java:65)
        at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:234)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        ... 8 more

以下是我的websocket配置的外观

Here's how my websocket configuration looks

@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfiguration extends
        AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/queue/", "/topic/");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // TODO Auto-generated method stub

    }

}

切换回1.1.9.RELEASE只有spring-boot -starter-websocket依赖(并将所有其他spring引导依赖关系保持在1.2.1.RELEASE,spring core保持在4.1.4),异常消失。

Switching back to 1.1.9.RELEASE of only the spring-boot-starter-websocket dependency (and keeping all other spring boot dependencies at 1.2.1.RELEASE and spring core at 4.1.4), the exception disappears.

看起来像一个但有人可以确认吗?

Looks like a bug but can someone confirm?

UPDATE :更多上下文 - 这是来自后端服务器代码 - 没有websocket客户端连接到它。意图是通过RabbitMQ发布有趣事件,然后从暴露websocket端点的前端服务器向客户端提供这些事件。我的前端服务器上的代码添加了Socksjs支持端点:

UPDATE: More context - this is from a backend server code - no websocket clients connect to it. Intention is to publish 'interesting' events over RabbitMQ, which are then available to clients from front end servers that expose a websocket endpoint. Code on my front end servers add the endpoint with Socksjs support:

public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/push").withSockJS();
}

从这个角度来看,要么我的理解存在根本缺陷:),或者Spring在检查应该总是有一个websocket端点时变得过于热心。

From that standpoint, either my understanding is fundamentally flawed :), OR Spring has become overzealous in checking that there should be a websocket endpoint always.

推荐答案

问题的根源是你还没有配置 registerStompEndpoints 中的任何端点。尝试使用STOMP但尚未配置任何STOMP端点的应用程序将无法正常工作。

The root of the problem is that you haven't configured any endpoints in registerStompEndpoints. An application that's trying to use STOMP, but has not configured any STOMP endpoints, won't work correctly.

当您使用Spring Boot 1.1.9.RELEASE时你的类路径上会有一些Spring Framework 4.0.x jar。 Spring Framework 4.0.x的WebSocket支持不会注意到错误配置,并允许您的应用程序启动,即使它不起作用。 Spring Framework 4.1的WebSocket支持会注意到这种错误配置并引发异常,从而提醒您注意该问题。

When you're using Spring Boot 1.1.9.RELEASE you'll have some Spring Framework 4.0.x jars on your classpath. Spring Framework 4.0.x's WebSocket support doesn't notice the misconfiguration and allows your app to start even though it won't work. Spring Framework 4.1's WebSocket support notices this misconfiguration and throws an exception, thereby alerting you to the problem.

这篇关于Spring引导websocket 1.2.1.RELEASE - bean'subProtocolWebSocketHandler'中的IllegalArgumentException:无处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 09:36