SpringBoot中使用WebSocket后单元测试报错的解决方案

SpringBoot与WebSocket遇到 javax.websocket.server.ServerContainer not available不可用 除了springboot和tomcat的,还有一个io.undertow.servlet.spec的实现类,这就找到了问题了,估计就是依赖冲突造成springboot在加载的时候加载了错误的ServletContext实现类导致的,搜索了一下果然有一个。断点停在了initServletContext方法,在这我们可以看到因为ServletContext为空,所以就给它设置了空值,但ServletContext为什么会为空呢,我们点进去看一下。版权所有:XuanRan。 阅读详情

使用了websocket后单元测试全部报错:
Failed to load ApplicationContext
Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerCon

解决方案:
SpringBootTest增加webEnvironment 参数。

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

1
原因:
由于测试环境下,没有websocket环境,所以测试的时候需要注释掉;正常启动的时候取消注释就可以了,也可以把websocket的config写成根据不同配置选择是否加载的,让他判断如果是test环境,也不加载websocket

Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available产生原因 在项目部署时需要将代码打包放到服务器上,打包的时候报了如下的错误,但是在idea上却是能正常运行的。 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelega... 阅读详情

相关推荐

SpringBoot启动单元测试报错javax.websocket.server.ServerContainer not available

在运行SpringBoot单元测试时,出现以下报错 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverEndpointExporter' defined in class path resource [X

123 8388

SpringBoot 整合websocket 测试出错

问题描述 javax.websocket.server.ServerContainer not available 问题起因 一般情况下,使用@SpringBootTest后,Spring将加载所有被管理的bean,基本等同于启动了整个服务,此时便可以开始功能测试。 由于web服务是最常见的服务,且我们对于web服务的测试有一些特殊的期望,所以@SpringBootTest注解中,给出了webEnvironment参数指定了web的environment,该参数的值一共有四个可选值: MOCK:此值为默

Lopka的博客 1768

【异常】IDEA中执行单元测试后提示IllegalStateException: javax.websocket.server.ServerContainer not available

经查阅资料,得知SpringBootTest在启动的时候不会启动服务器,所以WebSocket自然会报错。代码中使用了POM文件spring-boot-starter-websocket,用于统计实时人数。这个时候需要添加选项webEnvironment,以便提供一个测试的web环境。

奶爸的编程之路,也就一周冷个三天 2157

Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

websocket导致spring boot 项目单元测试启动失败的问题解决 在单元测试时,项目启动报错 Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available at org.springframework.util.Assert.state(Assert.java:76) at org.springframework.web.socket.server.standa

weixin_43811057的博客 2453

专栏丨华为HN8145XR光猫获取超级管理员密码

摘要:本文详细介绍了华为HN8145xr光猫获取超级管理员权限的完整步骤。首先通过ONT使能工具补全shell,然后利用Telnet登录光猫后台进行操作。文章提供了多种获取超级密码的方法,包括配置文件解密、一键查询工具等,并针对联通光猫特别说明了默认密码格式(CUAdmin+后八位数字)。此外,还介绍了恢复出厂设置、修改SSID等实用操作,帮助用户完全掌控光猫设备。文末附有详细的命令行操作指南,适合有一定技术基础的用户参考。

8265

从零到一:RT-Thread与W5500的硬件抽象层设计哲学与实践启示

本文深入探讨了RT-Thread操作系统下W5500以太网模块的硬件抽象层(HAL)设计哲学与实践。通过GD32F103和STM32F103平台的适配案例,详细阐述了如何利用RT-Thread的驱动框架实现跨平台硬件无关性、模块化设计及配置定制,为嵌入式开发者提供了可复用的HAL设计方法论和实战经验。

7z8x2c4v6b9的博客 197

springboot项目之websocket的坑:spring整合websocket后进行单元测试后报错的解决方案

前排提醒:还是博主菜,见识短浅,没遇到过这个问题。。。

m0_56426418的博客 1352

8.5/Q1,Charls最新高分文章解读!

8 257名受试者中,672人(8.14%)在9年内发生过卒中。在调整的多因素cox回归模型中,TyG和ABSI仍然是卒中的预测因素,TyG的HR为1.25(95%CI:1.06~1.47),ABSI的HR为1.33(95%CI:1.06~1.68)。TyG和ABSI联合诊断效能最高(AUC:0.579,95%CI:0.553~0.597),而TyG(AUC:0.566,95%CI:0.544~0.587)和ABSI(AUC:0.533,95%CI:0.524~0.597)的诊断效能最低。

gsky_sci的博客 1015

SpringBoot集成WebSocket,单元测试执行报错

SpringBoot集成了WebSocket,单元测试启动后会报如下错误:javax.websocket.server.ServerContainer not available,这是因为SpringBootTest启动时不会启动服务器,所以WebSocket会报错。

席木木的博客 623

伺服电机开发实战指南

伺服电机作为工业自动化的核心部件,正经历前所未有的技术革新。本文从基础原理出发,详细介绍了伺服电机的分类、工作原理和特性,分析了伺服电机系统组成与核心部件,探讨了企业级开发技术,包括控制算法、通信协议和故障诊断等高级功能,并提供了实战案例分析,从行业应用到具体开发步骤,展示了伺服电机的工程实现。通过深入理解伺服电机的原理、掌握开发技术、学习应用案例,可以实现伺服系统的高性能开发与应用。

全栈 1680

《遥感大模型生产级实战:从数据到决策的端到端AI工程》系列第一部分:AI遥感工程师的基础设施与工具链-文章 4:传统遥感分析与机器学习基线

本章将系统性地介绍经典遥感分析工作流,从数据预处理到多维度特征工程,再到如何利用经典的机器学习模型(如随机森林、支持向量机)进行监督与非监督学习。我们将通过一个完整的“智慧农业作物分类”项目实战,展示如何利用我们之前构建的数据湖和工具链,从原始数据到最终的分析结果,构建一个性能可靠、可解释性强的基线系统。更重要的是,我们将深入剖析这种传统方法的局限性,从而为后续章节引入遥感大模型的必要性提供强有力的论证。

panshengwu的博客 705

Java21 + SpringBoot3使用spring-websocket时执行mvn package报错

近日心血来潮想做一个开源项目,目标是做一款可以适配多端、功能完备的模板工程,包含后台管理系统和前台系统,开发者基于此项目进行裁剪和扩展来完成自己的功能开发。本项目为前后端分离开发,后端基于Java21和开发,前端提供了vue、angular、react、uniapp、微信小程序等多种脚手架工程。但在使用过程中遇到了一些问题,于是在此记录下来与诸位分享。

zzcoder的博客 1365

文献阅读笔记:量子微波测量技术综述

量子微波测量技术研究进展:量子微波测量技术利用里德堡原子与微波电场的相干相互作用,突破了传统测量方法的物理限制。该技术基于电磁诱导透明效应和里德堡原子能级跃迁原理,通过激光激发原子并监测光谱变化来测量微波电场强度。相比传统方法,量子微波测量具有超高灵敏度(理论极限可达nV/cm)、宽动态范围(超过100dB)、小型化等显著优势,且测量结果可直接溯源至普朗克常数。典型实验系统包括光源、原子气室和探测器,采用光谱法、干涉法等多种测量方法。近年来,该技术在基础研究和应用方面取得重要进展,展现出在通信、雷达、计量等

Grow into a more wonderful you 988

javax.websocket.server.ServerContainer not available

置顶个交流群 文章觉得海星的话,可以来群里找桃子交流技术或者普通乱聊= = 挂群: 820080257 1 问题 springboot 单元测试报错: javax.websocket.server.ServerContainer not available 2 流程 单元测试类的原注解是这样的: @RunWith(SpringRunner.class) @SpringBootTest 经查阅资料,得知SpringBootTest在启动的时候不会启动服务器,所以WebSocket自然会报错,这个时候需要添

Lewis的博客 2178

VS Code + EIDE + Clangd 构建 Keil/MDK 嵌入式开发新范式

嵌入式C/C++开发长期受限于传统IDE的语法理解弱、导航卡顿、跨工程复用难等问题。Clangd作为基于AST的现代语言服务器,结合EIDE对Keil uVision和ARM MDK工程文件(.uvprojx)的深度解析能力,可将编译配置、芯片型号、内存模型、扩展关键字等语义精准翻译为标准compile_commands.json,从而实现智能跳转、宏展开识别、结构体实时展开等高阶编辑体验。该方案不替换Keil/MDK编译与烧录流程,仅升级代码理解层,天然兼容STC8051、STM32 Cortex-M、G

