zoukankan      html  css  js  c++  java
  • Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

    springboot整合websocket,测试类启动报错,

    解决方式:在注解中加上webEnvironment参数,此参数的含义,参看官方文档

    You can use the webEnvironment attribute of @SpringBootTest to further refine how your tests will run:

    • MOCK — Loads a WebApplicationContext and provides a mock servlet environment. Embedded servlet containers are not started when using this annotation. If servlet APIs are not on your classpath this mode will transparently fallback to creating a regular non-web ApplicationContext. Can be used in conjunction with @AutoConfigureMockMvc for MockMvc-based testing of your application.
    • RANDOM_PORT — Loads an ServletWebServerApplicationContext and provides a real servlet environment. Embedded servlet containers are started and listening on a random port.
    • DEFINED_PORT — Loads an ServletWebServerApplicationContext and provides a real servlet environment. Embedded servlet containers are started and listening on a defined port (i.e from your application.properties or on the default port 8080).
    • NONE — Loads an ApplicationContext using SpringApplication but does not provide any servlet environment (mock or otherwise).

    有4个value可选,根据需要选择即可,其实就是给你的测试类配置了一个真实的servlet环境,并且给这个启动的嵌入式servlet容器一个端口进行监听;

    如此就可以结果websocket无法获取的问题

    @SpringBootTest(classes = XXX.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  • 相关阅读:
    WPF中的控件布局
    [转]WPF, WPF/E释疑
    创建像Vista任务栏一样的半透明玻璃按钮
    WPF中的TextBlock
    .net 2.0 文档生成工具
    XNA Game Studio Express 1.0正式版 发布
    WPF免费视频教程,来自Lynda.com
    WPF中的ControlTemplate(控件模板)
    获奖啦, 微软亚洲研究院第九届学生实践项目
    [转]让用户通过宏和插件向您的 .NET 应用程序添加功能
  • 原文地址:https://www.cnblogs.com/bin-zhao/p/14046880.html
Copyright © 2011-2022 走看看