在Grails 3中设置数据库的最新方法是什么?
问题描述:
如何在Grails 3中设置数据库?手册在这里看起来已过时: http://grails.github。 io / grails-doc / 3.0.x / guide / single.html#dataSource
How to set database in Grails 3? Manual looks obsolete here: http://grails.github.io/grails-doc/3.0.x/guide/single.html#dataSource
因为它给出了使用树丛代码进行设置的示例,如下所示:
since it gives an example of setting with grove code like follows:
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/my_database"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "username"
password = "password"
...
而我有 application.yml
与
dataSource:
pooled: true
jmxExport: true
driverClassName: org.h2.Driver
username: sa
password:
最新的方法是什么?
答
从GORM 3.2.2开始在图6中,grails文档是最新且正确的,不再需要在4月7日第一个回答日期中显示的额外配置。示例数据源配置为:
As of grails 3.2.2 with GORM 6, the grails documentation is current and correct and this "extra" config shown in the first answer date Apr 7 is no longer necessary. An example dataSource config is:
---
---
dataSources:
hibernate:
cache:
queries: true
use_second_level_cache: true
use_query_cache: true
region.factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'
dataSource:
pooled: true
# pool_size: 15
jmxExport: true
driverClassName: org.postgresql.Driver
dataSource_two:
pooled: true
# pool_size: 15
jmxExport: true
driverClassName: org.postgresql.Driver
#############################################################
# Spring Actuator Endpoints are Disabled by Default
#############################################################
---
---
endpoints:
enabled: false
jmx:
enabled: true
---
---
grails:
codegen:
defaultPackage: com.healthreveal
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
profile: rest-api (or web)
spring:
transactionManagement:
proxies: false
urlmapping:
cache:
maxsize: 1000
---
---
# you would think you could put this in the section above, but for some reason you can't
grails.logging.jul.usebridge: true
---
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
---
---
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
---
---
spring:
groovy:
template:
check-template-location: false
#################################################################
# This second section is a set of environment-specific over-rides
# to the common parameters. There is no need to repeat a
# common parameter unless you want to change the setting (or add
# a new setting) within the context of an environment.
#################################################################
---
---
environments:
development:
dataSources:
dataSource:
dbCreate: update
url: jdbc:postgresql://localhost:5432/dbOne
username: someuser
password: somepassword
dataSource_xyz:
dbCreate: update
url: jdbc:postgresql://localhost:5432/dbXYZ
username: someuser
password: somepassword
grails:
serverURL: "http://localhost:8080"
plugin:
forceSSL:
enabled: false
server:
port: 8080
ssl:
enabled: false