Spring In Action-2.1-01-@Component注解
package soundsystem; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class)//Spring的Junit测试,会在测试开始时,创建Spring的应用上下文 @ContextConfiguration(classes=CDPlayerSpringConfig.class)//表明配置类 public class SpringTest1 { //自动装配 @Autowired private SgtPeppers sp; @Test public void instanceSpring(){ sp.play(); } }