Conflit de lib Apache CXF et hibernate

Je viens de perdre pas mal de temps à faire fonctionner mon projet qui utilise hibernate et apache CXF pour exposer des WebServices.

Au moment de compiler j’avais l’erreur suivante :

WARN: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor:<br /> at net.sf.cglib.core.KeyFactory$Generator.generateClass

Au début ça me paraissait être un simple NoClassDefFound, mais la classe recherchée était bien dans mon CLASSPATH.

A force de chercher j’ai fini par comprendre que c’etait un problème d’incompatibilité de version de lib cglib. Il faut donc exclure la librairie cglib récupérée avec hibernate pour en prendre une nommée : cglib-nodep.

Voici comment faire dans votre fichier maven 2 :

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.2.1.ga</version>
    <exclusions>
        <exclusion>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.1_3</version>
</dependency>