Skip to content

Instantly share code, notes, and snippets.

@linux-china
Created January 17, 2020 19:05
Show Gist options
  • Save linux-china/962fb24b1791f56c87d44880a1907583 to your computer and use it in GitHub Desktop.
Save linux-china/962fb24b1791f56c87d44880a1907583 to your computer and use it in GitHub Desktop.
WebSocketConfig for WebFlux
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class WebSocketConfig {
@Bean
public HandlerMapping handlerMapping() {
Map<String, WebSocketHandler> map = new HashMap<>();
map.put("/ws1", new MyWebSocketHandler());
return new SimpleUrlHandlerMapping(map, -1);
}
@Bean
@ConditionalOnMissingBean
public WebSocketHandlerAdapter handlerAdapter() {
return new WebSocketHandlerAdapter();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment