1

我有一个具有以下参数的属性文件

 PAGINATION1=10
 PAGINATION2=20

在我的 config.groovy 文件中,我设置了

  grails.config.locations = ["classpath:default.properties","file:"+ fullPath]

读取属性文件值。

我可以使用访问控制器中的属性值

 grailsApplication.config.PAGINATION1

它工作正常。

我访问了我按照以下链接的属性文件

http://burtbeckwith.com/blog/?p=993&cpage=1

 class  Pagination  {

   int paginationNumber;

   static someMethod() {
    def grailsApplication = new Pagination().domainClass.grailsApplication
    def config = grailsApplication.config
    return config
}

    static constraints={
    def grailsConfig=someMethod();
    paginationNumber inList:[grailsConfig.PAGINATION1,'20','30','40']
}

}

但我收到以下错误。

      Caused by MissingPropertyException: No such property: domainClass for class: com.nagra.ms.sam.util.Pagination
      ->>   32 | someMethod in com.nagra.ms.sam.util.Pagination

      |     42 | doCall    in com.nagra.ms.sam.util.Pagination$__clinit__closure1
      |     72 | evaluate  in org.grails.datastore.mapping.config.groovy.MappingConfigurationBuilder
      |     51 | createMappedForm in org.grails.datastore.mapping.config.AbstractGormMappingFactory
      |     41 | <init> .  in org.grails.datastore.mapping.document.config.DocumentPersistentEntity$DocumentCollectionMapping
      |     26 | <init>    in org.grails.datastore.mapping.document.config.DocumentPersistentEntity
      |     63 | createPersistentEntity in org.grails.datastore.mapping.document.config.DocumentMappingContext
      |    159 | addPersistentEntityInternal in org.grails.datastore.mapping.model.AbstractMappingContext
      |    152 | addPersistentEntity in     ''
      |     63 | getObject in org.grails.datastore.gorm.bean.factory.AbstractMappingContextFactoryBean
      |    334 | innerRun  in java.util.concurrent.FutureTask$Sync
      |    166 | run       in java.util.concurrent.FutureTask
      |   1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
      |    603 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
      ^    722 | run . . . in java.lang.Thread

谁能知道如何访问域类中的属性文件值

4

0 回答 0