排除无法连接到MySQL的Spring Boot应用程序(Troubleshooting Spring Boot app that won't connect to MySQL)

编程入门 行业动态 更新时间:2024-10-12 20:20:37
排除无法连接到MySQL的Spring Boot应用程序(Troubleshooting Spring Boot app that won't connect to MySQL)

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

application.class

gradle构建文件

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

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

I built the MySQL connector and the database details into the app and it still wont connect to MySQL when running in Tomcat. My app is entirely open source and all source code is on the web at: https://github.com/clickcell/AutomationStatisticsPortal

The application.class

The gradle build file

The application.properties file, different from my repository, is:

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

I have tried setting up the MySQL 5.5 server to match application.properties

Every time the symptom is as follows:

Web app running but there is no database connection, no data being displayed.

I use Tomcat8 and MySQL 5.5. I have enabled the query log and monitor it using tail -f when I run queries direct to the server they show up in the log but when I reboot my app in the tomcat manager, nothing shows up in that log.

In the tomcat log I get the following:

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

It looks like it's registering the wrong kind of database driver, but I do not know why given my configuration.

最满意答案

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

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

您还可以使用此application.yml文件替换src/main/resources 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依赖项,或使用其他数据源类型。

The log you've shown is produced when H2 is used.

I cloned your repository and tested locally, it works when I update the src/main/resources/application.properties with MySQL parameters. You should remove the other one in root, it's ambiguous.

You could also replace your application.properties file in src/main/resources with this application.yml file:

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

In this case, add the Hikary dependency, or use another datasource type.

更多推荐

本文发布于:2023-08-06 17:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1452748.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   应用程序   Spring   Boot   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!