繁体   English   中英

从 Spring 中的类路径和文件系统加载 freemarker 模板

[英]Load freemarker template from classpath and filesystem in Spring

在 Spring 中,我们可以在文件系统和类路径中加载 freemarker 模板吗? All of the pages of web application we put in jar bundle, Spring will lookup in filesystem first if not found then it will search in classpath, whenever we want to override some page we just create a new one in some folder of web application that we在配置中指定。 使用这种方法,我的 web 应用程序可以在不停止服务器的情况下进行热检测。

您可以使用您的 ApplicationContext 实例使用getResource查找资源并使用它们:

ApplicationContext context = //load your app context
Resource resource = context.getResource("relative/file/path.fmk");
if ( !resource.exists() ) {
  resource = context.getResource("classpath:inside/your/classpath/path.fmk");
}

// do whatever you would like to do with this resource

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM