我的 Spring-Boot 服务器使用“starter-parent”pom 运行良好。问题是,如果可能的话,我宁愿不使用 spring pom 作为父级。当我只包含 spring-boot-dependencies pom 时(如此处所述),我最终没有加载驱动程序:
18:14:26.127 [localhost-startStop-1] WARN o.a.t.jdbc.pool.PooledConnection - Not loading a JDBC driver as driverClassName property is null.
18:14:26.147 [localhost-startStop-1] ERROR o.a.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/mydb
at java.sql.DriverManager.getConnection(DriverManager.java:689) ~[na:1.8.0_45]
at java.sql.DriverManager.getConnection(DriverManager.java:208) ~[na:1.8.0_45]
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:305) ~[tomcat-jdbc-8.0.23.jar:na]
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200) ~[tomcat-jdbc-8.0.23.jar:na]
...
我很确定这与 DriverManager 和 ServiceLoader 位未加载驱动程序有关,但我不确定如何强制这种情况发生。任何建议将不胜感激。
FWIW:如果我尝试“Class.forName()”MySQL jdbc 驱动程序,我实际上会得到一个“NoClassDefFoundError”,这令人费解,因为 mysql-connector 肯定在我的 pom.xml 中。多个类加载器还是什么?