spring mvc4.1+Websocket 链接时报错!

信息: Initializing Spring FrameworkServlet 'springmvc'
WebSocketConfig
new systemWebSocketHandler
Before Handshake
After Handshake
一月 19, 2017 3:41:06 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springmvc] in context with path [/main] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8080/main/webSocketServer; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.websocket.server.WsServerContainer.doUpgrade(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/websocket/server/ServerEndpointConfig;Ljava/util/Map;)V] with root cause
java.lang.NoSuchMethodError: org.apache.tomcat.websocket.server.WsServerContainer.doUpgrade(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/websocket/server/ServerEndpointConfig;Ljava/util/Map;)V
at org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy.upgradeInternal(TomcatRequestUpgradeStrategy.java:72)
at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.upgrade(AbstractStandardUpgradeStrategy.java:118)
at org.springframework.web.socket.server.support.DefaultHandshakeHandler.doHandshake(DefaultHandshakeHandler.java:215)
at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:120)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:112)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:223)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:107)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:75)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:90)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:494)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:632)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1550)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

pom.xml


4.0.0
com.scrx.ymg
main
0.0.1-SNAPSHOT
war
YMG


3.1
5.1.0.Final
5.2.4.Final
UTF-8

<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>7.0</version>
</dependency>

<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>javax.servlet.jsp.jstl</artifactId>
  <version>1.2.2</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aop</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-aspects</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context-support</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-expression</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-instrument</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-instrument-tomcat</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>4.3.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>aopalliance</groupId>
  <artifactId>aopalliance</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>commons-pool</groupId>
  <artifactId>commons-pool</artifactId>
  <version>1.6</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
</dependency>
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.8.2</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc-portlet</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-oxm</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-web</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-core</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-acl</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-aspects</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-cas</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-config</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-crypto</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-ldap</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-openid</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-remoting</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.security</groupId>
  <artifactId>spring-security-taglibs</artifactId>
  <version>3.2.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.webflow</groupId>
  <artifactId>spring-webflow</artifactId>
  <version>2.4.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.webflow</groupId>
  <artifactId>spring-binding</artifactId>
  <version>2.4.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.webflow</groupId>
  <artifactId>spring-js</artifactId>
  <version>2.4.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.webflow</groupId>
  <artifactId>spring-js-resources</artifactId>
  <version>2.4.0.RELEASE</version>
