开发者社区> 问答> 正文

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 746 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>多谢大神!这个问题我费老鼻子劲了。不过我查了一下 也没找到怎么解决 websocket配置的问题。</p>
    
    2020-06-07 17:20:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载