SSM学习之路——spring第二天_spring和junit的整合
原因: 一、在pom.xml中添加依赖 添加此依赖,注意版本号要和spring-context的版本号相同 < dependency > < groupId > org.springframework </ groupId > < artifactId > spring-test </ artifactId > < version > 5.0.2.RELEASE </ version > </ dependency > 添加junit依赖,注意这里一定要是4.12以上版本,不然会出错 < dependency > < groupId > junit </ groupId > < artifactId > junit </ artifactId > < version > 4.12 </ version > </ dependency > 二、修改测试类 1、在类上面添加注解,注意ContextConfiguration里,要添加classpath: 2、自动注入IAccountService类对象 @RunWith ( SpringJUnit4ClassRunner . class ) @ContextConfiguration ( locations = "classpath:bean.xml" ) public class AccountServiceTest {