</dependency>
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring-orm</artifactId> 
<version>4.3.0.RELEASE</version> 
</dependency> 
<dependency>
  <groupId>opensymphony</groupId>
  <artifactId>ognl</artifactId>
  <version>2.6.11</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>${hibernate-version}</version>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>${hibernate-version}</version>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-jpamodelgen</artifactId>
  <version>${hibernate-version}</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>${hibernate-validator-version}</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator-annotation-processor</artifactId>
  <version>${hibernate-validator-version}</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator-cdi</artifactId>
  <version>${hibernate-validator-version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>



<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.1</version>
</dependency>
<dependency>
  <groupId>org.glassfish.web</groupId>
  <artifactId>javax.el</artifactId>
  <version>2.2.4</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>  
</dependency>


com.fasterxml.jackson.core
jackson-core
2.3.0


com.fasterxml.jackson.core
jackson-databind
2.3.0


org.springframework
spring-websocket
4.0.1.RELEASE


org.springframework
spring-messaging
4.0.1.RELEASE





maven-compiler-plugin
2.3.2

1.7
1.7



maven-war-plugin
2.6

false




1个回答

出现这个问题的原因是,apache的websocket包和javax-servlet包冲突了,找到Apache Tomcat的webApp目录,打开你部署的项目文件夹,依次打开WEB-INF/lib,找到javaee-api-7.0.jar,删除,再重新启动项目。

manyouzhijian
My_Captain_ lib下面没有包.
3 年多之前 回复
manyouzhijian
My_Captain_ <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
3 年多之前 回复
manyouzhijian
My_Captain_ <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
spring mvc4.1+Websocket 链接时报错!

信息: Initializing Spring FrameworkServlet 'springmvc' WebSocketConfig new systemWebSocketHandler Before Handshake After Handshake 一月 19, 2017 3:41:06 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [springmvc] in context with path [/main] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8080/main/webSocketServer; nested exception is java.lang.NoSuchMethodError: org.apache.tomcat.websocket.server.WsServerContainer.doUpgrade(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/websocket/server/ServerEndpointConfig;Ljava/util/Map;)V] with root cause java.lang.NoSuchMethodError: org.apache.tomcat.websocket.server.WsServerContainer.doUpgrade(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Ljavax/websocket/server/ServerEndpointConfig;Ljava/util/Map;)V at org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy.upgradeInternal(TomcatRequestUpgradeStrategy.java:72) at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.upgrade(AbstractStandardUpgradeStrategy.java:118) at org.springframework.web.socket.server.support.DefaultHandshakeHandler.doHandshake(DefaultHandshakeHandler.java:215) at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:120) at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:112) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:223) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:107) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:75) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:934) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:90) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:494) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:632) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1550) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.scrx.ymg</groupId> <artifactId>main</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>YMG</name> <description/> <properties> <webVersion>3.1</webVersion> <hibernate-version>5.1.0.Final</hibernate-version> <hibernate-validator-version>5.2.4.Final</hibernate-validator-version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.servlet.jsp.jstl</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-instrument</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-instrument-tomcat</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.3.0.RELEASE</version> </dependency> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.2</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc-portlet</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>4.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-core</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-acl</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-aspects</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-cas</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-crypto</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-ldap</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-openid</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-remoting</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-webflow</artifactId> <version>2.4.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-binding</artifactId> <version>2.4.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-js</artifactId> <version>2.4.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-js-resources</artifactId> <version>2.4.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>4.3.0.RELEASE</version> </dependency> <dependency> <groupId>opensymphony</groupId> <artifactId>ognl</artifactId> <version>2.6.11</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernate-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-jpamodelgen</artifactId> <version>${hibernate-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>${hibernate-validator-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId> <version>${hibernate-validator-version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator-cdi</artifactId> <version>${hibernate-validator-version}</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> <version>2.2.4</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>javax.el</artifactId> <version>2.2.4</version> </dependency> <dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> <version>1.4.01</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.3.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> <version>4.0.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-messaging</artifactId> <version>4.0.1.RELEASE</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> </project>

springmvc 整合websocket 报错 404

第一: pom 配置文件: <dependency> <groupId>javax.websocket</groupId> <artifactId>javax.websocket-api</artifactId> <version>1.0</version> <scope>provided</scope><!--这个是从网上看的是为了解决jar包冲突的 --> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-websocket</artifactId> <version>4.1.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-messaging</artifactId> <version>4.1.6.RELEASE</version> </dependency> 第二步: 【注册,启动 websocket server 和 握手拦截器 】 @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { System.out.println("....注册......"); registry.addHandler(myhandler(), "/websocket").addInterceptors(myInterceptors()).setAllowedOrigins("*"); registry.addHandler(myhandler(), "/sockjs/websocket").addInterceptors(myInterceptors()).withSockJS(); } @Bean public WebSocketHandler myhandler() { System.out.println("....服务端......"); return new WebsocketEndPoint(); } @Bean public HandshakeInterceptor myInterceptors() { System.out.println("....握手拦截器......"); return new HandshakeInterceptor(); } } public class WebsocketEndPoint extends TextWebSocketHandler { private Logger logger = LoggerFactory.getLogger(WebsocketEndPoint.class); @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { super.handleTextMessage(session, message); logger.debug("GOMA === > WebSocketEndPoint.handlerTextMessage..."); TextMessage returnMessage = new TextMessage(message.getPayload()+" received at server"); session.sendMessage(returnMessage); } } public class HandshakeInterceptor extends HttpSessionHandshakeInterceptor { private Logger logger = Logger.getLogger(getClass()); @Override public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception { logger.debug("GOMA ===> Before Handshake"); return super.beforeHandshake(request, response, wsHandler, attributes); } @Override public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception ex) { logger.debug("GOMA ===> After Handshake"); super.afterHandshake(request, response, wsHandler, ex); } } 第三步:页面 client 我的tomcat 的端口是 9018 socket = new WebSocket('ws://localhost:9018/testSocket/websocket'); 运行报错: WebSocket connection to 'ws://localhost:9018/testSocket/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400 这是为啥? 都配置了 ,为啥 是404 奇怪~~~ 那个大神给我解决一下

websocket服务端执行报错

System.Net.Sockets.SocketException (0x80004005): 以一种访问权限不允许的方式做了一个访问套接字的尝试。 在 System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) 在 System.Net.Sockets.Socket.Bind(EndPoint localEP) 在 WebSocket.Program.Main(String[] args) 位置 E:\request\webSocket\WebSocket\Program.cs:行号 36 当我执行服务器端的时候就报如上的错误,求教怎么解决?

