views:

33

answers:

1

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)

A: 

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.

gmale
This is a Spring/Hibernate project and somehow I had included both a versioned and an unversioned slf4j-simple.jar in the project as part of the Hibernate config. I deleted slf4j-simple.jar, leaving slf4j-simple-1.4.2.jar matching the slf4j-simple-api-1.4.2.jar that is part of the Hibernate distribution I'm using. All is well.
Chance Kunga
glad you sorted it out. I think, I like the theory behind SLF4J but in practice, it seems to cause a lot of problems like this.
gmale
What's really a pain is when the frameworks you're using have dependencies on logging systems and then you get snarled up in those. BLECH.
Chance Kunga