Search code examples
grailsgrails-plugingrails-2.0grails-domain-classgrails-controller

Configuring a MySQL Database using Grail 2.4.4 (Unable to create initial connections of pool)


I'm a really beginner in Grails technology. I installed the IDE Groovy/Grails Tool Suite™ (GGTS, Grails 2.4.4) for Windows 64bits.

The environment path has been correctly updated concerning the JDK and Grails.

I created a new project called 'test', added a new domain class called 'test.User' as follow:

package test

class User {

    Integer id
    String firstName
    String lastName

    static constraints = {
        id(blank:false, unique:true)
        firstName(blank:false)
        lastName(blank:false)
    }
}

applied static scaffolding to generate the corresponding UserController and views associated with CRUD actions.

To check if my data model is working with H2 database I made some updates into the DataSource.groovy file and it works: I've added a new user throw the application and when I run the command SELECT* on my table USER (using grails dbconsole) and I have my new user entry displayed. So, until here all is ok!

But now I want to connect my application with an alternative SQL database using a different JDBC connector. I chose (for sake of compatibility) the one proposed within my BuildConfig.groovy file and uncommented it:

runtime mysql:mysql-connector-java:5.1.29

When I run the application 'run-app' (by default I think we are in development environment) I noticed the dependency mysql-connector-java-5.1.29.jar has been added into my .m2 directory (C:\Users\my_user_name.m2\repository\mysql\mysql-connector-java\5.1.29). So I think the dependency is correctly registered within a kindof MAVEN file within Grails. However the file does not appear into the ivy-cache directory. Is it normal ?

My BuildConfig.groovy file content:

grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.fork = [
    // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
    //  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

    // configure settings for the test-app JVM, uses the daemon by default
    test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the Console UI JVM
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

grails.project.dependency.resolver = "maven" // or ivy
grails.project.dependency.resolution = {
    // inherit Grails' default dependencies
    inherits("global") {
        // specify dependency exclusions here; for example, uncomment this to disable ehcache:
        // excludes 'ehcache'
    }
    log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
    checksums true // Whether to verify checksums on resolve
    legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility

    repositories {
        inherits true // Whether to inherit repository definitions from plugins

        grailsPlugins()
        grailsHome()
        mavenLocal()
        grailsCentral()
        mavenCentral()
        // uncomment these (or add new ones) to enable remote dependency resolution from public Maven repositories
        //mavenRepo "http://repository.codehaus.org"
        //mavenRepo "http://download.java.net/maven/2/"
        //mavenRepo "http://repository.jboss.com/maven2/"
    }

    dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
        runtime 'mysql:mysql-connector-java:5.1.29'
        // runtime 'org.postgresql:postgresql:9.3-1101-jdbc41'
        //test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
    }

    plugins {
        // plugins for the build system only
        build ":tomcat:7.0.55"

        // plugins for the compile step
        compile ":scaffolding:2.1.2"
        compile ':cache:1.1.8'
        compile ":asset-pipeline:1.9.9"

        // plugins needed at runtime but not for compilation
        runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18"
        runtime ":database-migration:1.4.0"
        runtime ":jquery:1.11.1"

        // Uncomment these to enable additional asset-pipeline capabilities
        //compile ":sass-asset-pipeline:1.9.0"
        //compile ":less-asset-pipeline:1.10.0"
        //compile ":coffee-asset-pipeline:1.8.0"
        //compile ":handlebars-asset-pipeline:1.3.0.3"
    }
}

Concerning the DataSource.groovy file I replaced the line concerning the driver name:

driverClassName = "org.h2.Driver"

by

driverClassName = "com.mysql.jdbc.Driver"

and for each environment (I know I only use development environment but it's just to avoid some errors) I replaced the followings lines:

url = "jdbc:h2:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"

by

url = "jdbc:mysql://localhost/test"

I've also added just below the default username and password (as root user) + the driver class name as follow (for each environment again):

driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""

Here's my DataSource.groovy file content:

dataSource {
    pooled = true
    jmxExport = true
    //driverClassName = "org.h2.Driver"
    driverClassName = "com.mysql.jdbc.Driver"
    username = "sa"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            //url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            url = "jdbc:mysql://localhost/test"
            driverClassName = "com.mysql.jdbc.Driver"
            username = "root"
            password = ""
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            //url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            url = "jdbc:mysql://localhost/test"
            driverClassName = "com.mysql.jdbc.Driver"
            username = "root"
            password = ""
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            //url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            url = "jdbc:mysql://localhost/test"
            driverClassName = "com.mysql.jdbc.Driver"
            username = "root"
            password = ""
            properties {
               // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
               jmxEnabled = true
               initialSize = 5
               maxActive = 50
               minIdle = 5
               maxIdle = 25
               maxWait = 10000
               maxAge = 10 * 60000
               timeBetweenEvictionRunsMillis = 5000
               minEvictableIdleTimeMillis = 60000
               validationQuery = "SELECT 1"
               validationQueryTimeout = 3
               validationInterval = 15000
               testOnBorrow = true
               testWhileIdle = true
               testOnReturn = false
               jdbcInterceptors = "ConnectionState"
               defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
            }
        }
    }
}

