在测试单元/类中不能使用自动装配(@Autowired)
测试类通常采用Junit测试,与tomcat无关,是两个运行环境
如果需要采用注解:
对于SSM,需要加上注解spring配置文件和启动类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/springMVC.xml")
对于SpringBoot:需要加上注解表明SpringBoot的测试,加上启动类
@SpringBootTest
@RunWith(SpringRunner.class)
在测试单元/类中不能使用自动装配
最新推荐文章于 2024-08-22 11:01:05 发布