基于注解的DI-Spring的JUnit4测试
添加jarspring-test-4.2.1.RELEASE.jar
package com.hk.spring.di01; import javax.annotation.Resource; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) //classpath:com/hk/spring/di01/applicationContext.xml指明类路径 @ContextConfiguration(locations="classpath:com/hk/spring/di01/applicationContext.xml") public class Mytest { @Resource private Student student; @Test public void test1(){ System.out.println(student); } }