package com.xiuye.bean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.xiuye.component.CarComponent;
public class Car {
private CarComponent wheels;
private CarComponent steer;
private CarComponent engine;
@Autowired
@Qualifier("carWheelComponent")
public void setWheels(CarComponent wheels) {
this.wheels = wheels;
}
@Autowired
@Qualifier("carSteerComponent")
public void setSteer(CarComponent steer) {
this.steer = steer;
}
@Autowired
public void setEngine(CarComponent engine) {
this.engine = engine;
}
public void configInfo(){
this.steer.description();
this.wheels.description();
this.engine.description();
}
}
package com.xiuye.test;
import javax.annotation.Resource;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.xiuye.bean.Car;
import com.xiuye.component.ComponentForStudent;
import com.xiuye.component.ComponentForStudent2;
import com.xiuye.config.BeanConfiguration1;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes=BeanConfiguration1.class)
@ActiveProfiles("dev")
public class TestMain {
@Resource
private ComponentForStudent cfs;
@Resource
private ComponentForStudent2 cfs2;
@Resource
private Car car;
@BeforeClass
public static void envConfig(){
System.setProperty("test","true");
}
@Test
public void testCfs(){
cfs.studentInfo();
}
@Test
public void testCfs2(){
cfs2.studentInfo();
}
@Test
public void testCar(){
this.car.configInfo();
}
}
十一月 12, 2016 1:06:39 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames
信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
十一月 12, 2016 1:06:39 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper instantiateListeners
信息: Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]
十一月 12, 2016 1:06:39 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
信息: Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@133c8f8, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1a25848, org.springframework.test.context.support.DirtiesContextTestExecutionListener@c3fd8b, org.springframework.test.context.transaction.TransactionalTestExecutionListener@194a1b5, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@5fc7f7]
十一月 12, 2016 1:06:39 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@25790e: startup date [Sat Nov 12 13:06:39 CST 2016]; root of context hierarchy
Active profile := dev
test := true
I'm car's steer!
I'm car's wheels!
I'm car's engine!