SockJS + Stomp + SpringBoot =问题 [英] SockJS + Stomp + SpringBoot = Issue

查看:134
本文介绍了SockJS + Stomp + SpringBoot =问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有页面的应用程序,该页面为此订阅了一个websocket端点:

I have an application with a page that subscribe a websocket endpoint with this:

 var socket = new SockJS("/hello");
            stompClient = Stomp.over(socket);
            stompClient.connect({}, function (frame) {
                stompClient.subscribe('/topic/nextticket', function (ws_response) {
                    var data = JSON.parse(ws_response.body);
                    ....
                });
            });

此应用程序可在Raspberry上运行,并且在Internet上连接了Raspberry时一切正常.但是在本地网络(没有互联网)中,我有这个

This app run on Raspberry and all works fine when the raspberry is connected on internet. But in a local network (no Internet) I have this

我的后端conf是:

@Configuration
@PropertySource("file:/etc/app.properties")
@EnableWebSocketMessageBroker
class MessageBroker extends AbstractWebSocketMessageBrokerConfigurer {

    @Autowired
    Environment env

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



    @Override
    void registerStompEndpoints(StompEndpointRegistry registry) {

        def ip = env.getProperty("kiosk.ip") ? env.getProperty("kiosk.ip") as String : "192.168.1.90"

        registry.addEndpoint("/hello")
                .setAllowedOrigins("*")
                .withSockJS()
                .setClientLibraryUrl("http://${ip}:8080/js/sockjs.js")


    }
}

我不明白为什么会有CORS(我想)问题.而且页面会永久重新加载.

I don't understand why have a CORS (I suppose) problem.. And the page reload forever.

预先感谢

路易斯

推荐答案

每当我使用特定IP时,我的应用程序中就会出现这种CORS行为.

I had this CORS behaviour in my application whenever I used a specific IP.

application.properties

server.address: 192.168.1.90

从application.properties删除server.address后,该应用程序按预期工作.如果有人知道造成这种情况的原因,请告诉我.我本来希望

After removing server.address from the application.properties the application worked as expected. If somebody knows the cause of this please let me know. I would have expected that

registry.setAllowedOrigins("*")

将所有CORS行为删除为此处的文档

would remove all CORS behaviour as document here

这篇关于SockJS + Stomp + SpringBoot =问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