Ich versuche, ein einfaches Grails 3 Projekt zu erstellen und blieb mit etwas wirklich einfach stecken. Ich möchte, dass meine Datenquelleneigenschaften von VM-Optionen stammen, die ich in meiner IntelliJ-IDE festgelegt habe. Bevor in Grails 2.x, habe ich nur so etwas wie:konvertieren Konfigurationsdatei application.yml zu application.groovy in Grails 3.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}
}
}
Nun, da ich habe application.yml, wie greife ich auf „System.properties“ und binde sie in yml? Ich habe gelesen, dass wir stattdessen application.groovy verwenden können, wenn YML es nicht unterstützt, in diesem Fall das ist, was die application.groovy wie folgt aussehen:
grails {
profile = 'web'
codegen {
defaultPackage = 'defPack'
}
}
info {
app {
name = '@[email protected]'
version = '@[email protected]'
grailsVersion = '@[email protected]'
}
}
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;'
}
}
}
Dank.
UPDATE:
application.groovy ist standardmäßig eingelassenes nicht werden, auch wenn ich application.yml
Für den letzten Teil, können Sie sie zitieren müsste: '= Useragents [ 'Gecko', 'WebKit'] ' –
@IanRoberts, danke ich werde meinen Beitrag aktualisieren. –