我在我的maven项目中使用带有spring的hibernate.这是我的POM文件
sqlsql
这是我的DAO课程
public class Task_Impl implements Task_Interface {
@Autowired
SessionFactory sessionfactory;
@Override
@Transactional
public void createTask(Task task) {
// TODO Auto-generated method stub
sessionfactory.getCurrentSession().save(task);
System.out.println("Task created in database");
}
@Override
public void deleteTask() {
// TODO Auto-generated method stub
}
}
这是我的Dispatcher Servlet(HelloWeb-servlet.xml)
xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">
factorybean">
sqlDialectsql">truesql.Driver"/>
sql://localhost:5432/newdatabase"/>
当我尝试运行该项目时,我收到以下错误
Error creating bean with name 'task_impl_bean': Injection of autowired dependencies Failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: org.hibernate.SessionFactory org.mod.Prime.DAO.Implementation.Task_Impl.sessionfactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionfactory' defined in ServletContext resource [/WEB-INF/HelloWeb-servlet.xml]: Invocation of init method Failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
主要根本原因是
Invocation of init method Failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
最佳答案
尝试在sessionFactory之前声明dataSourceBean
原文链接:https://www.f2er.com/spring/432313.htmlsql.Driver"/>
sql://localhost:5432/newdatabase"/>
factorybean">
sqlDialectsql">true