2012-09-14 82 views
1

我在Spring中使用freemarker。無法解析模板加載器路徑Freemarker

這是我配置我的freemarker方式:

<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">  
    <property name="templateLoaderPath" value="classpath:/META-INF/templates"/>  
</bean> 

這種結構實際上是工作的罰款,我能夠使用模板來生成我的報告等

但是在WebLogic中,我總是得到這個例外:

15 Sep 2012 01:03:02,060 DEBUG DefaultListableBeanFactory.doCreateBean:504 - Eagerly caching bean 'freemarkerConfiguration' to allow for resolving potential circular references 
15 Sep 2012 01:03:02,074 DEBUG DefaultListableBeanFactory.invokeInitMethods:1498 - Invoking afterPropertiesSet() on bean with name 'freemarkerConfiguration' 
15 Sep 2012 01:03:02,228 DEBUG FreeMarkerConfigurationFactoryBean.getTemplateLoaderForPath:360 - Cannot resolve template loader path [classpath:/META-INF/templates] to [java.io.File]: using SpringTemplateLoader as fallback 
java.io.FileNotFoundException: class path resource [META-INF/templates] cannot be resolved to absolute file path because it does not reside in the file system: zip:C:/Oracle/Middleware/user_projects/domains/gppuser/servers/GPPFilesBCSIS/tmp/_WL_user/GPPFilesBCSIS/phxni8/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/templates 
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204) 
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52) 
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.getTemplateLoaderForPath(FreeMarkerConfigurationFactory.java:351) 
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.createConfiguration(FreeMarkerConfigurationFactory.java:304) 
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean.afterPropertiesSet(FreeMarkerConfigurationFactoryBean.java:60) 

這個錯誤實際上是在加載過程中發生的。任何人都知道如何解決和刪除這個異常?該文件實際上仍然使用提供的模板生成,所以我不確定這個錯誤是什麼。

對於您的信息:我沒有使用爆炸部署。

回答

2

這是沒什麼好擔心的。請注意,日誌級別是DEBUG,而不是ERROR或WARNING。

當模板目錄可訪問通過java.io.File(因爲它不是一個jarwar等內),Spring將配置FreeMarker的使用java.io.File直接加載模板,因爲這樣的FreeMarker,可以檢查的最後修改時間和自動重新加載模板。爲了找出路徑是否可以映射到一個普通的目錄,Spring將調用Resource.getFile()並查看它是否拋出IOException。如果是這樣,Spring會記錄DEBUG級別,然後配置FreeMarker通過Spring的資源抽象(當然不使用Resource.getFile)加載模板。所以這是你的情況下正常的程序流程。

+0

但模板目錄在我的war文件中(並且也直接在war文件中訪問) – Rudy

+0

是的。這就是爲什麼Spring的'Resource'機制被用來代替'File',正如我上面所解釋的那樣。再次,這是正常的。它只是一個調試消息,而不是錯誤消息。 (除非確實在調試,否則不應該存儲調試級別的消息。)或者這有什麼問題? – ddekany