bonjour,
J'ai un tuto dont le code est en java + spring hibernate qui marche sous windows avec une base de données sous mysql.

Mais Par contre sous ubuntu (avec postgresql) j'obtiens le message suivant au déployement :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.bari.springmvc.dao.ProductDao com.bari.springmvc.service.ProductServiceImpl.productDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productDaoImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.bari.springmvc.dao.ProductDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:
org.hibernate.annotations.common.reflection.java.JavaReflectionManager.injectClassLoaderDelegate(Lorg/hibernate/annotations/common/reflection/ClassLoaderDelegate;)V
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)
----
Voici le contenu de mes fichiers de configurations et classes :

web.xml :
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>    
</web-app>
dispatcher-servlet.xml

Code xml : 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:jee="http://www.springframework.org/schema/jee"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/jee 
        http://www.springframework.org/schema/jee/spring-jee.xsd
    http://www.springframework.org/schema/lang 
        http://www.springframework.org/schema/lang/spring-lang.xsd
    http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd
   http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
    <context:annotation-config/>
    <context:component-scan base-package="com.bari.springmvc"/>
    <mvc:annotation-driven/>
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp" />
    <bean id="propertyConfiguration" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
        <property name="location" value="/WEB-INF/jdbc.properties"/>
    </bean>
    <bean id="messageSource"        
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
          <!-- <property name="basename" value="/WEB-INF/message" /> -->
          <property name="basename" value="/WEB-INF/message_en" />
    </bean>
    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}"
          p:username="${jdbc.username}"
          p:password="${jdbc.password}" />
 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
                <value>com/bari/springmvc/model/Product.hbm.xml</value>
            </list>
        </property>       
 
        <property name="hibernateProperties">
            <value>
                hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
                hibernate.show_sql=true
            </value>
        </property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
 
</beans>
context.xml :

Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/SpringHiberMVC"/>
jdbc.properties :

jdbc.driverClassName=org.postgresql.Driver
jdbc.dialect=org.hibernate.dialect.PostgreSQLDialect
jdbc.databaseurl=jdbc:postgresql://localhost:5432/sph_login
jdbc.username=postgres
jdbc.password=123
ProductDaoImpl.java :

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
package com.bari.springmvc.dao;
 
import com.bari.springmvc.model.Product;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
@Repository
public class ProductDaoImpl implements 
         ProductDao{
 
    @Autowired
    private SessionFactory sessionFactory;   
 
    @Override
    public void addProduct(Product product) {
        sessionFactory.getCurrentSession().save(product);
    }
 
    @Override
    public void updateProduct(Product product) {
        sessionFactory.getCurrentSession().update(product);
    }
 
    @Override
    public List<Product> listProduct() {
       return  sessionFactory.getCurrentSession().createQuery("from Product").list();
    }
 
    @Override
    public Product getProductById(Integer productId) {
        Session session = sessionFactory.getCurrentSession();
        List<Product> list = session.createQuery("from Product p where p.id=:productid").setParameter("productid", productId).list();
        return list.size()>0?(Product)list.get(0):null;
 
    }
 
    @Override
    public void removeProduct(Integer productId) {
        Product product = (Product)sessionFactory.getCurrentSession().load(Product.class, productId);
        if(product!=null){
        sessionFactory.getCurrentSession().delete(product);
        }
    }
 
}
ProductDao.java :

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
package com.bari.springmvc.dao;
 
import com.bari.springmvc.model.Product;
import java.util.List;
 
public interface ProductDao {
 
 
    public void addProduct(Product product);
 
    public void updateProduct(Product product);
 
    public List<Product> listProduct();
 
    public Product getProductById(Integer productId);
 
    public void removeProduct(Integer productId);
}
ProductDaoImpl.java :


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
package com.bari.springmvc.dao;
 
import com.bari.springmvc.model.Product;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
 
@Repository
public class ProductDaoImpl implements 
         ProductDao{
 
    @Autowired
    private SessionFactory sessionFactory;   
 
    @Override
    public void addProduct(Product product) {
        sessionFactory.getCurrentSession().save(product);
    }
 
    @Override
    public void updateProduct(Product product) {
        sessionFactory.getCurrentSession().update(product);
    }
 
    @Override
    public List<Product> listProduct() {
       return  sessionFactory.getCurrentSession().createQuery("from Product").list();
    }
 
    @Override
    public Product getProductById(Integer productId) {
        Session session = sessionFactory.getCurrentSession();
        List<Product> list = session.createQuery("from Product p where p.id=:productid").setParameter("productid", productId).list();
        return list.size()>0?(Product)list.get(0):null;
 
    }
 
    @Override
    public void removeProduct(Integer productId) {
        Product product = (Product)sessionFactory.getCurrentSession().load(Product.class, productId);
        if(product!=null){
        sessionFactory.getCurrentSession().delete(product);
        }
    }
 
}
ProductServiceImpl.java :


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
package com.bari.springmvc.service;
 
import com.bari.springmvc.dao.ProductDao;
import com.bari.springmvc.model.Product;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
@Service
public class ProductServiceImpl implements ProductService{
 
    @Autowired
    ProductDao productDao;
 
    @Override
    @Transactional
    public void addProduct(Product product) {
        productDao.addProduct(product);
    }
 
    @Override
    @Transactional
    public void updateProduct(Product product) {
        productDao.updateProduct(product);
    }
 
    @Override
    @Transactional
    public List<Product> listProduct() {
        return productDao.listProduct();
    }
 
    @Override
    @Transactional
    public Product getProductById(Integer productId) {
        return productDao.getProductById(productId);
    }
 
    @Override
    @Transactional
    public void removeProduct(Integer productId) {
        productDao.removeProduct(productId);
    }
 
}
ProductService.java :

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
package com.bari.springmvc.service;
 
import com.bari.springmvc.model.Product;
import java.util.List;
 
public interface ProductService {
 
    public void addProduct(Product product);
 
    public void updateProduct(Product product);
 
    public List<Product> listProduct();
 
    public Product getProductById(Integer productId);
 
    public void removeProduct(Integer productId);
}