2

我真的是Grails技术的初学者。我为Windows 64位安装了IDE Groovy/Grails Tool Suite™(GGTS,Grails 2.4.4)。使用Grail 2.4.4配置MySQL数据库(无法创建池的初始连接)

有关JDK和Grails的环境路径已经正确更新。

我创建了一个名为“测试”的新项目,添加了名为“test.User”一个新的域类如下:

package test 

class User { 

    Integer id 
    String firstName 
    String lastName 

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

应用于静态脚手架生成带有CRUD操作关联的相应UserController中和看法。

要检查我的数据模型是否与H2数据库一起工作,我对DataSource.groovy文件进行了一些更新,它的工作原理是:我添加了一个新用户抛出应用程序,并在我的表上运行SELECT *命令时USER(使用grails dbconsole),并显示我的新用户条目。所以,直到这里一切都好!

但现在我想用另一个SQL数据库连接我的应用程序使用不同的JDBC连接器。我选择(为了兼容性的缘故)我BuildConfig.groovy文件中提出的一个注释去掉它:

runtime mysql:mysql-connector-java:5.1.29 

当我运行应用程序“运行应用程序”(默认情况下,我认为我们是在开发环境)我注意到依赖关系mysql-connector-java-5.1.29.jar已被添加到我的.m2目录(C:\ Users \ my_user_name.m2 \ repository \ mysql \ mysql-connector-java \ 5.1.29)中。所以我认为依赖关系在Grails中的一种MAVEN文件中正确注册。但是该文件不会出现在ivy-cache目录中。这是正常的吗?

我BuildConfig.groovy文件内容:

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

关于DataSource.groovy文件我换成关于驱动程序名称行:

driverClassName = "org.h2.Driver" 

通过

driverClassName = "com.mysql.jdbc.Driver" 

和每个环境(我知道我只使用开发环境,但它只是为了避免一些错误)再次

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

通过

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

我还添加仅低于默认的用户名和密码(如root用户)+驱动程序类的名称如下(为每个环境中:我更换了以下线):

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

这是我的数据源。常规文件内容:

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

现在,当我跑,我有以下错误的应用程序:

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

这里是整个错误堆栈:

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 

看来Grails中找不到司机或类似的东西。但是我们已经看到JAR文件已经在.m2目录中注册过了。我不知道一两件事:这是否JAR文件必须出现在Grails的依赖关系列表:

enter image description here

整个名单上没有图像,但该文件没有出现在列表中。这是正常的吗?该文件只能出现在.m2目录中(在Ivy-cache中,这是相同的,该文件不存在)?当我运行该应用程序时,您认为依赖关系是否可用? Grails是否承认驱动程序会抛出类路径?

我真的迷路了。

非常感谢您的帮助。

+1

请注意,MySQL JDBC Driver类会显示在您的错误跟踪中。这表明您的应用程序正在使用MySQL JDBC jar *。找不到JDBC驱动程序完全是另一个例外。问题是您的应用程序无法连接到您的MySQL实例。您是否正确配置了数据源(URL,凭证)?您的示例代码为MySQL根用户显示一个空白密码... – jstell

回答

0

,但是我要说按照以下步骤一个接一个:

  1. 检查MySQL服务器安装在您的计算机上。情况可能是您只安装了Mysql客户端。

  2. 在你的DataSource.groovy中,我看到很多东西丢失或没有正确配置。少数我注意到: a)缺少方言配置 b)缺少端口号。连接到服务器

下面是纠正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 
      } 
     } 
    } 
} 

希望它能帮助!让我知道如果你在新的DataSource.groovy之后再面对任何问题。

+0

谢谢!很明显。我忘了安装MySQL服务器:)。我告诉过你,我是新手!现在关于DataSource.groovy文件,没有必要提供SQL休眠“方言”。我认为这是Grails中的默认语句(但我认为无论如何精确地更好)。而且也没有必要精确的端口太多(我在本地主机和'grails.server.port.http'在BuildConfig.groovy文件中不精确,所以默认为'8080')。所以,再次感谢您的帮助!再见。 – user1364743