开发者社区 问答 正文

spring-boot-test测试时出现不能创建bean的问题?报错

最近使用spring-boot写项目,集成了spring-boot-starter-websocket和spring-boot-starter-test;

websocket配置如下

@Configuration
public class WebSocketConfig {
    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }
}

正常运行spring-boot时websocket不报错

但是使用单元测试的时候报错

Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/xgh/WebSocketConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

去掉websocket的配置,单元测试正常,有没有比较好的解决办法,

单元测试中能不能指定不加载websocket相关的bean呢?

展开
收起
爱吃鱼的程序员 2020-06-07 17:20:12 830 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>多谢大神!这个问题我费老鼻子劲了。不过我查了一下 也没找到怎么解决 websocket配置的问题。</p>
    
    2020-06-07 17:20:27
    赞同 展开评论