grails - 如何导出Config.groovy中相对目录的物理路径?

标签 grails groovy

我正在尝试使用来自GitHub的源代码来设置Weceem。它需要一个用于上载目录的物理路径定义,并需要一个似乎用于写入可搜索索引的目录。上载的默认设置是:

weceem.upload.dir = 'file:/var/www/weceem.org/uploads/'

我想使用诸如WEB-INF / resources / uploads之类的相对路径来定义那些路径。我尝试了一种以前用相对路径访问目录的方法:
  File uploadDirectory = ApplicationHolder.application.parentContext.getResource("WEB-INF/resources/uploads").file
  def absoluteUploadDirectory = uploadDirectory.absolutePath
  weceem.upload.dir = 'file:'+absoluteUploadDirectory

但是,ApplicationHolder.application下的“parentContext”为NULL。谁能为此提供解决方案,让我使用相对路径?

最佳答案

查看您应该拥有的Config.groovy(也许已注释)

// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts

// "classpath:${appName}-config.properties", "classpath:${appName}-config.groovy",
grails.config.locations = [
        "file:${userHome}/.grails/${appName}-config.properties",
        "file:${userHome}/.grails/${appName}-config.groovy"
]

在部署服务器中创建Conig文件
"${userHome}/.grails/${appName}-config.properties"

并在该配置文件中定义您的 Prop (甚至不是相对路径)。

关于grails - 如何导出Config.groovy中相对目录的物理路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10629151/

相关文章:

grails - 如何在Grails Webflow插件中获取当前 View 状态名称

mongodb - 如何在 Grails 2.4.2 项目中集成 Spring Data Neo4j 和 Mongodb

hibernate - Grails和Hibernate:未知实体:com.mypackage.Role

authentication - grails:可重用的身份验证拦截器

Grails Spring Security(获取当前用户)

model-view-controller - Grails-路径中的用户名

java - Gradle 6.0 和 PMD 6.15 集成,如何在超出允许的违规限制时使构建失败

java - 获取分配给剖面 View 中特定剖面的所有作业

spring - Groovy Spring Bean 类路径

gradle - 来自 gradle 属性文件的 Groovy 字符串表现不正常