log4j没在根目录下如何解决

目录

解决:

在测试类中添加

以及

然后就解决了​编辑

 test代码


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);
		
	}
}
我的其他博客

HTTP与HTTTPS的区别-CSDN博客

什么情况下会产生StackOverflowError(栈溢出)和OutOfMemoryError(堆溢出)怎么排查-CSDN博客

谈谈我对HashMap扩容机制的理解及底层实现-CSDN博客

Redis 两种持久化方式 AOF 和 RDB-CSDN博客MySQL中的锁(简单)-CSDN博客

JDK、JRE、JVM的特点和关联-CSDN博客

面向对象的三大特征-CSDN博客

雪花算法生成id-CSDN博客

浅谈开源和闭源的认知-CSDN博客

浅谈开源和闭源的认知-CSDN博客

TCP三次握手 四次挥手-CSDN博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薅你两根毛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值