这个警告信息是因为 Spring Boot 2.x 以上版本中,已经移除了对 JDBC 驱动的显式加载。所有的 JDBC 驱动都应该通过 Java 的 Service Provider Interface (SPI) 自动注册。如果你使用的是最新版本的 Spring Boot 和 JdbcTemplate,你可以删除代码中显式加载驱动的部分,例如:
Class.forName("com.mysql.jdbc.Driver");
然后,在 application.properties 或 application.yml 文件中配置 JDBC 连接信息和驱动类名即可,例如:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
即新版spring中会自动加载Driver驱动,且建议在properties文件中配置数据库信息