Hibernate, Spring and SLF4J Binding

前端 未结 5 1791
囚心锁ツ
囚心锁ツ 2020-12-30 08:28

I\'m trying to setup a webapp with maven2 managed dependcies. Here my pom.xml



        
相关标签:
5条回答
  • 2020-12-30 09:11

    Hibernate depends on slf4j-api, so you need to add missing dependency in you pom.xml

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.8.0-beta4</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-30 09:13

    You are missing

      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
      </dependency>
    
    0 讨论(0)
  • 2020-12-30 09:22

    This should indeed work, the slf4j-log4j12 binding contains org/slf4j/impl/StaticLoggerBinder.

    1. Try to clean and redeploy your application, maybe something went wrong during deployment.
    2. Double check that the downloaded slf4j-log4j12-1.5.8.jar is not corrupted (try to open it).
    3. Maybe even delete it and let maven re-download it.

    Some unrelated remarks:

    • Instead of repeating frameworks version in dependencies, you should use a property. For example:

      ...
      <properties>
        <spring.version>3.0.2.RELEASE</spring.version>
        ...
      </properties>
      <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>${spring.version}</version>
        </dependency>
        ...
      </dependencies>
      
    • hibernate-core is a transitive dependency of hibernate-annotations, you don't need to declare it (if you want to use JPA, you should actually depend on hibernate-entitymanager).

    0 讨论(0)
  • 2020-12-30 09:23

    Hibernate depends on slf4j-api, so declaring it yourself shouldn't make any difference. Apart from that, I don't know why it's not working.

    0 讨论(0)
  • 2020-12-30 09:27

    Include the slf4j-api in your dependencies:

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.5.8</version>
    </dependency>
    

    Exclude the commons-logging dependency for minimum one of your declared spring dependencies and provide the slf4j facade for commons-logging:

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>3.0.2.RELEASE</version>
      <exclusions>
         <exclusion>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging</artifactId>
         </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <version>1.5.8</version>
      <scope>runtime</scope>
    </dependency>
    

    Include the log4j dependency for your logging together with the slf4j facade:

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.5.8</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
      <scope>runtime</scope>
    </dependency>
    

    A great blog post for further reading about logging with SLF4J and Spring can be found in the SpringSource Team blog under http://blog.springsource.com/2009/12/04/logging-dependencies-in-spring/.

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