-2
스프링 부트로 Java 스윙 응용 프로그램에 SockJS
클라이언트를 어떻게 구현합니까? 꽤 좋은 예가 있으면 언급하십시오.비 웹 응용 프로그램 용 SockJS Java 클라이언트 구현
스프링 부트로 Java 스윙 응용 프로그램에 SockJS
클라이언트를 어떻게 구현합니까? 꽤 좋은 예가 있으면 언급하십시오.비 웹 응용 프로그램 용 SockJS Java 클라이언트 구현
우선 해제, 공식 문서를 참조하십시오 : https://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
여전히 애플리케이션 서버를 필요 비 - 웹 애플리케이션, 귀하의 경우, 임베디드 솔루션 중 하나는 확실히 충분합니다. 당신이 받는다는을 사용하는 경우, 예를 들어보십시오
<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);
});
잘하면 그 도움이 될 것입니다 :) 행운을 빌어 요!
감사합니다. 완전히 의존성을 언급 할 수 있습니까? –
일부 클래스는 바람둥이 종속성에 포함되지 않습니다. –
내가 일하는 종속성을 추가했습니다. – mrUwa