You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
now when i run this war as a standalone application i am unable to connect to the websocket, when i deploy this war to a standalone tomcat connection can be successfull established. there seems to be something missing in the embedded configuration when using websockets in standalone mode
The text was updated successfully, but these errors were encountered:
Tomcat uses a ServletContainerInitializer to find classes annotated with @ServerEndpoint. Spring Boot doesn't support ServerContainerInitializerswhen you're using an embedded web container (see #321 for more details).
You need to make all of your endpoints Spring beans and use Spring's ServerEndpointExporter instead. Unfortunately, there's a bug that stops the exporter from working out-of-the-box with Spring Boot. There's a workaround, however. Add the following bean to Application:
@Bean
public ServletContextAware endpointExporterInitializer(final ApplicationContext applicationContext) {
return new ServletContextAware() {
@Override
public void setServletContext(ServletContext servletContext) {
ServerEndpointExporter exporter = new ServerEndpointExporter();
exporter.setApplicationContext(applicationContext);
exporter.afterPropertiesSet();
}
};
}
I've now realised that the workaround is only viable as long as you're not trying to use ServerEndpointConfig beans. ServerEndpointExporter needs to be exposed as a Bean in the application context for that to work as they're processed as part of ServerEndpointExporter's implementation of the BeanPostProcessor contract
I have an application defined this way:
and a ServerEndpoint:
pom.xml:
now when i run this war as a standalone application i am unable to connect to the websocket, when i deploy this war to a standalone tomcat connection can be successfull established. there seems to be something missing in the embedded configuration when using websockets in standalone mode
The text was updated successfully, but these errors were encountered: