warからvmファイルを読み込みたい、springのVelocityConfigurerを使ってみる。 2011/05/28

Javaです。springです。velocityです。
デプロイしたwarファイルの中からvmファイルを読み込んで使いたかったわけです。
VelocityConfigurerを使うと簡単でした。

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


で、
@Autowired
protected VelocityConfigurer velocityConfigurer;

にして使うときは、


Template template = velocityConfigurer.getVelocityEngine()
.getTemplate(
"test_utf8.vm",
"utf-8");

これで、beans.xmlに指定された場所から読み込んでくれる。

: