SpringBoot测试类注入Bean失败原因
首先针对SpringBoot的测试类,2.2版本之前和2.2版本之后是不一样的,在2.2版本之前需要贴注解@SpringBootTest和@RunWith(SpringRunner.class)需要在Spring容器环境下进行测试,因为@Test导包的是org.junit.Test,而 在2.2版本之后只需要贴注解@SpringBootTest,@Test导包为org.junit.jupiter.api.Test
注意测试类的包名和启动类的包名一定要一致,否则扫描不到bean对象会报空异常,如下图:

SpringBoot测试类注入Bean失败原因的更多相关文章
- SpringBoot集成spring-data-jpa注入Bean失败
当项目结构正常(spring管理的Bean在SrpingBoot启动类平级或下级,支持spring扫描时),实现类上加 @Service注解,在实现类中注入dao层的Bean时,项目无法启动,无法找到 ...
- SpringBoot测试类启动错误 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
报错 java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Cont ...
- Springboot 测试类没有找到bean注入
其他乱七八糟配置就不扯了,先上项目结构图 配置好参数后我再src/test/java类测试访问数据库时发现bean没有正确的注入.值得注意的是,这个项目的启动类是叫App.java 所以我们必须在这个 ...
- SpringBoot环境下使用测试类注入Mapper接口报错解决
当我们在进行开发中难免会要用到测试类,而且测试类要注入Mapper接口,如果测试运行的时候包空指针异常,看看测试类上面的注解是否用对! 正常测试我们需要用到的注解有这些: @SpringBootTes ...
- JPA实体类注解、springboot测试类、lombok的使用
前提准备: 搭建一个springboot项目,详情请参见其它博客:点击前往 1 引入相关依赖 web.mysql.jpa.lombok <?xml version="1.0" ...
- IntelliJ IDEA 2017版 SpringBoot测试类编写
SpringBoot的测试类编写Demo 源码见 https://github.com/liushaoye/baseone.git
- springboot测试类
Controller测试类 /** * Created by zhiqi.shao on 2017/5/12. */ @RunWith(SpringJUnit4ClassRunner.class) @ ...
- springboot 测试类,项目使用shiro时报错UnavailableSecurityManagerException
大概的问题就是,正常运行项目是没有问题的 使用测试类是,加载不了shiro的securityManager,主要导致不是很清楚,望告知, 解决方法 @Resource org.apache.shiro ...
- springboot 测试 有注入HttpSession的bean
question: nested exception is java.lang.IllegalStateException: No thread-bound request found: Are yo ...
- Springboot测试类之@RunWith注解
@runWith注解作用: --@RunWith就是一个运行器 --@RunWith(JUnit4.class)就是指用JUnit4来运行 --@RunWith(SpringJUnit4ClassRu ...
随机推荐
- jwt二次加密失败原因(Bad “options.expiresIn“ option the payload already has an “exp“ property.)
在写vue+nodejs项目的校验token时,出现了次错误 然后想了想问题所在: 第一次加密的时候使用jwt.sign(value,秘钥,{}),会返回一个字符串,然后当前端跳转别的发送请求时,会将 ...
- 记录一次在deepin安装node版本管理工具nvm的过程
安装nvm sudo apt-get install git -y # 安装git cd /home # 随便找个目录放代码 git clone https://github.com/nvm-sh/n ...
- csp-s2020 T2 动物园
题目简述: 共有n个动物,m条要求,每条要求描述了第x位上是1的话,必须购买y饲料,动物园里已有的动物必须的饲料已经购买了,问题是:在不要求增加购买饲料的基础上,还能放进去多少种动物?共有k个二进制, ...
- 【git】7.5 git工具-搜索
资料来源: (1) https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E6%90%9C%E7%B4%A2 1.git grep 注1:使用g ...
- WPF BackSpace 回退到上一个页面
在Wpf程序中,有时候点击到某些控件后,再按下[BackSpace]键,画面会回到上一个 TextBox可能自己处理了,所以没有这一个现象. 解决方案是: 在App.xaml.cs 的 Initial ...
- html元素全屏展示
参数传入dom对象即可,注意不是jQuery对象,Vue下兼容 /** * 面板全屏展示 */ fullscreen: function () { if (this.isFullScreen) { / ...
- zabbix5.2+mysql+ubuntu20.4
服务端 0.初始化机器 1.mysql安装 # apt-get install mysql-server # apt update 根据提示一步一步确认,要求输入的密码是创建管理员的密码 2.安装za ...
- base64 转图片
data:image+jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcg% ...
- viewport适配解决方案
viewport的单位vw.vh vw.vh将viewport分成了一百份.vw即 viewport width vh即viewport height 1vw等于视图单位的1%的宽度 1vh等于视图单 ...
- 关闭 Microsoft Compatibility Telemetry
Microsoft Compatibility Telemetry可能会导致操作系统(Win10)启动后一直读盘,打开任务管理器可能会看到 Microsoft Compatibility Teleme ...