Hibernate 3.4 with slf4j and log4j

后端 未结 6 894
挽巷
挽巷 2020-12-05 18:15

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-log

相关标签:
6条回答
  • 2020-12-05 18:49

    A Google search found this:

    http://marc.info/?l=slf4j-user&m=122218775201271&w=2

    Maybe you should check your JAR versions to make sure they're compatible.

    0 讨论(0)
  • 2020-12-05 18:49

    I had the same problem with displaytag version 1.2 including old slf4j. Changing the displaytag to have the exclusion:

    <dependency>
      <groupId>displaytag</groupId>
      <artifactId>displaytag</artifactId>
      <version>1.2</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl104-over-slf4j</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    

    and adding the correct dependencies:

    <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>
    

    seemed to fix the problem.

    0 讨论(0)
  • 2020-12-05 18:50

    This question is answered by the SLF4J FAQ. Please see

    http://slf4j.org/faq.html#compatibility and http://slf4j.org/faq.html#IllegalAccessError

    0 讨论(0)
  • 2020-12-05 18:50

    I think you need to exclude the built-in SLF4J dependency from each of the Hibernate dependencies.

    I use Hibernate with JPA, so my config isn't identical, but I think the crucial thing is to explicitly include log4j and SLF4J and explicitly exclude slf4j-api from all org.hibernate dependencies:

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.4.0.GA</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
            <scope>compile</scope>
        </dependency>
    
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.4.0.GA</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
            <scope>compile</scope>
        </dependency>
    
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
            <scope>runtime</scope>
        </dependency>
    
    0 讨论(0)
  • 2020-12-05 18:51

    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>
    

    and

         <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>
    
    0 讨论(0)
  • 2020-12-05 18:52

    After checking the version 1.5.6 POM for slf4j-log4j (and then slf4j-parent) you should be using log4j-1.2.14. The slf4j-log4j POM uses dependency management to inherit the appropriate version of log4j from the slf4j-parent POM.

    You shouldn't, however, need to include log4j as a specific dependency as it is already a dependency of slf4j-log4j. That may have been where you caused your problem.

    0 讨论(0)
提交回复
热议问题