spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

WebSocket startup fail

Open GZYangKui opened this issue 2 years ago • 3 comments

The following are the configuration details of my project's websocket:

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private TextMessageHandler handler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(handler, "/ws")
                .setAllowedOrigins("*")
                .setHandshakeHandler((a, b,c, d) -> true)
                .addInterceptors(new HandshakeInterceptor());
    }

    @Bean
    public TextMessageHandler textMessageHandler() {
        return new TextMessageHandler();
    }
}

When program run after throw exception:


org.springframework.context.ApplicationContextException: Failed to start bean 'subProtocolWebSocketHandler'
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:170)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:932)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:587)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
	at com.qihao.parking.client.server.Launcher.main(Launcher.java:13)
Caused by: java.lang.IllegalStateException: No handlers
	at org.springframework.util.Assert.state(Assert.java:76)
	at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:271)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
	... 14 common frames omitted


Since our project does not support STOMP, we did not connect to Broker and only implemented the original websocket implementation. I have read online tutorials that all write this way, but I don't know why I made an error writing this way.

SpringBoot:3.0.2 spring-boot-starter-websocket:3.0.5

GZYangKui avatar Apr 27 '23 10:04 GZYangKui

I'm not sure that it would cause the problem, but you shouldn't be mixing Spring Boot 3.0.2 and 3.0.5. From the information you've provided, I can tell that you're writing a servlet-based app, but it's not clear which embedded web server you're using. To make sure that we can see the complete picture, can you please provide a complete yet minimal example that reproduces the IllegalStateException: No handlers failure?

wilkinsona avatar Apr 27 '23 10:04 wilkinsona

Perhaps there is a conflict between other dependencies and the websocket module. I will create a separate springboot project with only one websocket dependency and maintain the same configuration as the current project, so that the program can run normally.

---- Replied Message ---- | From | Andy @.> | | Date | 04/27/2023 18:59 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [spring-projects/spring-boot] WebSocket startup fail (Issue #35182) |

I'm not sure that it would cause the problem, but you shouldn't be mixing Spring Boot 3.0.2 and 3.0.5. From the information you've provided, I can tell that you're writing a servlet-based app, but it's not clear which embedded web server you're using. To make sure that we can see the complete picture, can you please provide a complete yet minimal example that reproduces the IllegalStateException: No handlers failure?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

GZYangKui avatar Apr 28 '23 00:04 GZYangKui

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar May 05 '23 06:05 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar May 12 '23 06:05 spring-projects-issues

@GZYangKui we waiting for you.

SBaori avatar Jan 05 '24 11:01 SBaori