如何在 Spring Boot 中为 Velocity 加载 VM_global_library.vm?

How to load VM_global_library.vm for Velocity in Spring Boot?

我们在 Spring Boot 中使用 VelocityLayoutServlet 作为视图解析器。

@Bean(name = "velocityViewResolver")
public VelocityLayoutViewResolver velocityViewResolver() {
       VelocityLayoutViewResolver resolver = new VelocityLayoutViewResolver();
       this.properties.applyToViewResolver(resolver);
       resolver.setLayoutUrl("layout/default.vm");
       return resolver;}

我们想从 VM_global_library.vm 文件加载全局宏,如 Velocity User Guide 中所述。预期 Velocity 从 /templates 目录加载该默认文件,但没有发生。

添加 Velocity 用户指南中提到的显式设置也不起作用: spring.velocity.velocimacro.library=VM_global_library.vm

velocimacro.library - A comma-separated list of all Velocimacro template libraries. By default, Velocity looks for a single library: VM_global_library.vm. The configured template path is used to find the Velocimacro libraries.

我们是否遗漏了一些魔法,或者集成中是否遗漏了这一点?

可以使用 "spring.velocity.properties.*" 属性设置速度属性。 此配置适用于我:

spring.velocity.properties.velocimacro.library=templates/VM_global_library.vm