J'essaye d'utiliser eclipse avec Spring et hibernate.
J'ai réalisé le tuto vidéo suivant : [ame="http://vimeo.com/15705668"]Tutoriel JSF, Spring et Hibernate on Vimeo[/ame]
Mais voila mon fichier de configuration de Spring n'arrive pas à être charger.
application-context.xml
Suite à un appel basique
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- Essayé aussi avec org.apache.commons.dhcp.BasicDataSource --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/university" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" > <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>hibernateWebProject.domain.modele.Course</value> <value>hibernateWebProject.domain.modele.Student</value> <value>hibernateWebProject.domain.modele.Teacher</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop> </props> </property> </bean> <!-- Gestion des transactions --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- mode de transaction par annotation --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- Pour toute la configuration des beans --> <context:annotation-config /> <!-- pour le scan des classes générées --> <context:component-scan base-package="hibernateWebProject.domain"></context:component-scan> </beans>
L'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 private static ClassPathXmlApplicationContext context; ... context = new ClassPathXmlApplicationContext("application-context.xml");
Je pense que c'est un problème de librairie.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [application-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor': Cannot create inner bean '(inner bean)' of type [org.springframework.transaction.interceptor.TransactionInterceptor] while setting bean property 'transactionInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.hibernate.cfg.AnnotationConfiguration]: Constructor threw exception; nested exception is java.lang.ClassCastException: org.hibernate.annotations.common.reflection.java.JavaReflectionManager cannot be cast to org.hibernate.annotations.common.reflection.MetadataProviderInjector
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)
Donc voici les librairies installées :
J'ai lu que les dernière version d'hibernate n'utilise plus commons-loggin mais slf4j (si on enlève ceux installé on obtient la même erreur).
Si j'enleve commons-loggin j'obtient l'erreur suivante :
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.util.ClassUtils.<clinit>(ClassUtils.java:73)
at org.springframework.core.io.DefaultResourceLoader.<init>(DefaultResourceLoader.java:53)
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:199)
at org.springframework.context.support.AbstractRefreshableApplicationContext.<init>(AbstractRefreshableApplicationContext.java:84)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.<init>(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:58)
Il doit me manquer soit une librairie soit une ligne a changer pour adapter à SLF4 mais je ne vois pas et je commence à désespérer.
Merci de m'aider ou de me guider.
Partager