我想使用带弹簧的websockets并使用此博客http://www.baeldung.com/websockets-spring设置使其正常工作,但它不起作用.getting error:
未捕获类型错误:onrecieve不是函数(..)stomp.js
使用websockets,stockjs nd stomp with spring project.i m使用spring 4.2.4和tomcat 7.0.56时出现此错误。
我知道为什么会出现这个错误?
我的web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>CometdWireChatRE</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<servlet>
<description></description>
<display-name>chatbook</display-name>
<servlet-name>chatbook</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>chatbook</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/com/chatbook/web/xmlfileconfig/daoAccesspackage.xml
classpath:/com/chatbook/web/xmlfileconfig/serviceaccesspackage.xml
classpath:/com/chatbook/web/xmlfileconfig/cacheMan.xml
classpath:/com/chatbook/web/xmlfileconfig/configpackage.xml
</param-value>
</context-param>
<description>Wirechat Database</description>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/wirechatDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<listener>
<listener- class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
我的类启用websocket:
package com.chatbook.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat").withSockJS();
}
}
我的控制员:
package com.chatbook.web.controllers;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import com.chatbook.web.config.Message;
import com.chatbook.web.config.OutputMessage;
@Controller
public class AtmosController {
//@Autowired
//SimpMessagingTemplate template;
public AtmosController() {
System.out.println("atm");
}
@MessageMapping("/chat")
@SendTo("/topic/messages")
public OutputMessage send(Message message) throws Exception {
String time = new SimpleDateFormat("HH:mm").format(new Date());
System.out.println(message);
return new OutputMessage(message.getFrom(), message.getText(), time);
//template.convertAndSend("/topic/messages", new OutputMessage(message.getFrom(), message.getText(), time));
}
}