Exception java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource

后端 未结 6 1946
广开言路
广开言路 2021-02-07 07:07

I\'m trying to integrate spring and Hibernate with mysql. I created a simple java project and a package with 3 classes, an application context.xml file, and an hbm.xml for mappi

6条回答
  •  自闭症患者
    2021-02-07 07:34

    If you are using Spring 4+, you should use SessionFactory. Also, you need these jars: commons-pool, commons-dbcp.

    This is a sample code that I made, I hope it helps you:

    public class EmployeeDAOImpl implements EmployeeDAO{
    
        private SessionFactory sessionFactory;
    
        @Override
        public void saveEmployee(Employee e) {
            Session session = this.sessionFactory.openSession();
            Transaction tx = session.beginTransaction();
            session.persist(e);
            tx.commit();
            session.close();
        }
    
        public SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    
        public void setSessionFactory(SessionFactory sessionFactory) {
            this.sessionFactory = sessionFactory;
        }
    
    }
    

    applicationContext.xml:

    
    
    
         
            
            
            
            
        
    
          
            
    
            
            
                employee.hbm.xml
            
            
    
            
                
                    org.hibernate.dialect.Oracle9Dialect
                    update
                    true
    
                
            
        
    
    
        
            
        
    
    
    

提交回复
热议问题