gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:27:18 25 4
gpt4 key购买 nike

这个问题已经被问过很多次了,但是给出的答案都没有解决我的问题:我用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com