static
değişkenini config.groovy
içinde tanımlanmış bir değerle nasıl başlatabilirim?Grails: bir statik değişkeni config.groovy içinde tanımlanmış bir değerle başlatabilirsiniz
Şu anda böyle bir şey var: Her yöntem içinde http
değişken tanımlamak istemiyorum
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}")
...
}
}
(birkaç GET, POST, PUT ve DELETE).
http
değişkeninin hizmet içinde static
değişken olarak olmasını istiyorum.
class ApiService {
static grailsApplication
static http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
JSON get(String path) {
http.get(...)
...
}
}
Ben
Cannot get property 'config' on null object
olsun. ile aynı:
class ApiService {
def grailsApplication
static http
ApiService() {
super()
http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
}
JSON get(String path) {
http.get(...)
...
}
}
Ayrıca ben
static
tanımı olmadan çalıştı, ancak
Cannot get property 'config' on null object
aynı hata:
class ApiService {
def grailsApplication
def http
ApiService() {
super()
http = new HTTPBuilder("${grailsApplication.config.grails.api.server.url}")
}
}
Herhangi ipucu?
Teşekkürler Ian! ÇALIŞIYOR bir cazibe gibi :) – Agorreca