问题描述
我的Web应用程序使用Spring MVC和Freemarker.在启动后必须首先呈现网页(使用Freemarker 2.3.22)时,它会记录警告消息:
My web-application uses Spring MVC and Freemarker. When it must first render a web page (using Freemarker 2.3.22) after starting up, it logs a warning message:
Custom EL functions won't be loaded because no ObjectWarpper was specified
(是,ObjectWarpper
;错误消息有错字)
(Yes, ObjectWarpper
; the error message has typo)
但是,我想我 do 在我的配置bean中指定了ObjectWrapper
:
However, I think I do have an ObjectWrapper
specified in my configuration bean:
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/views/" />
<property name="freemarkerSettings">
<props>
<prop key="url_escaping_charset">UTF-8</prop>
<prop key="object_wrapper">DefaultObjectWrapper(2.3.22)</prop>
</props>
</property>
</bean>
那我该怎么做才能正确设置ObjectWrapper
并防止记录此警告消息?
So what must I do to correctly set up an ObjectWrapper
and prevent this warning message being logged?
如果使用default
object_wrapper
,我也会遇到同样的问题.
I have the same problem if I use a default
object_wrapper
.
推荐答案
这个问题也困扰着我,我检查了org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer类的源代码,发现没有初始化的taglibFactory设置了ObjectWrapper.
This problem also bothered me, I checked the source code of the org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer class and found the taglibFactory inited without ObjectWrapper being set.
因此,我扩展了FreeMarkerConfigurer类,并重写了getTaglibFactory()方法,并替换了spring mvc配置.这是我的代码:
So I extend the FreeMarkerConfigurer class and override the getTaglibFactory() method and replace the spring mvc config. Here is my code:
public class DefaultFreeMarkerConfigurer extends FreeMarkerConfigurer {
@Override
public TaglibFactory getTaglibFactory() {
TaglibFactory tagLibFactory = super.getTaglibFactory();
if (tagLibFactory.getObjectWrapper()==null) {
tagLibFactory.setObjectWrapper(super.getConfiguration().getObjectWrapper());
}
return tagLibFactory;
}
}
这篇关于由于未指定ObjectWarpper,因此不会加载自定义EL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!