static
で定義された値で変数を初期化するにはどうすればよいconfig.groovy
ですか?
現在、私はこのようなものを持っています:
class ApiService {
JSON get(String path) {
def http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
...
}
JSON get(String path, String token) {
def http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
...
}
...
JSON post(String path, String token) {
def http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
...
}
}
http
各メソッド(いくつかのGET、POST、PUT、およびDELETE)内で変数を定義したくありません。
http
変数をサービス内の変数として使用したいと思いstatic
ます。
私はこれを試しましたが成功しませんでした:
class ApiService {
static grailsApplication
static http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
JSON get(String path) {
http.get(...)
...
}
}
取得しCannot get property 'config' on null object
ます。同じ:
class ApiService {
def grailsApplication
static http
ApiService() {
super()
http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
}
JSON get(String path) {
http.get(...)
...
}
}
また、定義なしで試しましstatic
たが、同じエラーCannot get property 'config' on null object
です:
class ApiService {
def grailsApplication
def http
ApiService() {
super()
http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
}
}
どんな手掛かり?