且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Grails应用程序配置注入服务

更新时间:2022-10-20 16:53:58

The grailsApplication object is available within services, allowing this:

package example

import com.example.ExampleApiClient;

class ExampleService {

    def grailsApplication

    def relevantMethod() {

        def client = new ExampleApiClient(
            grailsApplication.config.apiCredentials.baseUrl
            grailsApplication.config.apiCredentials.username,
            grailsApplication.config.apiCredentials.password
        )

        return client.action();
    }
}

相关阅读

技术问答最新文章