Following symbolic link in Grails 3

蓝咒 提交于 2019-12-07 22:01:10

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/38268498/following-symbolic-link-in-grails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!