SpringBoot1.5整合velocity报ResourceNotFoundException

发布于 2022-09-07 23:27:42 字数 2714 浏览 14 评论 0

项目结构如下:

clipboard.png

加载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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒浓于脸红 2022-09-14 23:27:42

views/common/macro.vm -> /page/views/common/macro.vm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文