title: Spring WebSocket Simple Example - java.lang.IllegalStateException: Unexpected use of scheduler
body: <p>I'm trying to implement a WebSocket server in Spring without STOMP, following this article: <a href="http://www.devglan.com/spring-boot/spring-websocket-integration-example-without-stomp" rel="nofollow noreferrer">http://www.devglan.com/spring-boot/spring-websocket-integration-example-without-stomp</a></p>
  
  <p>WebSocketConfig.java</p>
  
  <pre><code>@Configuration
  @EnableWebSocket
  public class WebSocketConfig implements WebSocketConfigurer {
  
      @Autowired private WebSocketHandler webSocketHandler;
  
      @Override
      public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
          registry.addHandler(webSocketHandler, "/app");
      }
  
  }
  </code></pre>
  
  <p>WebSocketHandler</p>
  
  <pre><code>@Component
  public class WebSocketHandler extends TextWebSocketHandler {
  
      private List&lt;WebSocketSession&gt; sessions = new CopyOnWriteArrayList&lt;&gt;();
  
      @Override
      public void afterConnectionEstablished(WebSocketSession session) {
          sessions.add(session);
      }
  
      @Override
      protected void handleTextMessage(WebSocketSession session, TextMessage message) throws IOException {
          // ...
      }
  
  }
  </code></pre>
  
  <p>However, I get this exception at startup:</p>
  
  <pre><code>java.lang.IllegalStateException: Unexpected use of scheduler.
  at org.springframework.web.socket.config.annotation.WebSocketConfigurationSupport$NoOpScheduler.schedule(WebSocketConfigurationSupport.java:108) ~[spring-websocket-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.config.ScheduledTaskRegistrar.scheduleCronTask(ScheduledTaskRegistrar.java:414) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.config.ScheduledTaskRegistrar.scheduleTasks(ScheduledTaskRegistrar.java:352) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.config.ScheduledTaskRegistrar.afterPropertiesSet(ScheduledTaskRegistrar.java:332) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.finishRegistration(ScheduledAnnotationBeanPostProcessor.java:280) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:211) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:102) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:353) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:887) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:552) ~[spring-context-5.0.4.RELEASE.jar:5.0.4.RELEASE]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:388) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
  at my.package.App.main(App.java:31) [main/:na]
  </code></pre>
  
  <p>How to make this simple WebSocket app work?</p>