如何解决在信息请求中使用带有Springboot应用程序404的SockJS
谁能告诉我我做错了什么? 我正在尝试设置一个websocket-springboot服务器,响应ui
按照在线指南https://spring.io/guides/gs/messaging-stomp-websocket/
,使用sockjs和ive配置了我的消息代理和重脚终结点我收到一个404的信息请求到我的服务器,我似乎无法连接
@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>
);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。