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

4
在Spring中,我们可以同时在文件系统和类路径中加载freemarker模板吗?我们将Web应用程序的所有页面放在JAR包中,Spring会首先查找文件系统,如果没有找到,则会在类路径中查找。每当我们想要覆盖某个页面时,只需在我们在配置中指定的Web应用程序的某个文件夹中创建一个新页面即可。通过这种方法,我的Web应用程序可以在不停止服务器的情况下进行热检测。
1个回答

0

您可以使用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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接