spring - 在@WebMvcTest 中指定@SpringBootApplication
问题描述
Using将通过查找类(例如)@WebMvcTest
来自动配置所有 Web 层 bean 。@SpringBootConfiguration
@SpringBootApplication
如果配置类在不同的包中,扫描找不到,可以直接提供给@WebMvcTest
吗?
解决方案
以下将指向正确的@SpringBootApplication
类:
@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(controllers = {MyController.class})
@ContextConfiguration(classes={MySpringBootApplicationClass.class})
public class MyControllerTest {
//...
}
推荐阅读
- firebase - 使用分页器时更新材料表的问题
- php - 从购物车页面上的产品缩略图中删除链接
- javascript - 禁用其中一个包含任何值的
- html - 悬停图像上的 CSS 动画效果不起作用
- vue.js - Vue Router 模仿原生移动标签和历史堆栈
- url-parameters - 货币兑换 API 中的逗号?
- mysql - 如果不进行第二次查询,是否可以知道是什么 UPDATE "WHERE" 语句导致不更新?
- python - 当我使用 which python 时,python 有两个单独的路径
- javascript - 如何对带有解构 props 的组件进行测试?
- c# - 如何从 Unity AssetBundle 获取哈希以检查缓存?