Spring: “SimpleLogger does not seem to be location aware” exception

末鹿安然 提交于 2019-12-24 08:47:22

问题


I'm getting an exception in a Spring app on my first line of code:

ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

I have commons-logging-1.1.1.jar configured as a project library.

Here is the stack trace:

java.lang.UnsupportedOperationException: The logger [org.slf4j.impl.SimpleLogger(org.springframework.context.support.ClassPathXmlApplicationContext)] does not seem to be location aware.

at org.apache.log4j.Category.log(Category.java:347) at org.apache.commons.logging.impl.Log4JLogger.info(Log4JLogger.java:199) at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:456) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:394) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)


回答1:


Looks like you are using multiple logging frameworks at the same time. This error seems to be a symptom of a clash between your SLF4J and Log4J configurations.

Take a look at this post:
http://www.qos.ch/pipermail/slf4j-user/2010-February/000892.html
which states,

The code log(String FQCN, Priority p, Object msg, Throwable t) method throws an exception because the caller expects location aware logging but the actual logger implementation is not capable of delivering "location awareness".

Without more information, my best guess is that you have a reference to an slf4j jar like slf4j-nop-1.6.1.jar or something else that's turning off logging by pointing to Non-Operational implementation of the Logger class.

Find the culprit and delete it (or replace it with the slf4j-log4j version).

Are you using Maven?

If so, open the dependency graph of your pom file and search for all dependencies with slf4j in their name. Delete the one that looks like a NOOP jar.



来源:https://stackoverflow.com/questions/3690552/spring-simplelogger-does-not-seem-to-be-location-aware-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!