遵循Grails 3中的符号链接 [英] Following symbolic link in Grails 3

查看:144
本文介绍了遵循Grails 3中的符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Grails 2.x中,为了允许以下符号链接,我们可以在 scripts / _Events.groovy 中添加以下内容:

  eventConfigureTomcat = {tomcat  - > 
def ctx = tomcat.host.findChild()
ctx.allowLinking = true //关注软链接
}

我们如何在Grails 3中实现相同的功能?我试过在Grails 3的 src / main / scripts 目录下创建相同的脚本文件,但没有帮助。



编辑:



我也尝试在 Bootstrap.groovy

  Holders.getServletContext()。allowLinking = true 

GitHub issue#10045

解决方案

最后,我已经通过 graemerocher 。



您只需将以下内容添加到 ./ grails-app / init /< package> /Application.groovy

  @Bean 
EmbeddedServletContainerFactory containerFactory(){
TomcatEmbeddedServletContainer Factory containerFactory = new TomcatEmbeddedServletContainerFactory()

containerFactory.addContextCustomizers(new TomcatContextCustomizer(){
@Override
void customize(Context context){
StandardRoot root = new StandardRoot (context)
root.setAllowLinking(true)
context.setResources(root)
}
});

return containerFactory
}

要导入的软件包:

  import org.apache.catalina.Context 
import org.apache.catalina.webresources.StandardRoot
import org .springframework.boot.context.embedded.EmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
import org.springframework.context.annotation.Bean


In Grails 2.x, to allow following symbolic links, we can add following in the scripts/_Events.groovy:

eventConfigureTomcat = { tomcat ->
    def ctx = tomcat.host.findChild("")
    ctx.allowLinking = true     // Follow soft links
}

How can we achieve the same in Grails 3? I've tried creating the same script file in src/main/scripts directory in Grails 3 but didn't help.

Edit:

I also tried adding following line in Bootstrap.groovy:

Holders.getServletContext().allowLinking = true

GitHub issue #10045

解决方案

Finally, I've figured out the solution for following symbolic link in Grails 3 with the help of examples provided by graemerocher.

You just need to add the following to your ./grails-app/init/<package>/Application.groovy:

@Bean
EmbeddedServletContainerFactory containerFactory() {
    TomcatEmbeddedServletContainerFactory containerFactory = new TomcatEmbeddedServletContainerFactory()

    containerFactory.addContextCustomizers(new TomcatContextCustomizer() {
        @Override
        void customize(Context context) {
            StandardRoot root = new StandardRoot(context)
            root.setAllowLinking(true)
            context.setResources(root)
        }
    });

    return containerFactory
}

Packages to import:

import org.apache.catalina.Context
import org.apache.catalina.webresources.StandardRoot
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
import org.springframework.context.annotation.Bean

这篇关于遵循Grails 3中的符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