log4j没在src根目录下 而是在src/res里面出现下面情况
log4j:ERROR Ignoring configuration file [log4j.properties]. log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
解决:
在测试类中添加
import org.apache.log4j.PropertyConfigurator;
以及
@BeforeClass public static void setup() { PropertyConfigurator.configure("src/res/log4j.properties"); }
然后就解决了
test代码
import org.junit.BeforeClass; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.wy.dao.CustomerDao; import com.wy.po.Customer; import org.apache.log4j.PropertyConfigurator; public class DaoTest { @BeforeClass public static void setup() { PropertyConfigurator.configure("src/res/log4j.properties"); } @Test public void findCustomerByIdDaoTest() { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("res/applicationContext.xml"); CustomerDao customerDao = (CustomerDao) applicationContext.getBean("customerDao"); Customer customer = customerDao.findCustomerById(1); System.out.println(customer); } }