2

I'm struggling to set up my Grails 3.1.0 application with a local MySQL database (just on WAMP) and nothing I've tried from existing sources are working.

None of the following solutions worked for me:

Non-Solution 1

grails-app/conf/application.yml:

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

environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: jdbc:mysql://liveip.com/liveDb

build.gradle:

runtime 'mysql:mysql-connector-java:5.1.36'

Non-Solution 2

Similar, but copying the application.yml and build.gradle files from this Github starter project.

Non-Solution 3

Downloading the MySQL connector jar and referencing it in the build.gradle file according to this answer in the following way:

dependencies {

    ...

    compile files('libs/a.jar')
}

After each attempt, I've run grails clean and rebuilt in IntelliJ. Each method results in the following stack trace:

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@736e9adb;ClassLoader:sun.misc.Launcher$AppClassLoader@736e9adb
...
Caused by: java.lang.ClassNotFoundException: Unable to load class: com.mysql.jdbc.Driver" from ClassLoader:sun.misc.Launcher$AppClassLoader@736e9adb;ClassLoader:sun.misc.Launcher$AppClassLoader@736e9adb
    at org.apache.tomcat.jdbc.pool.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:56) ~[tomcat-jdbc-8.0.30.jar:na]
...
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver"
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_05]
Community
  • 1
  • 1
Joshua S.
  • 113
  • 9
  • 1
    take a close look at the post you referred to and your own config. Specifically tab/spacing around the heading: sub content elements. This config file is specific about spacing dataSource: pooled: true that should be dataSource:[enter][tab]pooled:true – V H Mar 24 '16 at 17:56
  • @vahid I used the correct formatting in the code, but I didn't put the proper indentation when copying it to this question, so unfortunately not the issue. Thanks for pointing it out! Edited. – Joshua S. Mar 24 '16 at 18:01
  • what goes wrong with 1 then. Your errors are related to not finding jar which really relate to your 3rd solution. Its easiest with 1st and I have it working – V H Mar 24 '16 at 18:13
  • try upgrading to 3.1.4 mine is running on that. I haven't test 3.1.0 specifically – V H Mar 24 '16 at 18:38

1 Answers1

2

Here is mine

build.gradle:

dependencies {
    runtime 'mysql:mysql-connector-java:5.1.20'

}

Now application.yml:

dataSources:
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: com.mysql.jdbc.Driver
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        username: username
        password: opendoor_policy
    nextdbsource:
        pooled: true
        jmxExport: true
        driverClassName: com.mysql.jdbc.Driver
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
        username: username
        password: opendoor_policy
        url: jdbc:mysql://localhost:3306/nextdbsource?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8
        dbCreate: update

environments:
    development:
        dataSources:
            dataSource:
                dbCreate: update
                url: jdbc:mysql://localhost:3306/db1?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8
    test:
        dataSources:
            dataSource:
                dbCreate: update
                url: jdbc:mysql://localhost:3306/db1?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8
    production:
        dataSources:
            dataSource:
                dbCreate: update
                url: jdbc:mysql://localhost:3306/db1?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8
                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

---

that works for me and it sets up 2 data sources

V H
  • 7,752
  • 2
  • 24
  • 43
  • Unfortunately same issue. I'm going to try your suggestion of upgrading to see if that helps. – Joshua S. Mar 24 '16 at 19:06
  • @JoshuaS. I have a generic way of upgrading - get the version create an app in that version then copy grails-app/[controllers/views/services/taglib/config/application.groovy] and if I have src/main/groovy folders in place then copy them too. the finally update the buildconfig to call in any plugins and review the config files - thats it in a nutshell swift upgrade – V H Mar 24 '16 at 19:18
  • 1
    It looks like the upgrade didn't help, but running it via the Grails console as opposed to through IntelliJ worked perfectly. If you use IntelliJ for Grails development, any idea why the IntelliJ run would cause the exception but wouldn't through the Grails console? – Joshua S. Mar 24 '16 at 20:49
  • @JoshuaS. I guess it all depends on what the issue returned from intelij is - I would start by checking the settings of intelij - inside settings search for sdk make sure its set to correct version SDK for grails that is. Then I would check JDK (ctrl shift alt + s) and ensure that is all correctly setup. Lastly I go into all my ide's using console and always ensure Ihave running the relevant version of grails and jdk pre going into it. I think the first 2 points should answer it for you – V H Mar 24 '16 at 21:06