Search code examples
javahibernatemavenslf4jwildfly-8

Hibernate can't serialize object on Wildfly due to SLF4J Module load error with Maven


I'm very new to J2EE so be gentle...

I'm using Wildfly (JBOSS) 8.2.0.Final and I've got an issue with hibernate. Every time I try to deserialize an object, I get an error from hibernate:

Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.Slf4jLogger 
from [Module "org.hibernate:main" from local module loader @4253c155 
(finder: local module finder @8b9d578 (roots: C:\dev\wildfly-8.2.0.Final\modules,
C:\dev\wildfly-8.2.0.Final\modules\system\layers\base))]

As I understand the wild world of SLF4J, wildfly has a custom implementation and the correct thing to do is exclude all references to anything other than org.slf4j from your dependencies and include the slf4j-api in your dependencies. I can confirm that my lib folder does have the slf4j-api JAR in there, but I don't know how to even start debugging this. Note that other aspects of the application are loading and are logging correctly, it's only when I try to deserialize something that hibernate tries to log and fails with this exception.

Below are some extracts from the pom:

<!-- logging -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <scope>provided</scope>
</dependency>   

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ejb-plugin</artifactId>
    <configuration>
        <archive>
            <addMavenDescriptor>false</addMavenDescriptor>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
            </manifest>
            <manifestEntries>
                <Dependencies>org.slf4j org.apache.xerces services</Dependencies>
                <Class-Path>xxx-myproject-${project.version}.jar</Class-Path>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

Solution

  • The current slf4j which is downloading is not matching with the current Hibernate version. You try replacing the slf4j existing dependency with the below one or else provide the specific version in the maven dependency.

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