利用Spring的JUnit4进行测试
不需要再显式创建Spring容器和getBean

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class MyTest {
    @Autowired//byType
    private School school;
    @Autowired
    private Student student;

    @Test
    public void test01() {
        System.out.println(school);
        System.out.println(student);
    }

}

相关文章:

  • 2021-04-10
  • 2021-06-19
  • 2021-07-09
  • 2021-08-10
  • 2022-12-23
  • 2021-09-27
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2022-02-03
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案