Spring Boot Websockets in Wildfly
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Spring Boot WebSocket support can run on WildFly, but the deployment model is different from the usual embedded-server setup. When deploying to WildFly, you typically package the application as a WAR, let WildFly provide the servlet container, and make sure your WebSocket configuration fits that external-container model.
Use a WAR Instead of the Usual Executable JAR
For WildFly deployment, the application is commonly packaged as a WAR.
Your main application class should extend SpringBootServletInitializer.
This lets the app run as a WAR in WildFly while still being launchable in development if needed.
Dependency Setup Matters
When deploying to WildFly, the embedded Tomcat starter should not be packaged as a normal runtime dependency.
In Maven, that usually means marking it as provided.
That prevents conflicts between the embedded container and WildFly's container services.
A Simple WebSocket Configuration
For Spring's STOMP-based messaging support, a standard configuration looks like this:
This works the same conceptually whether the app runs with embedded Boot or inside WildFly.
Deploying to WildFly
Package the application and copy the WAR to WildFly's deployment directory.
Then verify startup logs and confirm the WebSocket endpoint is exposed under the deployed application context path.
Watch for Container Conflicts
WildFly already provides Java EE or Jakarta EE infrastructure. Spring Boot can live inside that environment, but conflicts can appear if you accidentally package embedded-container pieces or rely on incompatible servlet APIs.
The safest approach is:
- package as WAR
- use container-provided servlet runtime
- keep dependency versions aligned with the target platform
Testing the Endpoint
A minimal JavaScript client can verify connectivity.
Adjust the path to match your actual deployment context and endpoint mapping.
Security and Proxy Considerations
If WildFly sits behind a reverse proxy or load balancer, make sure WebSocket upgrade headers are forwarded correctly. A perfectly valid Spring configuration can still fail if the proxy strips or mishandles the upgrade request.
That means deployment debugging sometimes belongs at the HTTP or infrastructure layer, not only inside Spring Boot or WildFly itself.
Common Pitfalls
A common mistake is deploying a default Boot executable JAR to WildFly expectations. For WildFly, WAR packaging is usually the right model.
Another mistake is leaving the embedded Tomcat dependency as a normal runtime dependency, which can create classpath or container conflicts.
Developers also often forget that the WebSocket URL includes the deployed application context path, not just the endpoint path from the Spring config.
Summary
- Spring Boot WebSockets can run in WildFly, but the app is usually packaged as a WAR.
- Extend
SpringBootServletInitializerfor external-container deployment. - Mark embedded Tomcat as
providedwhen deploying to WildFly. - Configure WebSocket endpoints normally through Spring.
- Check deployment context paths and container classpath conflicts when debugging.
Related reading
- Spring Boot with Apache Tiles
- Spring Boot with embedded Tomcat behind Apache proxy
- Spring Boot with Kotlin - Value annotation not working as expected
- Spring Boot with redirecting with single page angular2
- Spring boot with RefreshScope PostConstruct PreDestroy
- spring boot with spring security Error creating bean with name 'securityFilterChainRegistration
- Spring Boot without the web server
- Spring Boot YAML configuration for a list of strings

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.