默认情况下,velocity macro文件修改没有被应用服务器检测,必须重启才能生效。
Spring web.xml contextConfigLocation配置包含属性文件mvc-config.xml
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-config.xml
/WEB-INF/alert-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
mvc-config.xml部分内容如下:
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>WEB-INF/velocity/</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">gb2312</prop>
<prop key="output.encoding">gb2312</prop>
<prop key="contentType">text/html;charset=gb2312</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">1</prop>
<prop key="velocimacro.library.autoreload">true</prop>
<prop key="velocimacro.library">templates.vm</prop>
<prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.SimpleLog4JLogSystem</prop>
<prop key="runtime.log">com.ali</prop>
<prop key="runtime.log.error.stacktrace">true</prop>
<prop key="runtime.log.warn.stacktrace">true</prop>
<prop key="runtime.log.info.stacktrace">false</prop>
<prop key="runtime.log.invalid.reference">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix"><value>.vm</value></property>
<property name="exposeSpringMacroHelpers"><value>true</value></property>
<property name="exposeRequestAttributes"><value>true</value></property>
<property name="exposeSessionAttributes"><value>true</value></property>
<property name="contentType" value="text/html;charset=gb2312" />
<property name="dateToolAttribute">
<value>dateTool</value>
</property>
</bean>
Velocity文件包括库文件templates.vm都放在WEB-INF/velocity/
确保velocity文件被修改都立即重新扫描,关键的参数:
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">1</prop>
<prop key="velocimacro.library.autoreload">true</prop>
在index.vm上通过:
#parse("templates.vm")引入velocity模版。
Spring web.xml contextConfigLocation配置包含属性文件mvc-config.xml
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-config.xml
/WEB-INF/alert-config.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
mvc-config.xml部分内容如下:
<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>WEB-INF/velocity/</value>
</property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">gb2312</prop>
<prop key="output.encoding">gb2312</prop>
<prop key="contentType">text/html;charset=gb2312</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">1</prop>
<prop key="velocimacro.library.autoreload">true</prop>
<prop key="velocimacro.library">templates.vm</prop>
<prop key="runtime.log.logsystem.class">org.apache.velocity.runtime.log.SimpleLog4JLogSystem</prop>
<prop key="runtime.log">com.ali</prop>
<prop key="runtime.log.error.stacktrace">true</prop>
<prop key="runtime.log.warn.stacktrace">true</prop>
<prop key="runtime.log.info.stacktrace">false</prop>
<prop key="runtime.log.invalid.reference">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix"><value>.vm</value></property>
<property name="exposeSpringMacroHelpers"><value>true</value></property>
<property name="exposeRequestAttributes"><value>true</value></property>
<property name="exposeSessionAttributes"><value>true</value></property>
<property name="contentType" value="text/html;charset=gb2312" />
<property name="dateToolAttribute">
<value>dateTool</value>
</property>
</bean>
Velocity文件包括库文件templates.vm都放在WEB-INF/velocity/
确保velocity文件被修改都立即重新扫描,关键的参数:
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">1</prop>
<prop key="velocimacro.library.autoreload">true</prop>
在index.vm上通过:
#parse("templates.vm")引入velocity模版。