2011-07-08 33 views
4

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

回答

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