我在我的dao图层上获取会话对象时遇到问题我已经将我的hibernate DAO与spring集成,但我无法弄清楚这是我的错误
8 Mar, 2013 5:05:33 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Services\IPT\;C:\Program Files (x86)\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\NTRU Cryptosystems\NTRU TCG Software Stack\bin\;C:\Program Files\Dell\Dell Data Protection\Access\Advanced\Wave\Gemalto\Access Client\v5\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.6.0_31\bin;;.
8 Mar, 2013 5:05:34 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:EmployeeWebSpring' did not find a matching property.
8 Mar, 2013 5:05:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
8 Mar, 2013 5:05:34 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
8 Mar, 2013 5:05:34 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 459 ms
8 Mar, 2013 5:05:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
8 Mar, 2013 5:05:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.26
8 Mar, 2013 5:05:34 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Users\ankurj\hibernate\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\EmployeeWebSpring\WEB-INF\lib\servlet-2.3.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
8 Mar, 2013 5:05:34 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags is already defined
8 Mar, 2013 5:05:34 PM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://www.springframework.org/tags/form is already defined
8 Mar, 2013 5:05:35 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'ds'
8 Mar, 2013 5:05:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
8 Mar, 2013 5:05:37 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
8 Mar, 2013 5:05:37 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3621 ms
8 Mar, 2013 5:05:38 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
8 Mar, 2013 5:05:51 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ds] in context with path [/EmployeeWebSpring] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
at com.nousinfo.tutorial.dao.impl.EmployeeDAOImpl.getAllEmployees(EmployeeDAOImpl.java:56)
at com.nousinfo.tutorial.service.impl.EmployeeServiceImpl.getAllEmployees(EmployeeServiceImpl.java:50)
at com.nousinfo.tutorial.controllers.SearchEmployeeController.getAllEmployee(SearchEmployeeController.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
8 Mar, 2013 5:06:08 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ds] in context with path [/EmployeeWebSpring] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
at com.nousinfo.tutorial.dao.impl.DepartmentDAOImpl.getDepartment(DepartmentDAOImpl.java:155)
at com.nousinfo.tutorial.service.impl.DepartmentServiceImpl.getDepartment(DepartmentServiceImpl.java:96)
at com.nousinfo.tutorial.controllers.SearchDepartmentController.searchByDepartmentNo(SearchDepartmentController.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
8 Mar, 2013 5:37:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ds] in context with path [/EmployeeWebSpring] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;
at com.nousinfo.tutorial.dao.impl.EmployeeDAOImpl.getAllEmployees(EmployeeDAOImpl.java:56)
at com.nousinfo.tutorial.service.impl.EmployeeServiceImpl.getAllEmployees(EmployeeServiceImpl.java:50)
at com.nousinfo.tutorial.controllers.SearchEmployeeController.getAllEmployee(SearchEmployeeController.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:774)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是我的调度员servlet
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:annotation-config />
<mvc:annotation-driven />
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
id="dataSource">
<property value="com.mysql.jdbc.Driver" name="driverClassName" />
<property value="jdbc:mysql://192.168.25.30:3306/employee"
name="url" />
<property value="hr" name="username" />
<property value="hr123" name="password" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.nousinfo.tutorial.model.Department</value>
<value>com.nousinfo.tutorial.model.Employee</value>
<value>com.nousinfo.tutorial.model.EmployeeProject</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="employeeDaoImpl" class="com.nousinfo.tutorial.dao.impl.EmployeeDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="departmentDaoImpl" class="com.nousinfo.tutorial.dao.impl.DepartmentDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="projectDaoImpl" class="com.nousinfo.tutorial.dao.impl.ProjectDAOImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="employeserviceImpl"
class=" com.nousinfo.tutorial.service.impl.EmployeeServiceImpl">
<property name="employeeDAOImpl" ref="employeeDaoImpl" />
</bean>
<bean id="departmentserviceImpl"
class=" com.nousinfo.tutorial.service.impl.DepartmentServiceImpl">
<property name="departmentDAOImpl" ref="departmentDaoImpl" />
</bean>
<bean id="projectserviceImpl" class="com.nousinfo.tutorial.service.impl.ProjectServiceImpl">
<property name="projectDAOImpl" ref="projectDaoImpl" />
</bean>
<bean id="employeeValidator" class="com.nousinfo.tutorial.validator.EmployeeValidator" />
<bean id="mycontroller"
class="com.nousinfo.tutorial.controllers.SearchEmployeeController">
<property name="employeeServiceImpl" ref="employeserviceImpl"></property>
</bean>
<bean id="emplController" class="com.nousinfo.tutorial.controllers.EmployeeController">
<property name="employeeServiceImpl" ref="employeserviceImpl" />
<property name="projectServiceImpl" ref="projectserviceImpl" />
<property name="employeeValidator" ref="employeeValidator"></property>
</bean>
<bean id="departmentValidator" class="com.nousinfo.tutorial.validator.DepartmentValidator" />
<bean id="deaprtmentController" class="com.nousinfo.tutorial.controllers.DepartmentController">
<property name="departmentServiceImpl" ref="departmentserviceImpl"></property>
<property name="departmentValidator" ref="departmentValidator"></property>
</bean>
<bean id="deptCotrooler"
class="com.nousinfo.tutorial.controllers.SearchDepartmentController">
<property name="departmentServiceImpl" ref="departmentserviceImpl"></property>
</bean>
<bean id="projectValidator" class="com.nousinfo.tutorial.validator.ProjectValidator" />
<bean id="projectController" class="com.nousinfo.tutorial.controllers.ProjectController">
<property name="projectServiceImpl" ref="projectserviceImpl"></property>
<property name="projectValidator" ref="projectValidator"></property>
</bean>
<bean id="projectSearchController"
class="com.nousinfo.tutorial.controllers.SearchProjectController">
<property name="projectServiceImpl" ref="projectserviceImpl"></property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/" p:suffix=".jsp" />
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="com/nousinfo/resources/messages" />
</bean>
<!-- Configure the multipart resolver -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
</bean>
</beans>
这是dao层中我设置会话对象的方式
public class EmployeeDAOImpl implements EmployeeDAO {
/**
* This block is used to initialising the session object created by
* sessionFactory using HibernateUtil class. A org.hibernate.Session
* represents a single-threaded unit of work.
*/
/*
* static { session = HibernateUtil.getSessionFactory().openSession(); }
*/
private SessionFactory sessionFactory;
/**
* @return the sessionFactory
*/
public SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* @param sessionFactory
* the sessionFactory to set
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/**
* This will get all employees from the database
*
* @return list of employee
*/
@SuppressWarnings("unchecked")
@Override
public List<Employee> getAllEmployees() {
Session session = sessionFactory.openSession();
Criteria criteria = (Criteria) session.createCriteria(Employee.class);
List<Employee> employeeList = criteria.list();
return employeeList;
}}
答案 0 :(得分:2)
我注意到你的类路径中显然缺少hibernate-core。这一点很重要,因为它是所有Hibernate代码所在的地方。此外,在Spring Hibernate应用中,您应始终使用SessionFactory.getCurrentSession()
和 never SessionFactory.openSession()
。有关详细信息,请参阅"Implementing DAOs based on plain Hibernate 3 API"。