mysql - 无法连接到 MySQL 的 Spring Boot 应用程序故障排除

标签 mysql hibernate tomcat spring-boot

我在应用程序中构建了 MySQL 连接器和数据库详细信息,但在 Tomcat 中运行时它仍然无法连接到 MySQL。我的应用程序是完全开源的,所有源代码都在网上:https://github.com/clickcell/AutomationStatisticsPortal

The application.class

The gradle build file

与我的存储库不同的 application.properties 文件是:

spring.datasource.url=jdbc:mysql://localhost/springboot
spring.datasource.username=newuser
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

我已尝试设置 MySQL 5.5 服务器以匹配 application.properties

每次出现的症状如下:

Web 应用程序正在运行,但没有数据库连接,也没有显示任何数据。

我使用 Tomcat8 和 MySQL 5.5。当我直接向服务器运行查询时,我已经启用了查询日志并使用 tail -f 对其进行监控,它们显示在日志中但是当我在 tomcat 管理器中重新启动我的应用程序时,没有任何显示日志。

在 tomcat 日志中,我得到以下信息:

21-Dec-2016 10:19:16.693 INFO [http-nio-8080-exec-6] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/AutomationStatisticsPortal] has started
21-Dec-2016 10:19:17.339 WARNING [http-nio-8080-exec-6] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [AutomationStatisticsPortal] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
21-Dec-2016 10:19:19.026 INFO [http-nio-8080-exec-6] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
21-Dec-2016 10:19:26.839 INFO [http-nio-8080-exec-6] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/AutomationStatisticsPortal] is completed

看起来它注册了错误类型的数据库驱动程序,但我不知道为什么我的配置。

最佳答案

您显示的日志是使用 H2 时生成的。

我克隆了您的存储库并在本地进行了测试,当我使用 MySQL 参数更新 src/main/resources/application.properties 时它可以正常工作。 您应该删除根目录中的另一个,这是不明确的。

您还可以将 src/main/resources 中的 application.properties 文件替换为此 application.yml 文件:

spring:
    datasource:
        type: com.zaxxer.hikari.HikariDataSource
        url: jdbc:mysql://localhost/springboot
        username: newuser
        password: password
    jpa:
      database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
      database: MYSQL
      show-sql: true

在这种情况下,添加 Hikary 依赖项,或使用其他数据源类型。

关于mysql - 无法连接到 MySQL 的 Spring Boot 应用程序故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41260420/

相关文章:

hibernate - hibernate中的事务管理是什么?

java - Tomcat AD 身份验证 - 允许所有 AD 用户

mySql 触发器未按预期工作

php - SQL 输出到并排表

php - MySQL VALUES() 函数不适用于 Codeigniter db->query()

mysql - InnoDB:(PK,col1,col2,col3)形式的覆盖索引是否多余?

java - 如何插入忽略超过 100 个输入值

java - 从 hibernate 中获取查询的执行时间

tomcat - 在带有 GWT Tomcat 服务器端和 Jetty 的 IDEA 14 intelijj 中无法使用调试器 - SuperDevMode

java - Spring Boot HTTPS 和重定向