SpringBoot1.5整合velocity报ResourceNotFoundException

Jeffreyji
  • 9

项目结构如下:

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里。

回复
阅读 2.8k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