質問

I'm trying to setup Velocity template engine to use with spring-mvc. My project currently uses only java based spring configuration.

I have trouble setting up VelocityConfigurer.

According to Spring documentation I should create bean as follows:

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

I currently have the following related configuration, but cannot seem to find a way to inject "resourceLoaderPath" property. VelocityConfigurer class does not have corresponding setter or constructor.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;

@Configuration
public class AppConfig {

    @Bean
    public VelocityConfigurer velocityConfig() {
        VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
        return velocityConfigurer;
    }
}

Any ideas how to avoid .xml based configuration here?

役に立ちましたか?

解決

According to the javadoc the VelocityConfigurer has a setter for the resourceLoaderPath. The setter is inherited from the VelocityEngineFactory.

So it should be possible to set it:

@Bean
public VelocityConfigurer velocityConfig() {
    VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
    velocityConfigurer.setResourceLoaderPath("/WEB-INF/velocity/");
    return velocityConfigurer;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top