gpt4 book ai didi

java.lang.ClassNotFoundException : org. hibernate .cfg.AnnotationConfiguration

转载 作者:行者123 更新时间:2023-11-30 09:29:44 24 4
gpt4 key购买 nike

我遇到了以下问题:我尝试用 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 Status 500 - Error instantiating servlet class org.servlets.CAddressBookServlet


type Exception report

message Error instantiating servlet class org.servlets.CAddressBookServlet

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class 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(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)

root cause

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.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.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(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)

root cause

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.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(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.

如何让 hibernate 与我的 servlet 一起工作?

最佳答案

@Perception 有正确的答案。您需要将 Hibernate 库包含在已部署的 war 文件中。您可以将它们放在 WEB-INF/lib 或 Tomcat 认可的目录中。我更喜欢 WEB-INF/lib 位置,这样您就不会干扰服务器上的任何其他应用程序。

关于java.lang.ClassNotFoundException : org. hibernate .cfg.AnnotationConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13559568/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com