[英]Create Freemarker Configuration bean in Spring, together with parameter
I am having trouble creating a "freemarker.template.Configuration" bean and setting global shared variables in this instance of the Configuration. 我在创建“ freemarker.template.Configuration” bean并在此Configuration实例中设置全局共享变量时遇到了麻烦。 Something like:
就像是:
<bean id="conf" class="freemarker.template.Configuraton">
<property name="sharedVariable" >
**??**
</property>
</bean>
Is this possible? 这可能吗? I can't use FreeMarkerConfigurer instead of Configurer because I am using servlets (full stack of Spring MVC) as controllers in my project.
我不能使用FreeMarkerConfigurer而不是Configurer,因为我在项目中使用servlet(Spring MVC的完整堆栈)作为控制器。 Is there any way to convert a FreemarkerConfigurer into a Configurer?
有什么方法可以将FreemarkerConfigurer转换为Configurer?
The problem stems from that shared variables is not a JavaBean property... but, accidentally, Configuration
has a setAllSharedVariables(TemplateHashModelEx)
method, that's technically a property, so something like this should work (I haven't tried it and my Spring XML is rusty... tell me if there are typos in it): 问题源于共享变量不是JavaBean属性...但是,偶然地,
Configuration
具有setAllSharedVariables(TemplateHashModelEx)
方法,从技术上讲,这是一个属性,因此类似这样的方法应该可以工作(我没有尝试过,而且我的Spring XML生锈...告诉我其中是否有错字):
<bean id="conf" class="freemarker.template.Configuraton">
<property name="allSharedVariables">
<bean class="freemarker.template.SimpleHash">
<constructor-arg>
<map>
<entry key='someVarName' value='someValue' />
<entry key='otherVarName' value-ref='valueBeanId' />
</map>
</constructor-arg>
</bean>
</property>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.