[Struts2 + Hibernate3] - Bon classpath et pourtant
Bonjour à tous,
Je commence aujourd'hui un projet Struts 2 + Hibernate 3
Après une journée de Google, de tuto, de FAQ et autres guides, voici ma question :
Comment fait-on ? :aie:
Plus sérieusement, j'ai créé l'appli Struts 2 qui tourne correctement. Validation de formulaire, etc. Et la j'ai installé Hibernate 3 pour tenter de sauvegarder le formulaire. Rien de plus simple !
Voici les étapes que j'ai suivi :
1. J'ai créé un fichier "hibernate.cfg.xml" où je mets ce que l'on trouve dans la documentation (chemin BD, driver mysql, login, pwd, fichier de mapping hibernate, etc.)
2. J'ai créé mon fichier de mapping entre la table BD et une classe toute simple (id + nom)
3. J'ai créé le "HibernateUtil" conseillé par tout le monde
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
} |
4. J'ai ajouté les librairies "required" par hibernate, notamment "slf4j-api-1.5.2.jar"
5. Je lance le tout
et voici l'exception :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
7 déc. 2008 19:36:48 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet default a g�n�r� une exception
java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at org.slf4j.LoggerFactory.<clinit>(LoggerFactory.java:60)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:151)
at src.HibernateUtil.<clinit>(HibernateUtil.java:12) |
D'après mes recherches sur google, cela viendrait d'un problème de classpath, alors que j'ai justement la librairie citée comme coupable...
Je pense que cela vient d'autres choses. Dans aucune de mes étapes, j'ai dit à Struts 2 de travailler avec hibernate, c'est peut-être cela ? Un oubli d'un properties dans un coin ? Bref, si quelqu'un a déjà travaillé avec ces deux framework, je suis preneur ;)
Merci d'avoir pris le temps de lire jusqu'ici. Il n'y a plus qu'à poster la réponse :p