There are many problems in spring boot unit test. When I use websocket, I will run the test class and report an error: error creating bean with name ‘serverendpoint exporter’ defined in class path resource [COM/Jacklin/config]/ WebSocketConfig.class ]Here I introduce the annotation @ serverendpoint:
There are two ways to solve this problem
Method 1: remove the @ runwith of the test class（ SpringRunner.class ）, but this method will have limitations. For example, when you want a @ authwired class below, you will report an error. I can’t do it here, according to your code situation.
The second way: add webenvironment after springboottest= SpringBootTest.WebEnvironment.RANDOM_ Port means to create a web application context (response based or servlet based). Reason: websocket depends on the startup of Tomcat and other containers. So in the process of testing, we need to really start a Tomcat as a container.
Run after adding, no more error!!
- [spring] start error: nosuchmethoderror: javax.servlet.http . HttpServletResponse.getStatus () I
- Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded (How to Fix)
- Exception of browser accessing servlet404
- Possible causes and solutions of 404 problems in accessing servlet pages
- org.apache.jasper . jasperexception: unable to compile class for jsp: error resolution
- Linux Tomcat accessing files on the server
- Server Tomcat v7.0 server at localhost failed to start
- java.lang.IllegalStateException Exception: cause analysis and solution
- solve java.net.SocketException : Unrecognized Windows Sockets error: 0: JVM_ Bind
- Problems of accessing servlet display 404 on MyEclipse
- When feign is called, the solution of request method ‘post’ not supported appears
- stay web.xml Configure error page in
- Spring jacjson version conflict “nosuchme” thodError:com.fasterxml.jackson.databind.ObjectMapper.canSerialize “
- Annotations are not allowed here
- Error creating bean with name ‘datasource’ defined in class path resource
- Request cannot get static resource
- WebSocket handshake Unexpected response code 403
- Tomcat opens the startup.bat The reason for the flash
- Maven project running servlet jump JSP error: HTTP status 500 – unable to compile class for JSP
- Server Tomcat v8.0 Server at localhost failed to start.