gpt4 book ai didi

java - 无法将 Grails 3.3 与 mysql 数据库连接

转载 作者:行者123 更新时间:2023-11-29 05:07:20 25 4
gpt4 key购买 nike

我一直在尝试从 Grails 项目连接到 MySQL 数据库,但我还没有成功。

我正在使用以下版本的 IntelliJ IDEA 17:

| Grails Version: 3.3.0.RC1
| Groovy Version: 2.4.12
| JVM Version: 1.8.0_131

build.gradle

dependencies{
compile files ("lib/mysql-connector-java-5.1.43-bin")
}

application.yml

hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password: ''

environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql:3306//localhost/mydatabase
test:
dataSource:
dbCreate: update
url: jdbc:mysql:3306//localhost/mydatabase
production:
dataSource:
dbCreate: none
url: jdbc:mysql:3306//localhost/mydatabase

错误

"C:\Program Files\Java\jdk1.8.0_131\bin\java" -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Djline.WindowsTerminal.directConsole=false -Dfile.encoding=UTF-8 -classpath C:\Users\Vaggelis\AppData\Local\Temp\classpath.jar org.grails.cli.GrailsCli run-app
|Resolving Dependencies. Please wait...

CONFIGURE SUCCESSFUL

Total time: 3.824 secs
|Running application...
2017-08-07 19:42:52.921 ERROR --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.

java.sql.SQLException: Unable to load class: com.mysql.jdbc.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2

2017-08-07 19:42:55.391 ERROR --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : Unable to load class: com.mysql.jdbc.Driver from ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2;ClassLoader:sun.misc.Launcher$AppClassLoader@18b4aac2
2017-08-07 19:42:55.405 ERROR --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Destroy method on bean with name 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor' threw an exception

2017-08-07 19:42:55.431 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Unsatisfied dependency expressed through method 'methodValidationPostProcessor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastoreServiceRegistry': Cannot resolve reference to bean 'hibernateDatastore' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution

Caused by: org.hibernate.exception.GenericJDBCException: Unable to check JDBC Connection auto-commit in preparation for DDL execution

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':bootRun'.
Process 'command 'C:\Program Files\Java\jdk1.8.0_131\bin\java.exe'' finished with non-zero exit value 1

Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error |
Failed to start server (Use --stacktrace to see the full trace)

Process finished with exit code 1

MySQLConnector 被正确导入,所以我一定是在数据源中的某个地方输入了错误的数据。

最佳答案

在 grails 3 中,方言是在 hibernate 部分而不是数据源下指定的。

hibernate:
dialect: org.hibernate.dialect.MySQL5InnoDBDialect

关于java - 无法将 Grails 3.3 与 mysql 数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45551981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com