71.9 Velocity

默认情况下,Spring Boot会配置一个VelocityViewResolver,如果需要的是VelocityLayoutViewResolver,你可以自己创建一个名为velocityViewResolver的bean。你也可以将VelocityProperties实例注入到自定义视图解析器以获取基本的默认设置。

以下示例使用VelocityLayoutViewResolver替换自动配置的velocity视图解析器,并自定义layoutUrl及应用所有自动配置的属性:

  1. @Bean(name = "velocityViewResolver")
  2. public VelocityLayoutViewResolver velocityViewResolver(VelocityProperties properties) {
  3. VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
  4. properties.applyToViewResolver(resolver);
  5. resolver.setLayoutUrl("layout/default.vm");
  6. return resolver;
  7. }