我正在尝试从服务中的集成测试访问servletContext(应用程序上下文)。
以下是我在集成测试中允许它的方法:
import org.codehaus.groovy.grails.web.context.ServletContextHolder as SCH
class ScraperServiceIntegrationTests extends GroovyTestCase {
ScraperService scraperService
def testStoring() {
scraperService = new ScraperService()
scraperService.servletContext = new SCH()
scraperService.storing()
...
}
...
}
以下是我在服务中使用servlet上下文的方法:
class ScraperService {
static transactional = true
def servletContext
synchronized def storing() {
servletContext.numberOfCreditProvider = "whatever"
...
}
...
}
我收到了以下错误信息:
No such property: numberOfCreditProvider for class: org.codehaus.groovy.grails.web.context.ServletContextHolder
我该如何解决这个错误?