Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs SockJS与springboot应用程序404应信息请求_Reactjs_Spring Boot_Websocket_Stomp_Sockjs - Fatal编程技术网

Reactjs SockJS与springboot应用程序404应信息请求

Reactjs SockJS与springboot应用程序404应信息请求,reactjs,spring-boot,websocket,stomp,sockjs,Reactjs,Spring Boot,Websocket,Stomp,Sockjs,谁能告诉我我做错了什么? 我正在尝试设置websocket-springboot服务器,react ui 使用sockjs和ive在线配置了我的MessageBroker和stomp端点 我收到一个404的信息请求到我的服务器,我似乎无法连接 @控制器 公共类连接控制器{ @自动连线 私有SimpMessagingTemplate消息模板; @消息映射(“/connect”) 公共无效连接(@有效负载连接){ messagingTemplate.convertAndSend(“/connect

谁能告诉我我做错了什么? 我正在尝试设置websocket-springboot服务器,react ui

使用sockjs和ive在线配置了我的MessageBroker和stomp端点

我收到一个404的信息请求到我的服务器,我似乎无法连接

@控制器
公共类连接控制器{
@自动连线
私有SimpMessagingTemplate消息模板;
@消息映射(“/connect”)
公共无效连接(@有效负载连接){
messagingTemplate.convertAndSend(“/connectionRequest/”+connection.getConnecteeId(),connection);
}
}
@配置
@EnableWebSocketMessageBroker
公共类WebSocketConfig实现WebSocketMessageBrokerConfiger{
@凌驾
public void配置MessageBroker(MessageBrokerRegistry配置){
config.enableSimpleBroker(“/topic”);
config.setApplicationDestinationPrefixes(“/app”);
}
@凌驾
公共无效注册表TompendPoints(StompEndpointRegistry注册表){
registry.addEndpoint(“/gs guide websocket”).withSockJS();
}
}
导出类ContactList扩展React.Component{
构造函数(){
超级();
this.sendMessage=this.sendMessage.bind(this);
}
发送消息(){
试一试{
this.clientRef.sendMessage('/app/connect',JSON.stringify());
返回true;
}捕获(e){
返回false;
}
}
render(){
返回(
连接
{this.clientRef=client}
onConnect={()=>{console.log('connected')}
onDisconnect={()=>{this.setState({clientConnected:false}}}
调试={true}/>
);
}
}
@Controller
public class ConnectController {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @MessageMapping("/connect")
    public void connect(@Payload Connection connection) {
       messagingTemplate.convertAndSend("/connectionRequest/"+connection.getConnecteeId(), connection);
    }
}

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

  @Override
  public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/topic");
    config.setApplicationDestinationPrefixes("/app");
  }

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


export class ContactList extends React.Component {

    constructor() {
        super();
        this.sendMessage = this.sendMessage.bind(this);
    }
    
      sendMessage () {
        try {
          this.clientRef.sendMessage('/app/connect',JSON.stringify());
          return true;
        } catch(e) {
          return false;
        }
      }

    render() {
        return (
            <Flex gap="gap.small" column>
                <button onClick={this.sendMessage}>
                    Connect
                </button>

                <SockJsClient url='http://localhost:8080/' topics={["/topic/connectionRequest/abc"]}
                    onMessage={ this.onMessageReceive } ref={ (client) => { this.clientRef = client }}
                    onConnect={ () => { console.log('connected')} }
                    onDisconnect={ () => { this.setState({ clientConnected: false }) } }
                    debug={ true }/>
            </Flex>
        );
    }
}