【发布时间】:2021-12-22 09:33:02
【问题描述】:
我的代码最后进入 else 块,并在战争模式下(部署到 tomcat)记录“找不到文件”,但在开发模式下,在调用方法时使用相同的参数可以正常工作。该文件存在于 grails 3 默认文件结构中 = grails-app/i18n/messages.properties
def index= {
log.debug params.id
def f = new File("grails-app/i18n/${params.id}")
log.info("i18n Controller ---" + f.toString())
InputStream stream = null
if (f.exists()) {
stream = new FileInputStream("grails-app/i18n/${params.id}")
} else {
ServletContext sc = grailsApplication.parentContext.servletContext
def res = sc.getResource("/WEB-INF/grails-app/i18n/${params.id}")
if (res) {
stream = sc.getResourceAsStream("/WEB-INF/grails-app/i18n/${params.id}")
}
}
if (stream) {
log.debug "Streaming"
render stream.text
} else {
log.debug "Not found"
render '#Message bundle not found'
}
}
造成这种不同行为的原因可能是什么?
【问题讨论】:
标签: java file tomcat grails groovy