詳細に春ブーツのWebSocket統合とnginxの設定について

この記事では、私が習得したり、作業する私たちのすべてのための学習の一定の基準値を持っていると信じて、非常に詳細にあなたに伝え春ブーツのWebSocketとnginxの構成の統合に関連する情報、紙のサンプルコードを導入する主である、あなたは以下の友達を必要とします小さなシリーズは、バーの下に一緒に学ぶことを学んで。
序文

このホワイトペーパーでは、あなたの参照の研究のために共有する春ブーツのWebSocketの統合とnginxの設定に関連するコンテンツを紹介するという名前生年月日言葉の下には、詳細な紹介を見てみるために、と言ってあまり話をしませんでした。

A:春ブーツのWebSocket統合

Mavenプロジェクトを作成し、以下の依存性を追加

org.springframework.boot春ブート依存関係1.4.0.RELEASE輸入ポンポンorg.springframework.boot春ブート・スターター・ウェブorg.springframework.boot春ブート・スタータのWebSocket
代码如下:

パッケージcom.wh.web輸入org.springframework.web.socket.TextMessage。輸入org.springframework.web.socket.WebSocketSession。輸入org.springframework.web.socket.handler.TextWebSocketHandler。パブリッククラスCountWebSocketHandlerがTextWebSocketHandlerを拡張{プライベート静的長い、カウント= 0; 保護された無効handleTextMessage(WebSocketSessionセッション、TextMessageのメッセージは)例外{session.sendMessage(新規のTextMessage(「你是第」+(++数)+「位を访客」))スロー; }}
パッケージcom.wh.web; 輸入org.springframework.context.annotation.Configuration。輸入org.springframework.web.socket.config.annotation.WebSocketConfigurer。輸入org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry。@ConfigurationパブリッククラスWebsocketConfigurationはWebSocketConfigurer {ます。public void registerWebSocketHandlers(WebSocketHandlerRegistryレジストリ){registry.addHandler(新CountWebSocketHandler()、「/ウェブ/回数」)を実装します。}}
パッケージcom.wh.web; 輸入org.springframework.boot.SpringApplication。輸入org.springframework.boot.autoconfigure.SpringBootApplication。輸入org.springframework.web.socket.config.annotation.EnableWebSocket。@EnableWebSocket @SpringBootApplicationパブリッククラスServerApp {パブリック静的無効メイン(文字列[] args){SpringApplication.run(ServerApp.class、引数)。}}
application.properties内容如下。

server.port = 9080 spring.resources.static-場所=クラスパス:/ webappの/ HTML /
SRC /メイン/リソース/ webappの/ HTML / index.htmlを内容如下:

web socket

ウェブソケット

おすすめ

転載: blog.csdn.net/sakura379/article/details/93469771