0

有这样的引导程序:

class BootStrap {                                                                                                                                                                                                                              

    def init = { servletContext ->                                                                                                                                                                                                             
      def file = servletContext.getResource("ehcache.xml")                                                                                                                                                                                     
       println "+++ ${file}"                                                                                                                                                                                           
    }                                                                                                                                                                                                                                          
    def destroy = {                                                                                                                                                                                                                            
    }                                                                                                                                                                                                                                          
}   

应用程序包含ehcache.xmlgrails-app/conf 目录中的文件,但它打印

+++ 空

在引导期间。问题是什么?

4

1 回答 1

3

servletContext.getResource不在类路径上,它在web-app. 改为尝试(这可能需要闭包之外的grailsApplication.classLoader.getResource类级别,我不确定)。def grailsApplicationinit

或者,将文件移动到web-app/WEB-INF,然后

servletContext.getResource('/WEB-INF/ehcache.xml')

应该管用。

于 2013-01-06T10:23:00.707 回答