Configuring Grails 3.1.0 with MySQL

I am trying to configure a Grails 3.1.0 application on a local MySQL database (only on WAMP), and nothing that I tried to use from existing sources does not work.

None of the following solutions worked for me:

Not a solution 1

Grails application / 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' 

Not decision 2

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

Not decision 3

Download the MySQL connector and referring to it in the build.gradle file according to this answer as follows:

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

After each attempt, I ran grails clean and rebuilt in IntelliJ. Each method leads to 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] 
+2
source share
1 answer

Here is my

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 --- 

which works for me and it sets 2 data sources

+1
source

Source: https://habr.com/ru/post/1240717/


All Articles