我正在尝试使用tomcat 7.0,java6和hibernate 4设置Web应用程序。
基本上,你可以说我遇到了和这个帖子一样的问题:java.lang.ClassNotFoundException: org.hibernate.HibernateException,但是我无法解决它。我已经检查了构建路径,以及我能够想到的其他所有内容。
因此,当试图让servlet使用hibernate对象时,我得到了这个错误:
HTTP状态500 - 实例化servlet类controller.ControlServlet
时出错堆栈追踪:
java.lang.ClassNotFoundException: org.hibernate.HibernateException
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
controller.SearchCommand.<init>(SearchCommand.java:25)
controller.ControlServlet.<init>(ControlServlet.java:31)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
SearchCommand:
public class SearchCommand implements Command{
private BookingDAO dao;
public SearchCommand(){
this.dao = new BookingDAO(); // line 25
}
ControlServlet:
public ControlServlet() {
super();
commands.put("search", new SearchCommand());
}
BookingDAO:
public class BookingDAO {
private SessionFactory factory;
public BookingDAO(){
try {
factory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public void getHotel(Booking booking, int hotelId){
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Hotel hotel = (Hotel) session.get(Hotel.class, hotelId);
booking.setHotel(hotel);
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
类路径: http://i.stack.imgur.com/e1S2a.jpg
任何人都可以帮助我吗?