weixin_34321753的博客 353

遥感生态指数(RSEI)——四个指数的计算

遥感生态指数是在4个生态指数的基础上通过主成分变换得出的一个评价生态环境质量的指标。因此,第二部分就是要分别计算出这4个指数的值。 ①首先,是绿度指数的计算,一般用归一化植被指数(NDVI) NDVI=(NIR-Red)/(NIR+Red) 在Bandmath工具中输入NDVI计算公式 (float(b4-b3))/(b4+b3) 其中,b3、b4分别是红波段和近红外波段 ②其次,是湿度计算。 WET = c1B1 + c2B2 + c3B3...

qq_41978498的博客 9万+

黑马:苍穹外卖Day5:webSocket 组件测试报错解决方案

这个并不是我们的代码出现了问题,而是boot 单元测试本身的问题。1.去掉注解 @SpringBootTest。

L982653的博客 396

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

springboot项目引入websocket之后使用单元测试报错报错

springboot项目引入websocket之后使用单元测试报错报错 在@springBootTest注解内加入 webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT

BZZZZZZZZO的博客 281

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

spring boot在运行测试类Error creating bean with name ‘serverEndpointExporter‘ defined...问题解决方案

在spring boot单元测试的时候会遇到很多问题,我在使用websocket的时候会运行测试类,报错: Error creating bean with name 'serverEndpointExporter' defined in class path resource [com/Jacklin/config/WebSocketConfig.class] ,我这里引入了注解@ServerEndPoint: 解决的方式有两种: 第一种方式:去掉测试类的@RunWith(SpringRunner.c

gb4215287的博客 4262

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

spring boot 运行单元测试时,websocket报错

spring boot 运行单元测试时,websocket报错 SpringBootTest增加webEnvironment 参数: package com.hengyun.admin; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.Sp...

lwy572039941的博客 3475

Springboot 项目中引入WebSocket后,单元测试出现错误

前端CSS面试题文档,JavaScript面试题文档,Vue面试题文档,大厂面试题文档,需要的读者可以戳这里获取!需要的读者可以戳这里](https://bbs.csdn.net/topics/618191877)获取!**[外链图片转存中…(img-X629EKfs-1712956323221)][外链图片转存中…(img-qDprrNzS-1712956323222)]

2303_79056168的博客 1005

SpringBoot单元测试报错“Error creating bean with name ‘serverEndpointExporter‘ ”

的bean时出错,而这个bean是webscoket中的,而webscoket是需要依赖tomcat等容器才能启动的,恰巧运行单元测试不需要依赖tomcat容器,两者互相矛盾这就是出现该问题的原因了。在SpringBoot中使用单元测试时,出现以下报错,意思是创建名为‘serverEndpointExporter’的bean时出错。使用tomcat容器运行单元测试,在注解。通过报错提示可以看出,在创建命名为 ‘

weixin_45151960的博客 3930

SpringBoot单元测试报错javax.websocket.server.ServerContainer not available

SpringBootTest单元测试

weixin_53251671的博客 1077

若依SpringBoot添加单元测试类及测试类启动报错

在springbootTest注解加入 webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,我们在测试使用 websocket的时候需要启动一个完整的服务器,而使用这个注解就是说每次测试都会选用一个随即可用的端口模拟启动一个完整的服务器。在 src 目录下创建 test.java.mainTests 文件。将以下依赖添加到 admin 的 pom.xml 中。在admin 模块中添加单元测试。

天天++的博客 2761

SpringBoot2.0整合WebSocket后JUnit单元测试报错:javax.websocket.server.ServerContainer not available

整个程序运行时是不报错的,但是单元测试就会报错。 解决办法: 在单元测试的类上加上注解: @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) 这里的Application是你SpringBoot启动类的类名。 这里注解的作用是提供一个se...

唐流雨的博客 3137

解决:javax.websocket.server.ServerContainer not available 报错问题

该方法是 服务器端点出口,当进行 SpringBoot 单元测试时,并没有启动服务器,所以当加载到这个bean时会报错。

m0_62645012的博客 5716
上一篇: 后端怎么偷懒快速高效去写一些前端的代码
下一篇: 大学四年java学习的经验及心得体会
JavaPorter
博客等级 码龄7年 10粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值