Spring 集成 Junit

1.引入依赖



    org.springframework
    spring-test
    5.0.5.RELEASE
    test

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);
    }
}

 

你可能感兴趣的:(java,Spring,junit)