问题在于标题-如何在ServletContext
中获取Config.groovy
。目的是获得当前上下文的真实(绝对)路径。
最佳答案
在那里无法获得ServletContext
。
可以通过一个丑陋的解决方法来获取绝对路径:
def path = getClass().getProtectionDomain().getCodeSource().getLocation()
.getFile().replace(getClass().getSimpleName() + ".class", "").substring(1);
(
substring(1)
删除了不必要的前斜杠)
关于grails - 在Config.groovy中获取ServletContext(或如何获取当前上下文的真实路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3733928/