gpt4 book ai didi

grails - 在 Grails 3.x 中将配置文件 application.yml 转换为 application.groovy

转载 作者:行者123 更新时间:2023-12-02 06:57:04 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的 Grails 3 项目,但遇到了一些非常简单的问题。因此,我希望我的数据源属性来 self 在 IntelliJ IDE 中设置的 VM 选项。在 Grails 2.x 之前,我经常这样做:

environments {
development{
//Database connection properties
def dbserver = System.properties.getProperty('dbserver')
def dbport = System.properties.getProperty('dbport')
............
dataSource {
url: "jdbc:sqlserver://${dbserver}:${dbport};databaseName=${dbname}
}
}

现在我有了 application.yml,如何访问“System.properties”并将其嵌入到 yml 中?我读过,如果 YML 不支持,我们可以使用 application.groovy,在这种情况下,application.groovy 看起来像这样:

grails {
profile = 'web'
codegen {
defaultPackage = 'defPack'
}
}

info {
app {
name = '@info.app.name@'
version = '@info.app.version@'
grailsVersion = '@info.app.grailsVersion@'
}
}

spring {
groovy {
template['check-template-location'] = false
}
}

hibernate {
naming_strategy = 'org.hibernate.cfg.DefaultNamingStrategy'
cache {
queries = false
}
}

grails {
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']
}
}
urlmapping {
cache {
maxsize = 1000
}
}
controllers {
defaultScope = 'singleton'
}
converters {
encoding = 'UTF-8'
}
views {
default { codec = 'html' }
gsp {
encoding = 'UTF-8'
htmlcodec = 'xml'
codecs {
expression = 'html'
scriptlets = 'html'
taglib = 'none'
staticparts = 'none'
}
}
}
}
dataSource {
pooled = true
jmxExport = true
driverClassName = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
dbCreate = ''
username = 'someUsername'
password = 'somePass'
}
environments {
development {
dataSource {
url = 'jdbc:sqlserver://localhost:1234;databaseName=someDbName;'
}
}
}

谢谢。

更新:

默认情况下,即使我删除了 application.yml,application.groovy 也不会被接收

最佳答案

结果我遇到了一个问题,我需要将“default”关键字放在引号内。喜欢:

grails {
profile = 'web'
codegen {
defaultPackage = 'defPack'
}
}

info {
app {
name = '@info.app.name@'
version = '@info.app.version@'
grailsVersion = '@info.app.grailsVersion@'
}
}

spring {
groovy {
template['check-template-location'] = false
}
}

hibernate {
naming_strategy = 'org.hibernate.cfg.DefaultNamingStrategy'
cache {
queries = false
}
}

grails {
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']
}
}
urlmapping {
cache {
maxsize = 1000
}
}
controllers {
defaultScope = 'singleton'
}
converters {
encoding = 'UTF-8'
}
views {
'default' { codec = 'html' }//THIS WAS THE SOURCE OF ERROR
gsp {
encoding = 'UTF-8'
htmlcodec = 'xml'
codecs {
expression = 'html'
scriptlets = 'html'
taglib = 'none'
staticparts = 'none'
}
}
}
}

def dbserver = System.properties.getProperty('dbserver')
def dbport = System.properties.getProperty('dbport')
def dbusername = System.properties.getProperty('dbusername')
def dbpassword = System.properties.getProperty('dbpassword')
def dbname = System.properties.getProperty('dbname')

dataSource {
pooled = true
jmxExport = true
driverClassName = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
dbCreate = ''
username = dbusername
password = dbpassword
}
environments {
development {
dataSource {
url = 'jdbc:sqlserver://${dbserver}:${dbport};databaseName=${dbname}'
}
}
}

关于grails - 在 Grails 3.x 中将配置文件 application.yml 转换为 application.groovy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30057329/

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