SpringBoot1.5整合velocity报ResourceNotFoundException
项目结构如下:
加载Velocity代码:
@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;
}
报错信息如下:
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
macro.vm文件是在resource->page->views->common里。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
views/common/macro.vm -> /page/views/common/macro.vm