Spring: “SimpleLogger does not seem to be location

2019-07-28 17:48发布

问题:

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.