Я пытаюсь создать простой проект Grails 3 и застрял на чем-то очень простом. Поэтому я хочу, чтобы свойства источника данных исходили из параметров виртуальной машины, которые я установил в своей IntelliJ IDE. Раньше в 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? Я читал, что мы можем вместо этого использовать application.groovy, если YML не поддерживает его, в этом случае это то, как выглядит 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.groovy не используется по умолчанию, даже когда я удалил application.yml
userAgents = ['Gecko', 'WebKit']
- person Ian Roberts   schedule 05.05.2015