1.引入依赖
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
2.添加两个注解,初始化spring容器
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class Demo1 {
@Autowired
Person pp;
@Test
public void test(){
pp.name = "haha";
pp.age = 12;
System.out.println(pp.name+":"+pp.age);
}
}