Hibernate 3.4与slf4j和log4j [英] Hibernate 3.4 with slf4j and log4j

查看:174
本文介绍了Hibernate 3.4与slf4j和log4j的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Hibernate 3.2升级到3.4,显然使用slf4j。我们的项目目前使用log4j。所以我的假设是我应该使用slf4j-log4j12包装的实现。

I'm attempting to upgrade from Hibernate 3.2 to 3.4, which apparently uses slf4j. Our project currently uses log4j. So my assumption is that I should be using the slf4j-log4j12 wrapped implementation.

Maven slf4j依赖项是:

The Maven slf4j dependency is:

<dependency>
    <groupId>org.slf4j</groupId>
     <artifactId>slf4j-log4j12</artifactId>
    <version>1.5.6</version>
</dependency>

虽然log4j依赖关系是:

While the log4j dependency is:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.15</version>
</dependency>

slf4j-log4j12和log4j都引用了最新版本(我可以在Maven仓库中找到它)。当我运行我的应用程序时,Hibernate在其日志记录中失败:

Both slf4j-log4j12 and log4j reference the latest version (that I could find in the Maven repository). When I run my app, Hibernate fails in its logging:

java.lang.NoSuchFieldError: name
    at org.slf4j.impl.Log4jLoggerAdapter.<init>(Log4jLoggerAdapter.java:75)
    at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:75)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:163)
    ...

我错过了什么?

编辑1:

java.lang.IllegalAccessError: tried to access field org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
    at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
    at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:163)
    ...

编辑2 : 这个博客声称这个问题是由于使用slf4j-api的错误版本提供的hibernate注释引起的。 jar。

Edit 2: This blog claims the problem is caused by hibernate annotations shipping with the wrong version of slf4j-api.jar.

推荐答案

我没有任何问题

i have no problems with

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.4.0.GA</version>
    </dependency>

     <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.6</version>
    </dependency>
    <!-- concrete Log4J Implementation for SLF4J API-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>

这篇关于Hibernate 3.4与slf4j和log4j的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