Grails Functional Testing - grailsApplication.config is null within controllers and services

前端 未结 2 1485
鱼传尺愫
鱼传尺愫 2020-12-17 06:12

Grails 1.3.5

I\'ve written a handful of functional tests and I\'m running into issues when my controllers and services reference configuration data via grailsApplica

相关标签:
2条回答
  • 2020-12-17 06:23

    You need to construct the grails app -- as it is not injected by default.

    youService.grailsApplication = new org.codehaus.groovy.grails.commons.DefaultGrailsApplication()
    

    "DefaultGrailsApplication" by it's default configuration will look for Config as the config class.

    0 讨论(0)
  • 2020-12-17 06:34

    This is the hack that I have done for a while, there might be a better way though

    def filePath = new File('grails-app/conf/Config.groovy').toURL()
    def config = new ConfigSlurper(System.properties.get('grails.env')).parse(filePath)
    ConfigurationHolder.config = config
    
    0 讨论(0)
提交回复
热议问题