Now, when I run the application I have the following error:

ERROR pool.ConnectionPool  - Unable to create initial connections of pool.

Here's the whole error stack:

2016-08-23 16:18:58,040 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Line | Method
->>  411 | handleNewInstance             in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1129 | createCommunicationsException in com.mysql.jdbc.SQLError
|    358 | <init> . . . . . . . . . . .  in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect                   in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly . . . . . . in     ''
|   2320 | createNewIO                   in     ''
|    834 | <init> . . . . . . . . . . .  in     ''
|     46 | <init>                        in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
|    416 | getInstance                   in com.mysql.jdbc.ConnectionImpl
|    347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
|    266 | run                           in java.util.concurrent.FutureTask
|   1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run                           in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->>   79 | socketConnect                 in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    345 | doConnect                     in java.net.AbstractPlainSocketImpl
|    206 | connectToAddress . . . . . .  in     ''
|    188 | connect                       in     ''
|    172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
|    392 | connect                       in java.net.SocksSocketImpl
|    589 | connect . . . . . . . . . . . in java.net.Socket
|    538 | connect                       in     ''
|    434 | <init> . . . . . . . . . . .  in     ''
|    244 | <init>                        in     ''
|    256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
|    308 | <init>                        in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly             in     ''
|   2320 | createNewIO . . . . . . . . . in     ''
|    834 | <init>                        in     ''
|     46 | <init> . . . . . . . . . . .  in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance             in com.mysql.jdbc.Util
|    416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
|    347 | connect                       in com.mysql.jdbc.NonRegisteringDriver
|    266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
|   1142 | runWorker                     in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                           in java.lang.Thread
Error |
2016-08-23 16:19:00,132 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Line | Method
->>  411 | handleNewInstance             in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1129 | createCommunicationsException in com.mysql.jdbc.SQLError
|    358 | <init> . . . . . . . . . . .  in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect                   in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly . . . . . . in     ''
|   2320 | createNewIO                   in     ''
|    834 | <init> . . . . . . . . . . .  in     ''
|     46 | <init>                        in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
|    416 | getInstance                   in com.mysql.jdbc.ConnectionImpl
|    347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
|    266 | run                           in java.util.concurrent.FutureTask
|   1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run                           in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->>   79 | socketConnect                 in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    345 | doConnect                     in java.net.AbstractPlainSocketImpl
|    206 | connectToAddress . . . . . .  in     ''
|    188 | connect                       in     ''
|    172 | connect . . . . . . . . . . . in java.net.PlainSocketImpl
|    392 | connect                       in java.net.SocksSocketImpl
|    589 | connect . . . . . . . . . . . in java.net.Socket
|    538 | connect                       in     ''
|    434 | <init> . . . . . . . . . . .  in     ''
|    244 | <init>                        in     ''
|    256 | connect . . . . . . . . . . . in com.mysql.jdbc.StandardSocketFactory
|    308 | <init>                        in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly             in     ''
|   2320 | createNewIO . . . . . . . . . in     ''
|    834 | <init>                        in     ''
|     46 | <init> . . . . . . . . . . .  in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance             in com.mysql.jdbc.Util
|    416 | getInstance . . . . . . . . . in com.mysql.jdbc.ConnectionImpl
|    347 | connect                       in com.mysql.jdbc.NonRegisteringDriver
|    266 | run . . . . . . . . . . . . . in java.util.concurrent.FutureTask
|   1142 | runWorker                     in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                           in java.lang.Thread
Error |
2016-08-23 16:19:02,194 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Line | Method
->>  411 | handleNewInstance             in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1129 | createCommunicationsException in com.mysql.jdbc.SQLError
|    358 | <init> . . . . . . . . . . .  in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect                   in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly . . . . . . in     ''
|   2320 | createNewIO                   in     ''
|    834 | <init> . . . . . . . . . . .  in     ''
|     46 | <init>                        in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance . . . . . . in com.mysql.jdbc.Util
|    416 | getInstance                   in com.mysql.jdbc.ConnectionImpl
|    347 | connect . . . . . . . . . . . in com.mysql.jdbc.NonRegisteringDriver
|    266 | run                           in java.util.concurrent.FutureTask
|   1142 | runWorker . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    617 | run                           in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . . . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->>   79 | socketConnect                 in java.net.DualStackPlainSocketImpl
Error |
2016-08-23 16:19:02,205 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Line | Method
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  266 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Caused by CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->>  411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1129 | createCommunicationsException in com.mysql.jdbc.SQLError
|    358 | <init> .  in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly in     ''
|   2320 | createNewIO in     ''
|    834 | <init> .  in     ''
|     46 | <init>    in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance in com.mysql.jdbc.Util
|    416 | getInstance in com.mysql.jdbc.ConnectionImpl
|    347 | connect . in com.mysql.jdbc.NonRegisteringDriver
|    266 | run       in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->>   79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    345 | doConnect in java.net.AbstractPlainSocketImpl
|    206 | connectToAddress in     ''
|    188 | connect   in     ''
|    172 | connect . in java.net.PlainSocketImpl
|    392 | connect   in java.net.SocksSocketImpl
|    589 | connect . in java.net.Socket
|    538 | connect   in     ''
|    434 | <init> .  in     ''
|    244 | <init>    in     ''
|    256 | connect . in com.mysql.jdbc.StandardSocketFactory
|    308 | <init>    in com.mysql.jdbc.MysqlIO
|   2498 | coreConnect in com.mysql.jdbc.ConnectionImpl
|   2535 | connectOneTryOnly in     ''
|   2320 | createNewIO in     ''
|    834 | <init>    in     ''
|     46 | <init> .  in com.mysql.jdbc.JDBC4Connection
|    411 | handleNewInstance in com.mysql.jdbc.Util
|    416 | getInstance in com.mysql.jdbc.ConnectionImpl
|    347 | connect   in com.mysql.jdbc.NonRegisteringDriver
|    266 | run . . . in java.util.concurrent.FutureTask
|   1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
Error |
Forked Grails VM exited with errorJava HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

