1.测试类需要继承 AbstractJUnit4SpringContextTests类

2.测试类上边添加注解

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml")

3.即可注入组件测试

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext-*.xml")
public class UserServiceTest extends AbstractJUnit4SpringContextTests{

	@Autowired
	private UserService userService;
	
	@Test
	public void test() {
		List<User> list = this.userService.findAll();
		System.out.println(list);
	}

}

相关文章:

  • 2021-11-17
  • 2021-06-05
  • 2022-12-23
  • 2021-11-08
  • 2021-11-02
  • 2022-12-23
  • 2021-07-08
  • 2021-09-21
猜你喜欢
  • 2021-10-01
  • 2021-10-07
  • 2021-10-20
  • 2021-12-22
  • 2021-12-04
  • 2021-04-20
  • 2021-08-11
相关资源
相似解决方案