-2
SockJS
クライアントをJavaBeansアプリケーションでSpringブートで実装するにはどうすればいいですか?かなり良い例があれば言及してください。Web以外のアプリケーション用のSockJS Javaクライアント実装
SockJS
クライアントをJavaBeansアプリケーションでSpringブートで実装するにはどうすればいいですか?かなり良い例があれば言及してください。Web以外のアプリケーション用のSockJS Javaクライアント実装
まず第一に、公式ドキュメントを参照してください:https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
非Webアプリケーションは、まだ組み込みソリューションの一つは間違いなく十分です、あなたのケースでは、アプリケーションサーバが必要になります。あなたはMavenを使用している場合、例えば試してみてください。
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
<version>4.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.0.v20161208</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-log4j</artifactId>
<version>8.5.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
<scope>runtime</scope>
</dependency>
</dependencies>
あなたのクライアントは、このように、多かれ少なかれ見ることができますので、同様に揺動フレームを開始することができ
List<Transport> transports = new ArrayList<Transport>(2);
transports.add(new WebSocketTransport(new StandardWebSocketClient()));
transports.add(new RestTemplateXhrTransport());
SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new StringMessageConverter());
StompSession session = null;
DefaultStompFrameHandler stompHandler = new DefaultStompFrameHandler();
try {
session = stompClient.connect(WEBSOCKET_URI, new MyStompSessionHandler()).get(1, TimeUnit.SECONDS);
session.subscribe("/topic" + "/channel", stompHandler);
// do your stuff
...
} finally {
if (session != null) {
session.disconnect();
}
}
あなたの主な春のブートクラス:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
ConfigurableApplicationContext context = new SpringApplicationBuilder(Application.class).headless(false).run(args);
EventQueue.invokeLater(() -> {
// this is your JFrame
AppPrincipalFrame appFrame = context.getBean(AppPrincipalFrame.class);
appFrame.setVisible(true);
});
うまくいけば、それはいくつかの助けになるだろう:)幸運!
ありがとうございます。あなたも完全な依存関係について言及できますか? –
いくつかのクラスはtomcat依存関係にありません –
私が働いている依存関係を追加しました。 – mrUwa