mysql - IntelliJ 15/Grails 3 : Cannot connect to mySql DB

标签 mysql tomcat grails intellij-idea dbconnection

这个问题已经被问过很多次了,但是给出的答案都没有解决我的问题:我用 IntelliJ IDEA 15.0.1 创建了一个新的 Grails 3 项目,没有添加额外的代码:它运行了。当我尝试配置我的项目以连接到 MySql 数据库时,出现以下错误:

ERROR org.apache.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@77abfbdc;ClassLoader:sun.misc.Launcher$AppClassLoader@77abfbdc
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:280)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:708)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:642)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:464)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:141)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:115)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:102)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:126)
at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy.afterPropertiesSet(LazyConnectionDataSourceProxy.java:162)
at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy.<init>(LazyConnectionDataSourceProxy.java:106)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1075)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)

我的配置是:JDK 1.7.072/Grails 3.1.8/IntelliJ 15.0.1

构建.gradle :

   buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
        classpath "org.grails.plugins:hibernate4:5.0.6"
    }
}

version "0.1"
group "testgrails3"

apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"

ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = project.gradleWrapperVersion
}

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false
}

dependencies {

    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-ehcache"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web:3.1.8"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
    runtime "mysql:mysql-connector-java:5.1.39"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}

task wrapper(type: Wrapper) {
    gradleVersion = gradleWrapperVersion
}

assets {
    minifyJs = true
    minifyCss = true
}

应用程序.yml:

hibernate:
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: com.mysql.jdbc.Driver
    dialect: org.hibernate.dialect.MySQL5InnoDBDialect
    username: myuser
    password: mypassword

environments:
    development:
        dataSource:
            dbCreate: update
            url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/myappdev;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    test:
        dataSource:
            dbCreate: update
            url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/myapptest;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
    production:
        dataSource:
            dbCreate: update
            url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/myappprod;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
            properties:
                jmxEnabled: true
                initialSize: 5
                maxActive: 50
                minIdle: 5
                maxIdle: 25
                maxWait: 10000
                maxAge: 600000
                timeBetweenEvictionRunsMillis: 5000
                minEvictableIdleTimeMillis: 60000
                validationQuery: SELECT 1
                validationQueryTimeout: 3
                validationInterval: 15000
                testOnBorrow: true
                testWhileIdle: true
                testOnReturn: false
                jdbcInterceptors: ConnectionState
                defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED

---

当然,jdbc:mysql://xxx.xxx.xxx.xxx:3306/是合法IP。

感谢您的帮助:我在这个问题上花了好几天...

最佳答案

你的依赖列表中没有mysql依赖 将其添加到您的依赖列表:

`runtime 'mysql:mysql-connector-java:5.1.37'`

关于mysql - IntelliJ 15/Grails 3 : Cannot connect to mySql DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38048727/

相关文章:

tomcat - 如何访问 Dockerfile 中声明的环境变量?

grails - 在Web应用程序中使用RabbitMQ,多个线程可以在同一队列上工作

html - HTML解析-从.html文件获取和更新数据

mysql - 使用批处理文件插入数据库

php - 对子查询的别名使用 where 条件

mysql - 从 Mysql 工作台自动化 Excel 报告

linux - 特定文件夹中的 java.lang.ClassNotFoundException

php - CakePHP 2.x 基于 HasMany 表记录的 Order By desc

java - 在两个不同的端口上运行 Tomcat 服务器

grails - 无法解析 grails 中的 org.apache.commons.net.ftp 类