2017-07-03 13 views
0

Ich habe versucht, eine Web-Anwendung von einfachen Brokern zu einem eingebetteten ActiveMQ Broker mit stampfen 1.5.4 mit Spring zu ändern Boot aber immer einen Fehler immer auf bis startenFrühling Boot-WebSocket mit eingebettetem ActiveMQ Broker

Caused by: java.lang.IllegalArgumentException: No handlers 
    at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE] 
    at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:244) ~[spring-websocket-4.3.9.RELEASE.jar:4.3.9.RELEASE] 
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:175) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE] 
    ... 15 common frames omitted 

I reduziert der Fehler mit einem einfachen Beispiel

POM Datei *

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>websocket</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>websocket</name> 
    <description>Demo project for Spring Boot</description> 

    <parent> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-parent</artifactId> 
     <version>1.5.4.RELEASE</version> 
     <relativePath/> <!-- lookup parent from repository --> 
    </parent> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 
     <java.version>1.8</java.version> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-activemq</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-websocket</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-configuration-processor</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>org.apache.activemq</groupId> 
      <artifactId>activemq-stomp</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>io.projectreactor</groupId> 
      <artifactId>reactor-net</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>io.projectreactor</groupId> 
      <artifactId>reactor-core</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>io.netty</groupId> 
      <artifactId>netty-all</artifactId> 
      <version>4.1.2.Final</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-test</artifactId> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

Anwendungsklasse

package com.example.websocket; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 

@SpringBootApplication 
public class WebsocketApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(WebsocketApplication.class, args); 
    } 
} 

WebSocketConfig Klasse

package com.example.websocket; 

import org.springframework.beans.factory.annotation.Value; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.jms.annotation.EnableJms; 
import org.springframework.messaging.simp.config.MessageBrokerRegistry; 
import org.springframework.web.socket.config.annotation.EnableWebSocket; 
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport; 

@Configuration 
@EnableWebSocket 
@EnableWebSocketMessageBroker 
@EnableJms 
public class WebSocketConfig extends WebSocketMessageBrokerConfigurationSupport { 

    @Value("${spring.activemq.user}") 
    private String mqUser; 
    @Value("${spring.activemq.password}") 
    private String mqPasword; 

    @Override 
    public void configureMessageBroker(final MessageBrokerRegistry config) { 
     config.enableStompBrokerRelay("/topic") // 
     .setRelayHost("localhost") // 
     .setRelayPort(61613) // 
     .setClientLogin(mqUser) // 
     .setClientPasscode(mqPasword) // 
     ; 
     config.setApplicationDestinationPrefixes("/app"); 
    } 

    @Override 
    public void registerStompEndpoints(final StompEndpointRegistry registry) { 
     registry.addEndpoint("/websocket").withSockJS(); 
    } 

} 

application.yml

spring: 
    activemq: 
    broker-url: stomp://localhost:61613 
    user: user 
    password: pass 

Jemand weiß, mein Fehler?

Antwort

0

Ich fand die Lösung. Mein Problem war die EnableWebSocketMessageBroker Annotation und fehlende Bereitstellung von ActiveMQ Broker

die application.yml entfernen und WebSocketConfig Klasse

package com.example.websocket; 

import org.apache.activemq.broker.BrokerService; 
import org.apache.activemq.broker.jmx.ManagementContext; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.messaging.simp.config.MessageBrokerRegistry; 
import org.springframework.web.socket.config.annotation.EnableWebSocket; 
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport; 

@Configuration 
@EnableWebSocket 
public class WebSocketConfig extends WebSocketMessageBrokerConfigurationSupport { 


    @Override 
    public void configureMessageBroker(final MessageBrokerRegistry config) { 
     config.enableStompBrokerRelay("/topic") // 
     .setRelayHost("localhost") // 
     .setRelayPort(61613); 
     config.setApplicationDestinationPrefixes("/app"); 
    } 

    @Override 
    public void registerStompEndpoints(final StompEndpointRegistry registry) { 
     registry.addEndpoint("/websocket").withSockJS(); 
    } 

    @Bean(initMethod = "start", destroyMethod = "stop") 
    public BrokerService broker() throws Exception { 
     final BrokerService broker = new BrokerService(); 
     broker.addConnector("stomp://localhost:61613"); 

     broker.setPersistent(false); 
     final ManagementContext managementContext = new ManagementContext(); 
     managementContext.setCreateConnector(true); 
     broker.setManagementContext(managementContext); 

     return broker; 
    } 
} 

Werke für mich ändern.

Verwandte Themen