It seems Grails cannot find the driver or someting like that. However we've seen that the JAR file has been registered within .m2 directory. I wonder one thing: does this JAR file need to appear in the list of Grails dependencies:

enter image description here

The whole list is not on the picture but the file does not appear in the list. Is it normal ? Does the file must only appears within the .m2 directory (within the Ivy-cache this is the same, the file is not present) ? Do you think the dependency is available when I run the application ? Does Grails recognize the driver throw the classpath ?

I'm really lost.

Thanks a lot in advance for your help.


Solution

  • But I would say follow steps below one by one:

    1. Check if mysql server is installed on your machine. Case might be that you only have Mysql-client installed.

    2. In your DataSource.groovy I see many things either missing or not configures properly. Few i noticed are: a) missing dialect configuration b) missing port no. to connect to server

    Below is corrected DataSource.groovy

    dataSource {
        pooled = true
        jmxExport = true
        //driverClassName = "org.h2.Driver"
        driverClassName = "com.mysql.jdbc.Driver"
        dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
        username = "sa"
        password = ""
    }
    hibernate {
        cache.use_second_level_cache = true
        cache.use_query_cache = false
    //    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
        cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
        singleSession = true // configure OSIV singleSession mode
        flush.mode = 'manual' // OSIV session flush mode outside of transactional context
    }
    
    // environment specific settings
    environments {
        development {
            dataSource {
                dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
                //url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
                url = "jdbc:mysql://localhost:3306/test"//you had a missing port here
                driverClassName = "com.mysql.jdbc.Driver"
                username = "root"
                password = ""
            }
        }
        test {
            dataSource {
                dbCreate = "update"
                //url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
                url = "jdbc:mysql://localhost/test"
                driverClassName = "com.mysql.jdbc.Driver"
                username = "root"
                password = ""
            }
        }
        production {
            dataSource {
                dbCreate = "update"
                //url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
                url = "jdbc:mysql://localhost/test"
                driverClassName = "com.mysql.jdbc.Driver"
                username = "root"
                password = ""
                properties {
                   // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
                   jmxEnabled = true
                   initialSize = 5
                   maxActive = 50
                   minIdle = 5
                   maxIdle = 25
                   maxWait = 10000
                   maxAge = 10 * 60000
                   timeBetweenEvictionRunsMillis = 5000
                   minEvictableIdleTimeMillis = 60000
                   validationQuery = "SELECT 1"
                   validationQueryTimeout = 3
                   validationInterval = 15000
                   testOnBorrow = true
                   testWhileIdle = true
                   testOnReturn = false
                   jdbcInterceptors = "ConnectionState"
                   defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
                }
            }
        }
    }
    

    Hope it help!! Let me know if you face any issue further after the new DataSource.groovy.