spring3下velocity配置问题解决

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

 

<bean id="velocityConfig"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" value="/WEB-INF/view/" />
        <property name="configLocation" value="/WEB-INF/classes/velocity.properties" />        
    </bean>


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="cache" 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" class="com.taiji.eap.components.scheduler.JobList_view" />

 

在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"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="resourceLoaderPath" 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里用的属性。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值