Próbuję stworzyć prosty projekt Grails 3 i utknąłem z czymś naprawdę prostym. Dlatego chcę, aby moje właściwości źródła danych pochodziły z opcji maszyn wirtualnych ustawionych w moim IDI IntelliJ. Przed w Grails 2.x, po prostu kiedyś zrobić coś takiego:Konwertuj plik konfiguracyjny application.yml na application.groovy w 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}
}
}
Teraz mam application.yml, w jaki sposób mogę uzyskać dostęp do "System.properties" i osadzić go w yml? Czytałem, że możemy zamiast używać application.groovy jeśli yml nie obsługuje, w tym przypadku jest to, co application.groovy wygląda następująco:
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;'
}
}
}
Dzięki.
UPDATE:
application.groovy nie jest podjęta w domyślnie, nawet gdy usunąłem application.yml
Do ostatniej części, trzeba by je zacytować: 'nagłówki UserAgent = [ „Gecko”, "WebKit"] ' –
@IanRoberts, dzięki temu zaktualizuję mój post. –