如何使用 web-api 配置文件在 Grails 3.1.x 上配置 MySQL 数据源?
How to configure a MySQL DataSource on Grails 3.1.x with web-api profile?
我从 v1.3.x 开始就在使用 Grails,现在 DataSource/GORM 配置我没有成功...
我的步骤是:
1 - $ grails create-app myApi --profile=web-api.
2 - 配置 application.yml 文件:
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password:
environments:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/test-app
3 - 在 build.gradle 文件中,将 运行 时间依赖性 "com.h2database:h2" 替换为"mysql:mysql-connector-java:5.1.37"
4 - 创建一个名为 test-app
的数据库
5 - 创建域:$grails create-domain-class MyDomain
6 - 在 MyDomain classe 上添加一个名为 name
的字符串属性
示例:
package myapi
class MyDomain {
String name
static constraints = { }
}
7 - 运行 应用程序:$grails 运行-app
输出:
Running application...
objc[27851]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Grails application running at http://localhost:8080 in environment: development
并且没有创建任何表...有人知道我在这里缺少哪一步吗?
OBS.: 即使我拼错了数据库名称,应用程序仍然 运行ning 并且没有错误发生。
默认情况下不包含 Hibernate 插件作为 Grails 3.1.0.M2 和 web-api[=19= 的正常依赖项] 配置文件,所以为了解决这个问题,您只需添加依赖项:
runtime "org.grails.plugins:hibernate:4.3.10.7"
我从 v1.3.x 开始就在使用 Grails,现在 DataSource/GORM 配置我没有成功...
我的步骤是:
1 - $ grails create-app myApi --profile=web-api.
2 - 配置 application.yml 文件:
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
username: root
password:
environments:
development:
dataSource:
dbCreate: update
url: jdbc:mysql://localhost:3306/test-app
3 - 在 build.gradle 文件中,将 运行 时间依赖性 "com.h2database:h2" 替换为"mysql:mysql-connector-java:5.1.37"
4 - 创建一个名为 test-app
的数据库5 - 创建域:$grails create-domain-class MyDomain
6 - 在 MyDomain classe 上添加一个名为 name
的字符串属性
示例:
package myapi
class MyDomain {
String name
static constraints = { }
}
7 - 运行 应用程序:$grails 运行-app
输出:
Running application...
objc[27851]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Grails application running at http://localhost:8080 in environment: development
并且没有创建任何表...有人知道我在这里缺少哪一步吗?
OBS.: 即使我拼错了数据库名称,应用程序仍然 运行ning 并且没有错误发生。
默认情况下不包含 Hibernate 插件作为 Grails 3.1.0.M2 和 web-api[=19= 的正常依赖项] 配置文件,所以为了解决这个问题,您只需添加依赖项:
runtime "org.grails.plugins:hibernate:4.3.10.7"