如何为Liferay查找'java.lang.ClassNotFoundException:com.mysql.cj.jdbc.Driver'

时间:2019-04-09 12:25:55

标签: java liferay-7

请在此处帮助我修复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>

Stacktrace:

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)

1 个答案:

答案 0 :(得分:1)

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

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