如何fiw 'java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver' for liferay

How to fiw 'java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver' for liferay

请帮我修复这里的 ClassNotFoundException: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

这里有一些细节:

我正在从 hibernate.cfg.xm

加载配置

SessionFactoryConnection.java

    public class SessionFactoryConnection {
        private static SessionFactory sessionFactory;
        static {
            Configuration configuration = new Configuration();
            configuration = configuration.configure("hibernate.cfg.xml");
            sessionFactory = configuration.buildSessionFactory();
        }

        private SessionFactoryConnection() {
        }

        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    }

hibernate.cfg.xm

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/company?serverTimezone=UTC</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">1</property>
        <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="hbm2ddl.auto\">update</property>
        <property `enter code here`name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <mapping class="com.aimprosoft.model.Department"/>
        <mapping resource="hbm/Department.hbm.xml"/>
        <mapping class="com.aimprosoft.model.Employee"/>
        <mapping resource="hbm/Employee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

我正在使用

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>

堆栈跟踪:

2019-04-09 12:20:52.063 ERROR [http-nio-8080-exec-1][DriverManagerConnectionProvider:88] JDBC Driver class not found: com.mysql.cj.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1309)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1138)
    ........
    at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
    at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

请检查您是否在 hibernate.cfg.xml 文件中添加了此 属性。

  <property name = "hibernate.connection.driver_class">
     com.mysql.jdbc.Driver
  </property>