春天。"SimpleLogger似乎没有位置意识 "异常[英] Spring: "SimpleLogger does not seem to be location aware" exception

本文是小编为大家收集整理的关于春天。"SimpleLogger似乎没有位置意识 "异常的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我的第一行代码在 Spring 应用程序中遇到异常:

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

我将 commons-logging-1.1.1.jar 配置为项目库.

这是堆栈跟踪:

java.lang.UnsupportedOperationException:记录器 [org.slf4j.impl.SimpleLogger(org.springframework.context.support.ClassPathXmlApplicationContext)] 似乎无法识别位置.

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

推荐答案

看起来您正在同时使用多个日志框架.此错误似乎是您的 SLF4J 和 Log4J 配置之间发生冲突的症状.

看看这个帖子:
http://www.qos.ch/pipermail/slf4j-user/2010-2月/000892.html
哪条规定,

<块引用>

代码日志(String FQCN, Priority p,Object msg, Throwable t) 方法抛出一个例外,因为调用者期望位置感知日志记录,但实际的记录器实现不是能够提供"位置意识".

如果没有更多信息,我最好的猜测是您引用了 slf4j jar,如 slf4j-nop-1.6.1.jar 或其他通过指向 Logger 类的非操作实现来关闭日志记录的东西.

找到罪魁祸首并删除它(或将其替换为 slf4j-log4j 版本).

你在使用 Maven 吗?

如果是这样,请打开 pom 文件的依赖关系图并搜索名称中包含 slf4j 的所有依赖项.删除看起来像 NOOP jar 的那个.

本文地址:https://www.itbaoku.cn/post/1575081.html

问题描述

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)

推荐答案

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.