读书人

spring3上velocity配置有关问题解决

发布时间: 2012-09-19 13:43:54 作者: rapoo

spring3下velocity配置问题解决

在改造原有系统的过程中,想要配置spring下的velocity,原配置如下:

?

<bean id="velocityConfig"
??? ??? value="/WEB-INF/view/" />
??? ??? <property name="configLocation" value="/WEB-INF/classes/velocity.properties" />????????
??? </bean>


??? <bean id="viewResolver"
??? ??? value="false" />
??? ??? <property name="prefix" value="" />
??? ??? <property name="suffix" value=".vm" />
??? ??? <property name="toolboxConfigLocation" value="/WEB-INF/classes/toolbox.xml" />
??? ??? <property name="contentType" value="text/html;charset=utf-8" />
??? ??? <property name="exposeSpringMacroHelpers" value="true"></property>
??? </bean>
??? <!-- action -->
??? <bean id="joblist" />

?

在veloctiy.properties中配置

# 设置读取模板文件的解码格式,为了支持中文??
?input.encoding=utf-8??
# 配置输出视图文件的解码格式,为了支持中文??
?output.encoding=utf-8?

?

结果在启动时总是报一个错:

ERROR [main] app.VelocityEngine - org.apache.velocity.exception.ParseErrorException: Template.process : Unsupported input encoding : utf-8??? for template org/springframework/web/servlet/view/velocity/spring.vm

结果造成:

Error creating bean with name 'velocityConfig' defined in ServletContext resource [/WEB-INF/classes/eap-servlet-admin.xml]: Invocation of init method failed; nested exception is org.apache.velocity.exception.VelocityException: Velocimacro : Error using VM library : org/springframework/web/servlet/view/velocity/spring.vm

?

改了很多地方,可是一想,已经在velocity.properites中加了utf-8,为什么不行,把这个去掉后,不报错了,但vm页面上就必须用标记来代,不能写中文了。最后,改写成这样:

<bean id="velocityConfig"
??? ??? value="/WEB-INF/view/" />
??? ??? <property name="configLocation" value="/WEB-INF/classes/velocity.properties" />
??? ??? <!-- 这里太有意思了,因为什么不知道,但要重新再设一下input.encoding就行了 -->
??? ??? ?<property name="velocityProperties">???
???????? <props>???
???????????? <prop? key="input.encoding">UTF-8</prop>???
???????????? <prop? key="output.encoding">UTF-8</prop>?????
????????? </props>???
????? </property>?????????
??? </bean>

就行了,为什么要再设一次呢?我只能推测加载spring.vm用的属性不是在加载velocity.properites里用的属性。

因为查了很多网上资料都没什么结果,这里记一下,如有人有此问题,也好有个结论。

读书人网 >软件架构设计

热点推荐