Bean Velocity配置从xml到java

时间:2015-08-08 10:19:39

标签: java xml spring

我想将带有velocity的xml bean转换为config java class

这是旧的xml配置:

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

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    <property name="cache" value="true"/>
    <property name="prefix" value=""/>
    <property name="suffix" value=".html"/>
    <property name="exposeSpringMacroHelpers" value="true"/>
</bean>

这是新的java类配置:

    @Bean
    public ViewResolver viewResolver()
    {
        VelocityViewResolver viewResolver= new VelocityViewResolver();
        viewResolver.setPrefix("");
        viewResolver.setSuffix(".html");
        viewResolver.setCache(true);

        return viewResolver;
    }

    @Bean
    public VelocityConfigurer velocityConfig()
    {
       VelocityConfigurer velocityConfig = new VelocityConfigurer();

      // ???????????

       return velocityConfig;
    }

怎么做?

1 个答案:

答案 0 :(得分:0)

VelocityConfig扩展了VelocityEngineFactory,因此您可以使用setResourceLoaderPath方法:

velocityConfig.setResourceLoaderPath("/WEB-INF/View/");