spring - 不使用弹簧启动的测试中的 DI (@SpringBootTest)
问题描述
从 spring boot 切换回“正常” spring,因为该应用程序仅使用一些 jdbc 代码“upsert”到 postgresql 数据库中。
1)
尝试用以下方法注释测试类:
@RunWith(SpringJUnit4ClassRunner.class)
public class DBIntegration {
results in:
java.lang.IllegalStateException: Failed to load ApplicationContext
2)
尝试用以下方法注释类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {})
public class DBIntegration {
[main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [de.mydomain.myproject.DBIntegration]: no resource found for suffixes {-context.xml}.
No exceptions, but java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=insertDataFrom_sometest],
3)尝试用以下方法注释类:
@Component
public class DBIntegration {
dependency injection does not work in this case, the expected service
(to be injected) throws a nullpointerexception
解决方案
推荐阅读
- firebase - 在使用 firebase 动态链接时,我是否需要为电子商务应用中的每个产品手动创建动态链接?
- javascript - 当我在数据表中添加按钮(打印)时,lengthChange 不显示
- dart - text justify 不能与 RichText 一起正常工作
- python - 双击将 txt 文件添加到自定义 PyQt 编辑器
- android - 预期为 BEGIN_OBJECT,但在第 1 行第 1 列路径为 STRING - Laravel 到改造 2
- php - 下单成功后更改第 n 个订单的用户角色
- html - 如何从后端 Django MarkdownX 渲染到 Vue.js 前端的 html?
- google-chrome - 添加到主屏幕迷你信息栏未在某些设备上显示
- c - 在 C 中标记 URL
- reactjs - 为什么我会在以下代码中收到 writetostore 错误?