简体   繁体   中英

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

Please help me with fixing ClassNotFoundException here: java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

Here are some details on it:

I'm loading configs from 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>

I'm using

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

The 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)

Please check whether you added this property in hibernate.cfg.xml file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM