我已经在我的系统上安装了 grails 3.0.2 和 xampp 服务器。我想通过grails连接Xampp的MySql。因此,对位于 grails-app/conf 文件夹的 application.yml 文件进行了一些更改,现在看起来像
dataSource:
pooled: true
jmxExport: true
driverClassName: "com.mysql.jdbc.JDBC4MySQLConnection"//changed driver class
username: root //username
password: 123456 //password
//现在在开发环境中我更改了 dbCreat->update 和
//url->jdbc:mysql://localhost:3306/myDB //我没有对测试和生产环境进行任何更改
环境:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/myDB;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: update
url: jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
我是 grails 新手,所以我不知道在哪里放置 mysql-connector.jar,但我已在位于 myProject/build 文件夹的 .dependencies 文件中添加了 mysql-connector.jar 的路径。
当我尝试运行我的应用程序时,它给出了很多错误,最后给出了异常
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.JDBC4MySQLConnection at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:340) at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(Poole dConnection.java:246) ... 83 more
我无法理解错误。 如果他们是我的 mysql 连接与 grails 3.0.2 和 jdk 1.8 的步骤教程的任何步骤,请发布链接。
提前致谢。
最佳答案
Grails 3.0 使用 Gradle 构建系统来:
build related tasks such as compilation, runnings tests and producing binary distrubutions of your project
因此,您可以在 build.gradle
文件的依赖项 block 内添加依赖项:
dependencies {
// other dependencies ...
runtime 'mysql:mysql-connector-java:5.1.36'
}
请参阅Grails Gradle Build documentation和 Gradle Dependency Management Basics了解更多相关信息。
关于mysql - grails 3.0.2 mysql 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32263833/