我遇到了以下问题:我尝试使用 Eclipse 创建一个简单的 Servlep:
@WebServlet(description = "Adress book servlet", urlPatterns = {"/new_address"})
public class CAddressBookServlet extends HttpServlet
{
public CAddressBookServlet()
{
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{}
private static final long serialVersionUID = 1L;
}
它适用于Tomcat!但后来我要在我的项目中添加 Hibernate 功能。我只向 servlet 构造函数添加了一行:
@WebServlet(description = "Adress book servlet", urlPatterns = {"/new_address"})
public class CAddressBookServlet extends HttpServlet
{
public CAddressBookServlet()
{
super();
new AnnotationConfiguration();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{}
private static final long serialVersionUID = 1L;
}
导致以下错误:
HTTP 状态 500 - 实例化 servlet 类 org.servlets.CAddressBookServlet 时出错
类型异常报告
消息实例化 servlet 类 org.servlets.CAddressBookServlet 时出错
描述 服务器遇到一个内部错误,阻止它完成这个请求。
例外
javax.servlet.ServletException: 实例化 servlet 类 org.servlets.CAddressBookServlet org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 时出错) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor .java:1004) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent .ThreadPoolExecutor.runWorker(未知来源) java.util.concurrent.ThreadPoolExecutor$Worker。运行(未知来源) java.lang.Thread.run(未知来源)
根本原因
java.lang.NoClassDefFoundError: org/hibernate/cfg/AnnotationConfiguration org.servlets.CAddressBookServlet.(CAddressBookServlet.java:33) sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 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. authenticationator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931) org. apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:第407章SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)
根本原因
java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) org .servlets.CAddressBookServlet.(CAddressBookServlet.java:33) 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:472) org. apache.catalina.valves.ErrorReportValve。调用(ErrorReportValve.java:99)org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)org.apache.coyote。 http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java: 310) java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源) java.util.concurrent.ThreadPoolExecutor$Worker.run(未知来源) java.lang.Thread.run(未知来源)AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)运行(未知来源)运行(未知来源)
note Apache Tomcat/7.0.33 日志中提供了根本原因的完整堆栈跟踪。
如何使休眠与我的 servlet 一起工作?