[FIXED] Keep Spring Boot application alive with websocket connection


My Spring Boot application is quite small and has one job: Act as a client by opening a websocket connection to a third-party website and listen for messages.

The problem is that after my javax.websocket.Endpoint implementation has been initialised and the connection has been created, my Spring boot application closes.

I would have thought that any open websocket connection would keep my application up and running?

I don’t need an embedded servlet container so I have specifically set web-environment: false in application.yaml.

Is there a way to remedy this without adding a servlet container I will never use?


I fixed this by using OkHttpClient and initialising it with a @PostConstruct in my @Configuration. I annotated the listener with @Component and it now stays alive without needing the embedded servlet container.

Answered By – wild_nothing

Answer Checked By – Gilberto Lyons (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published