我在应用程序中构建了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.DriverI 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 completedIt 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: trueIn this case, add the Hikary dependency, or use another datasource type.
更多推荐
发布评论