5
config.groovy
에 정의 된 값으로 static
변수를 초기화하는 방법은 무엇입니까?Grails : config.groovy에 정의 된 값으로 정적 변수를 초기화하십시오.
은 현재 내가 이런 일이 : 나는 각 방법 안에 http
변수를 정의하지 않으
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}")
...
}
}
를 (여러 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}")
}
}
어떤 단서?
감사합니다. Ian! 매력처럼 작동 :) – Agorreca