spring 整合websocket配置文件报错的问题

如题: 在这个类加@Configuaration标签,项目可以正常启动,当时只要访问页面,就会报cfg标签找不到, 如果不加这个标签,项目可以正常启动并且可以正常访问,但是访问websocket时,会报连接不上的错误 ![图片说明](https://img-ask.csdn.net/upload/201703/02/1488440797_85142.png)

spring boot 整合 websocket 外置tomcat启动报错,访问报错

![图片说明](https://img-ask.csdn.net/upload/202005/11/1589186001_6765.jpg) ![图片说明](https://img-ask.csdn.net/upload/202005/11/1589186105_462754.jpg) ![图片说明](https://img-ask.csdn.net/upload/202005/11/1589186040_152834.jpg)

使用webSocket的时候报错了,不能接受到来自服务器的消息

报的是ClassCastException java.sun.nio.ch.SocketChannelImpl 转换成org.java_websocket.WrappedByteChannel失败 怎么回事呢

springMVC中使用websocket报错404

![图片说明](https://img-ask.csdn.net/upload/201612/01/1480567442_423163.png) ## 似乎是springmvc拦截了ws请求,怎么才能让springMVC不拦截WS呢 JS代码 ``` var websocket = null; //判断当前浏览器是否支持WebSocket if('WebSocket' in window){ websocket = new WebSocket("ws://localhost:8080/VM2.0/websocket"); } else{ alert('浏览器不支持websocket,请更换浏览器'); }; //连接发生错误的回调方法 websocket.onerror = function(){ console.log("websocket连接失败"); }; //连接成功建立的回调方法 websocket.onopen = function(event){ console.log("websocket连接成功"); }; ``` java代码 ``` //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。 private static int onlineCount = 0; //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识 private static CopyOnWriteArraySet<MySocket> webSocketSet = new CopyOnWriteArraySet<MySocket>(); //与某个客户端的连接会话,需要通过它来给客户端发送数据 private Session session; /** * 存储当前有效的session对象 */ private static Queue<Session> sessionSet = new ConcurrentLinkedQueue<Session>(); /** * 连接建立成功调用的方法 * @param session 可选的参数。session为与某个客户端的连接会话,需要通过它来给客户端发送数据 */ @OnOpen public void onOpen(Session currentSession){ if(sessionSet.contains(currentSession) == false){ sessionSet.add(currentSession); System.out.println("WebSocketTest.onOpen()================Add=" + sessionSet.size()); } System.out.println("Server say:Client connected"); } ```

【费解的疑问】websocket.js 报错了 ,显示无法加载

是这样的,项目中 websocket.js 报错了,以前都是正常的,对 xss 拦截器修改 url-patter 后,就无法请求 websocket.js 了,是怎么回事呢?

spring与websocket集成请求头报错

```一月 05, 2018 6:28:16 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [Spring MVC Dispatcher Servlet] in context with path [/eLearningSystem] threw exception [Request processing failed; nested exception is org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://127.0.0.1:8085/eLearningSystem/ws.do?CFAPP_USERNAME=admin; nested exception is java.lang.NoSuchMethodError: org.springframework.web.socket.WebSocketHttpHeaders.getUpgrade()Ljava/lang/String;] with root cause java.lang.NoSuchMethodError: org.springframework.web.socket.WebSocketHttpHeaders.getUpgrade()Ljava/lang/String; at org.springframework.web.socket.server.support.DefaultHandshakeHandler.doHandshake(DefaultHandshakeHandler.java:171) at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:120) at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) at javax.servlet.http.HttpServlet.service(HttpServlet.java:624) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:73) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.learning.filter.SessionFilter.doFilter(SessionFilter.java:55) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.learning.pager.PagerFilter.doFilter(PagerFilter.java:28) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at cn.learning.filter.EncryptionRequestFilter.doFilter(EncryptionRequestFilter.java:199) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) ``` 请各位大神帮帮忙,我下载的demo上传的时候Upgrade的值也是个字符串数组。 但是我集成到项目里就报这个错了,在网上搜了找解决方案,都没出现过这样的情况,不知道该怎么修改。

spring mvc+websocket问题请教

http://my.oschina.net/ldl123292/blog/304360?p=1#comments 按照这篇博客操作,遇到了好多问题,本人小白,想找会的前辈帮忙答疑解惑下,祈求好心人~~~

spring_websocket 客户端发送消息报错

![图片说明](https://img-ask.csdn.net/upload/201609/28/1475048079_993186.png)

我在原有的项目当中按照官方的例子集成了spring websocket,没有报错,但是项目无法启动

我的项目是sring+springMVC+Mybatis,JDK为1.7,tomcat 7 按照官方的例子[spring web socket demo](https://spring.io/guides/gs/messaging-stomp-websocket/ "")搞了好几天了,一直是这样,有木有大神帮我看看是怎么回事 主要的代码在这里 @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("/hello").withSockJS(); }

springcloud下websocket无法通过网关连接

在springcloud下使用websocket,前端框架使用vue 若前端直接调用websocket的服务(不走网关),则可正常连接(url: http://localhost:8604/webSocketServer)) 若前端通过网关来连接websocket的服务,则会报404和一些跨域的问题。(url: http:localhost:9091/system-otherService/webSocketServer) 注: 8604为webSocket服务的端口,9091为网关的端口 前端: ![图片说明](https://img-ask.csdn.net/upload/201808/24/1535099271_464422.png) 后台: websocket配置: ![图片说明](https://img-ask.csdn.net/upload/201808/24/1535099351_587376.png) 网关路由![图片说明](https://img-ask.csdn.net/upload/201808/24/1535099397_526124.png) network: ![图片说明](https://img-ask.csdn.net/upload/201808/24/1535099412_427241.png) 错误信息:![图片说明](https://img-ask.csdn.net/upload/201808/24/1535099424_768522.png)

外网访问时websocket报错404何解?

使用tomcat的websocket,但是出现用域名绑定后内网访问websocket成功,但是外网访问websocket后页面报错404,后台无报错,百度了下都说是tomcat7下的jar包冲突,但尝试了好像并不是这么回事...求大佬解救一下!!!!![图片说明](https://img-ask.csdn.net/upload/201909/27/1569575833_322304.jpg)

spring websocket +stomp 发送数据大于65536报错

https://segmentfault.com/a/1190000006617344 //这个是案例 https://segmentfault.com/a/1190000006617344//这个文档 现在就是调用这个方法发送数据到后台直接页面就报错了 client.send(destination, {}, body);// 后面的json数据内容太多 下面是报的错误 <Failed to parse TextMessage payload=[,6165,1284..], byteCount=16384, last=true] in session xlur_cla. Sending STOMP ERROR to client.> org.springframework.messaging.simp.stomp.StompConversionException: The 'content-length' header 129794 exceeds the configured message buffer size limit 65536

数据库连接报错!!!怎么修改

附上调试报告 怎么修改??? type Exception report message An exception occurred processing JSP page /WebContent/add.jsp at line 106 description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: An exception occurred processing JSP page /WebContent/add.jsp at line 106 103: 104: j=stmt.executeUpdate(); 105: }}catch(Exception e){} 106: conn.close(); 107: 108: 109: %> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:575) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause java.lang.NullPointerException org.apache.jsp.WebContent.add_jsp._jspService(add_jsp.java:189) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.69 logs.

尝试进行Websocket连接时出现意外的响应代码200

<div class="post-text" itemprop="text"> <p>Fairly new gopher here. Limited experience.</p> <p>I am going through a book that explores websockets and I hit a dead end. I have assembled a simple chat app with the examples from the book and when I run it I hit the following error:</p> <blockquote> <p>WebSocket connection to 'ws://localhost:5000/room' failed: Error during WebSocket handshake: Unexpected response code: 200</p> </blockquote> <p>Does anybody know what causes this?</p> <p>main.go</p> <pre><code>package main import ( "html/template" "log" "net/http" "path/filepath" "sync" ) type templateHandler struct { //once is an object that will perform exactly one action once sync.Once filename string templ *template.Template } func (t *templateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { //this function call will be executed only once t.once.Do(func() { t.templ = template.Must(template.ParseFiles(filepath.Join("templates", t.filename))) log.Println("one time") }) t.templ.Execute(w, nil) } func main() { http.Handle("/", &amp;templateHandler{filename: "chat.html"}) if err := http.ListenAndServe(":5000", nil); err != nil { log.Fatal("ListenAndServe", err) } } </code></pre> <p>client.go</p> <pre><code>package main //Notes on channels //read from channel x to a //a := &lt;- x //write 5 to channel x //x &lt;- 5 import ( "github.com/gorilla/websocket" ) //client represents a single chatting user. type client struct { //client represents a single chatting user socket *websocket.Conn //sent is a channel on which messages are sent send chan []byte //room is the room this client is chatting in room *room } func (c *client) read() { for { //if err is nil after the execution of ReadMessage() //execute the line between the braces if _, msg, err := c.socket.ReadMessage(); err == nil { c.room.forward &lt;- msg } else { break } } c.socket.Close() } func (c *client) write() { for msg := range c.send { if err := c.socket.WriteMessage(websocket.TextMessage, msg); err != nil { break } } c.socket.Close() } </code></pre> <p>room.go</p> <pre><code>package main import ( "log" "net/http" "github.com/gorilla/websocket" ) type room struct { //forward is a channel that holds incoming messages //that should be forwarded to other clients forward chan []byte //join is a channel for clients wishing to join the room join chan *client //leave is a channel for clients wishing to leave the room. leave chan *client //clients holds al the current clients in this room. clients map[*client]bool } func (r *room) run() { for { select { case client := &lt;-r.join: //joining r.clients[client] = true case client := &lt;-r.leave: //leaving delete(r.clients, client) close(client.send) case msg := &lt;-r.forward: //forward message to all clients for client := range r.clients { select { case client.send &lt;- msg: default: //failed to send delete(r.clients, client) close(client.send) } } } } } const ( socketBufferSize = 1024 messageBufferSize = 256 ) //in order for the browser to switch to the websocket //protocol a header with an upgrade request from http //to websocket must be sent var upgrader = &amp;websocket.Upgrader{ ReadBufferSize: socketBufferSize, WriteBufferSize: socketBufferSize, } func (r *room) ServeHTTP(w http.ResponseWriter, req *http.Request) { socket, err := upgrader.Upgrade(w, req, nil) if err != nil { log.Fatal("ServeHTTP:", err) return } client := &amp;client{ socket: socket, send: make(chan []byte, messageBufferSize), room: r, } r.join &lt;- client defer func() { r.leave &lt;- client }() go client.write() client.read() } </code></pre> <p>chat.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Chat&lt;/title&gt; &lt;style&gt; input {display:block;} ul{list-style:none;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;ul id="messages"&gt;&lt;/ul&gt; &lt;form id="chatbox"&gt; &lt;textarea&gt;&lt;/textarea&gt; &lt;input type="submit" value="Send" /&gt; &lt;/form&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt; &lt;/script&gt; &lt;script&gt; $(function(){ var socket = null; var msgBox = $("#chatbox textarea"); var messages = $("#messages"); $("#chatbox").submit(function(){ if (!msgBox.val()) return false; if (!socket) { alert("Error: There is no socket connection."); return false; } socket.send(msgBox.val()); msgBox.val(""); return false; }); if (!window["WebSocket"]) { alert("Error: Your browser does not support web sockets.") }else { socket = new WebSocket("ws://localhost:5000/room"); socket.onclose = function() { alert("Connection has been closed."); } socket.onmessage = function(e) { messages.append($("&lt;li&gt;").text(e.data)); } } }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> </div>

springboot整合没有batis启动报错!

我用springboot整合mybatis启动时报错,数据库用的是mysql! 这是我的yml配置文件: ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549001_22080.png) ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549042_774378.png) 启动时报的错误: ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549097_455256.png) 之后我上网百度了一下,有人说是springboot的启动项里少加了一个(exclude=DataSourceAutoConfiguration.class) ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549181_300854.png) 加上之后再运行,就报如下错误了: ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549250_447681.png) ![图片说明](https://img-ask.csdn.net/upload/201907/08/1562549260_480467.png) 有哪位大神可以为我解答一下?

.net websocket 实现 报错

Error during WebSocket handshake: Unexpected response code: 200 chrome控制台报的错误 action代码 ``` public HttpResponseMessage T() { if (System.Web.HttpContext.Current.IsWebSocketRequest) { System.Web.HttpContext.Current.AcceptWebSocketRequest(ProcessWSChat); } return new HttpResponseMessage(HttpStatusCode.SwitchingProtocols); //return View(); } private async Task ProcessWSChat(AspNetWebSocketContext context) { System.Net.WebSockets.WebSocket socket = context.WebSocket; while (true) { //ArraySegment<byte> buffer = new ArraySegment<byte>(new byte[1024]); //WebSocketReceiveResult result = await socket.ReceiveAsync( // buffer, CancellationToken.None); if (socket.State == WebSocketState.Open) { //string userMessage = Encoding.UTF8.GetString( // buffer.Array, 0, result.Count); string userMessage = DateTime.Now.ToString(); ArraySegment<byte> buffer = new ArraySegment<byte>( Encoding.UTF8.GetBytes(userMessage)); await socket.SendAsync( buffer, WebSocketMessageType.Text, true, CancellationToken.None); } else { break; } } } ``` js代码 ``` <script type="text/javascript"> var serverData,statusDiv,ws; //var SERVER_URL = "/Dou/T"; window.onload = function () { ws = new WebSocket("ws://" + window.location.host + "/Sun/T"); serverData = document.getElementById("serverData"); statusDiv = document.getElementById("statusDiv"); startlistenServer(); } function startlistenServer() { statusDiv.innerHTML="Start Connect Server..."; //var es = new EventSource(SERVER_URL); ws.onopen = openHandler; ws.onerror = errorHandler; ws.onmessage = messageHandler; } function openHandler(e) { statusDiv.innerHTML = "Server Open<br>"; } function errorHandler(e) { statusDiv.innerHTML = "Error<br>"+e.message; } function messageHandler(e) { serverData.innerHTML = e.data; } </script> ```

autobahn android使用WebSocket 报错

我在做一个Android项目中用到了websocket,使用了autobahn-android.jar包,但是在建立连接之后报了错误。 ``` D/de.tavendo.autobahn.WebSocketReader: run() : WebSocketException (de.tavendo.autobahn.WebSocketException: RSV != 0 and no extension negotiated) D/de.tavendo.autobahn.WebSocketReader: ended D/de.tavendo.autobahn.WebSocketConnection: opening handshake received D/de.tavendo.autobahn.WebSocketConnection: fail connection [code = 4, reason = WebSockets protocol violation ``` 我查看了错误地点并且看了源码,错误发生在WebSocketReader的processData处,源码为: ``` if (mFrameHeader == null) { // need at least 2 bytes from WS frame header to start processing if (mFrameBuffer.position() >= 2) { byte b0 = mFrameBuffer.get(0); boolean fin = (b0 & 0x80) != 0; int rsv = (b0 & 0x70) >> 4; int opcode = b0 & 0x0f; byte b1 = mFrameBuffer.get(1); boolean masked = (b1 & 0x80) != 0; int payload_len1 = b1 & 0x7f; // now check protocol compliance if (rsv != 0) { throw new WebSocketException("RSV != 0 and no extension negotiated"); } ...(省略) ``` 背景: 服务端我使用了Spring+SpringMVC+Hibernate框架,并且搭建了WebSocket的服务端,在Web版本使用JavaScript连接WebSocket正常,地址保证没有任何问题。 探索: 遇到这个问题之后我百度&Google了很久,发现有GitHub和StackOverflow不少人提出来这个问题,但都没有得到有效解决,看了半天感觉靠谱的回答说是autobahn支持websocket版本的问题,,但是并没有给出行之有效的解决方法。我使用的WebSocket是Java7及以上自带的javax.websocket里面的方法,也没有具体的版本说明,希望做过或者了解的大神能够解答一下疑惑。是因为版本的问题么?如果是应该使用什么版本的WebSocket?如果不是,是因为什么原因导致的,应该如何解决呢? 先感谢阅读。

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

你以为这样写Java代码很6,但我看不懂

为了提高 Java 编程的技艺,我最近在 GitHub 上学习一些高手编写的代码。下面这一行代码(出自大牛之手)据说可以征服你的朋友,让他们觉得你写的代码很 6,来欣赏一下吧。 IntStream.range(1, 5).boxed().map(i -&gt; { System.out.print("Happy Birthday "); if (i == 3) return "dear NAME"...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

立即提问
相关内容推荐