Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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
Java Springboot Websocket+;跺脚+;SOCKJS不使用JBOSS EAP 6.4,未找到抛出404_Java_Spring Boot_Websocket_Jboss_Stomp - Fatal编程技术网

Java Springboot Websocket+;跺脚+;SOCKJS不使用JBOSS EAP 6.4,未找到抛出404

Java Springboot Websocket+;跺脚+;SOCKJS不使用JBOSS EAP 6.4,未找到抛出404,java,spring-boot,websocket,jboss,stomp,Java,Spring Boot,Websocket,Jboss,Stomp,问题:无法访问JBOSS EAP 6.4服务器中的Springboot Websocket端点。使用SOCKJS访问WebSocket时,浏览器控制台中出现404错误 有关问题和步骤的更多详细信息: 我用了这个项目。本spring参考使用了客户端web库的包。但是它没有加载客户端JS库,所以我修改了下面的链接来工作 <link href="https://cdn.jsdelivr.net/webjars/org.webjars/bootstrap/3.4.1/bootstrap.

问题:无法访问JBOSS EAP 6.4服务器中的Springboot Websocket端点。使用SOCKJS访问WebSocket时,浏览器控制台中出现404错误

有关问题和步骤的更多详细信息:

我用了这个项目。本spring参考使用了客户端web库的包。但是它没有加载客户端JS库,所以我修改了下面的链接来工作

<link href="https://cdn.jsdelivr.net/webjars/org.webjars/bootstrap/3.4.1/bootstrap.min.css" rel="stylesheet">
<link href="/main.css" rel="stylesheet">
<script src="/app.js"></script>
<script src="https://cdn.jsdelivr.net/webjars/org.webjars/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.2/dist/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/webjars/org.webjars/sockjs-client/1.1.2/sockjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/webstomp-client@1.2.6/dist/webstomp.min.js"></script>
服务器端代码:

WebSocketConfig

@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").setAllowedOrigins("*").withSockJS();
    }

}
控制器

@Controller
public class GreetingController {

    @MessageMapping("/hello")
    @SendTo("/topic/greetings")
    public Greeting greeting(HelloMessage message) throws Exception {
        Thread.sleep(1000); // simulated delay
        return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
    }
}
根据这一点,我们在Jboss EAP 6.4中做了以下更改

  • 在JBoss EAP服务器配置文件(standalone.xml)的web子系统中启用NIO2连接器
  • 在jboss-web.xml文件中使用true启用WebSocket
  • 我们有默认的Jboss上下文路径

    请帮助我们解决问题:

    获取http://localhost:8080/gs-指南websocket/info?t=1601151988789 404(未找到)

    另外,我们在STS控制台日志中看到以下信息,但JBOSS EAP 6.4日志中没有此类信息

    [MessageBroker-3]o.s.w.s.c.WebSocketMessageBrokerStats:WebSocketSession[1当前WS(1)-HttpStream(0)-HttpPoll(0),总计1,0异常关闭(0连接失败,0发送限制,0传输错误)],StompSubtocol[已处理的连接(1)-已连接(1)-断开连接(0)],stompBrokerRelay[null],边界通道内[pool size=6,active threads=0,queued tasks=0,completed tasks=6],outboundChannel[pool size=1,active threads=0,queued tasks=0,completed tasks=1],sockJsScheduler[pool size=8,active threads=1,queued tasks=2,completed tasks=7]

    谢谢你的帮助

    也参考了以下解决方案,但运气不佳

    @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").setAllowedOrigins("*").withSockJS();
        }
    
    }
    
    @Controller
    public class GreetingController {
    
        @MessageMapping("/hello")
        @SendTo("/topic/greetings")
        public Greeting greeting(HelloMessage message) throws Exception {
            Thread.sleep(1000); // simulated delay
            return new Greeting("Hello, " + HtmlUtils.htmlEscape(message.getName()) + "!");
        }
    }