the project structure is as follows:
load Velocity code:
@Bean
public VelocityEngine getVelocityEngine() throws IOException {
logger.info("MyWebMvcConfiguration VelocityEngine");
return getVelocityConfigurer().getVelocityEngine();
}
@Bean
public VelocityConfigurer getVelocityConfigurer() {
logger.info("MyWebMvcConfiguration VelocityConfigurer");
VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
velocityConfigurer.setResourceLoaderPath("/page/");
Properties velocityProperties = new Properties();
velocityProperties.put("output.encoding", "UTF-8");
velocityProperties.put("input.encoding", "UTF-8");
velocityProperties.put("contentType", "text/html;charset=UTF-8");
velocityProperties.put("velocimacro.library", "views/common/macro.vm");
velocityProperties.put("velocimacro.library.autoreload", true);
velocityConfigurer.setVelocityProperties(velocityProperties);
return velocityConfigurer;
}
the error message is as follows:
Caused by: org.apache.velocity.exception.VelocityException: Velocimacro: Error using VM library: views/common/macro.vm
at org.apache.velocity.runtime.VelocimacroFactory.initVelocimacro(VelocimacroFactory.java:219)
at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:274)
at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:93)
at org.springframework.ui.velocity.VelocityEngineFactory.createVelocityEngine(VelocityEngineFactory.java:251)
at org.springframework.web.servlet.view.velocity.VelocityConfigurer.afterPropertiesSet(VelocityConfigurer.java:121)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1689)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1627)
... 35 common frames omitted
Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource "views/common/macro.vm"
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
at org.apache.velocity.runtime.VelocimacroFactory.initVelocimacro(VelocimacroFactory.java:202)
... 41 common frames omitted
The macro.vm file is in resource- > page- > views- > common.