-------------------------------------------------------
Running cn.itcast.crm.service.impl.CustomerServiceImplTest
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.6 sec <<< FAILURE!
test(cn.itcast.crm.service.impl.CustomerServiceImplTest) Time elapsed: 0.02 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
解决方法,把你的测试类里面的方法注释掉,比如:
package cn.itcast.crm.service.impl;
import static org.junit.Assert.*;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import cn.itcast.crm.dao.CustomerDao;
import cn.itcast.crm.entity.Customer;
import cn.itcast.crm.service.CustomerService;
//@ContextConfiguration(locations={"classpath:applicationContext-service.xml","classpath:applicationContext-dao.xml"})
@ContextConfiguration(locations="classpath*:applicationContext-*.xml")
//classpath*从jar包里面加载:applicationContext-*.xml读取所有的配置文件
@RunWith(SpringJUnit4ClassRunner.class)
public class CustomerServiceImplTest {
/*@Test
public void test() {
//1.从spring容器中获取Dao
ApplicationContext app = new ClassPathXmlApplicationContext("classpath:applicationContext-dao.xml");
CustomerDao cd = (CustomerDao) app.getBean("customerDao");
Customer c = cd.findById(23L);
System.out.println("*****"+c.getCustName());
}*/
@Autowired
private CustomerService cs;
@Test
public void test() {
//1.从spring容器中获取Dao
/* Customer c = cs.findById(1L);
System.out.println("*****"+c.getCustName());*/
}
}
在上面的测试类中注释掉
//1.从spring容器中获取Dao
/* Customer c = cs.findById(1L);
System.out.println("*****"+c.getCustName());*/
这样就不会运行测试的方法.
同时需要你更新maven索引库,这样就可以使用.