首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法将Grails 3.3与mysql数据库连接

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

Stack Overflow用户
提问于 2017-08-07 16:51:59
回答 3查看 3.1K关注 0票数 1

我一直试图连接从Grails项目到MySQL数据库,但我还没有管理它。

我正在研究IntelliJ IDEA 17的以下版本:

代码语言:javascript
复制
| Grails Version: 3.3.0.RC1
| Groovy Version: 2.4.12
| JVM Version: 1.8.0_131

build.gradle

代码语言:javascript
复制
dependencies{
     compile files ("lib/mysql-connector-java-5.1.43-bin")
}

application.yml

代码语言:javascript
复制
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

误差

代码语言:javascript
复制
"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正在被正确导入,所以在某个地方,我一定是在数据源中输入了错误的数据。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-08-08 12:31:53

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

代码语言:javascript
复制
hibernate:
  dialect: org.hibernate.dialect.MySQL5InnoDBDialect
票数 1
EN

Stack Overflow用户

发布于 2017-08-08 05:52:29

我正在使用这个配置,它运行得很好:

build.gradle

代码语言:javascript
复制
dependencies {
    runtime 'mysql:mysql-connector-java:5.1.29'
}

application.yml

代码语言:javascript
复制
hibernate:
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory


dataSource:
    pooled: true
    jmxExport: true


environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: "jdbc:mysql://localhost:3306/mydb?autoReconnect=true"
            driverClassName: "com.mysql.jdbc.Driver"
            dialect: org.hibernate.dialect.MySQL5InnoDBDialect
            username: "yyyyy"
            password: "xxxxx"
票数 1
EN

Stack Overflow用户

发布于 2017-08-16 19:00:54

通过从我的两个tablePerConcreteClass域类中删除abstract映射,我修复了Grails3.2.9项目中的类似问题:

代码语言:javascript
复制
static mapping = {
    tablePerConcreteClass true
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45551981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档