相关疑难解决方法(0)

Spring 4 WebSocket应用程序

我试图从spring网站运行这个例子: 教程 除了Spring Boot部分.

在web.xml

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>sample</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                com.evgeni.websock.WebSocketConfig
            </param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>sample</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)

Java配置:

@Configuration
@ComponentScan(basePackages = {"com.evgeni.controller"})
@EnableWebSocketMessageBroker
@EnableWebMvc
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketMessageBrokerConfigurer  {

    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/hello").withSockJS();
    }

    public void configureClientInboundChannel(ChannelRegistration registration) {
        // TODO Auto-generated method stub

    }

    public void configureClientOutboundChannel(ChannelRegistration registration) {
        // TODO Auto-generated method stub

    }

    public void configureMessageBroker(MessageBrokerRegistry registry) { …
Run Code Online (Sandbox Code Playgroud)

java spring jsp spring-mvc websocket

7
推荐指数
1
解决办法
2万
查看次数

Spring Websocket和404连接状态

在Tomcat 7.0.50下运行的一个正在运行的Spring MVC 4.0.2项目中,我正在尝试使用简单的代理和sockjs stomp端点实现Spring Websocket,遵循官方参考.因此,在contextConfigLocation(DistpacherServlet属性)中,我添加了一个值"websocket-config.xml",其中包含:

>     <websocket:message-broker application-destination-prefix="/app" >
>           <websocket:stomp-endpoint path="/monitor">
>             <websocket:sockjs />
>           </websocket:stomp-endpoint>
>           <websocket:simple-broker prefix="/topic"/>
>     </websocket:message-broker>
Run Code Online (Sandbox Code Playgroud)

在eclipse控制台(catalina log)中,当我启动Tomcat时,会出现行

  • 初始化ExecutorService'clientInboundChannelExecutor'
  • 初始化ExecutorService'weboutOutboundChannelExecutor'
  • 初始化ExecutorService'messageBrokerSockJsScheduler'
  • 将URL路径[/ monitor/**]映射到[class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]类型的处理程序上

在jsp页面中我放了代码

....
var socket = new SockJS("monitor");
var stompClient = Stomp.over(socket); ....

不幸的是,当我从Chrome(v32)加载jsp页面时,我收到此错误:

无法加载资源:服务器响应状态为404(未找到)

http:// localhost:8080 /(ProjectName)/ monitor/info

显然我在本地进行此测试,然后所有其他webapp资源都可以在http:// localhost /(ProjectName)正确访问.

怎么了?

****更新2014年2月20日我试图按照这个解决的堆栈问题,建议使用Tomcat8 for Spring Websocket,不幸的是它不起作用

spring websocket sockjs

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

spring ×2

websocket ×2

java ×1

jsp ×1

sockjs ×1

spring-mvc ×1