Spring Boot / Velocity无法找到资源错误

时间:2018-03-21 02:07:01

标签: java spring spring-boot velocity

我正在尝试使用一组Velocity模板来使用Spring Boot应用程序。我在google上搜索了一下,找到了一些信息,我试图实现它们,但无法让它工作。你能告诉我我做错了什么吗?我一直收到这个错误:

Unable to find resource '/VBS Template Files/StandardVariables.vm'

我在Eclipse中附加了我的文件夹结构,我尝试了所有可能的路径组合。但似乎没有任何效果。

顺便说一下,我的控制器类在一个不同的项目中。这会引起问题吗? enter image description here

我添加了一个属性文件:

#VelcoityConfiguration
spring.velocity.resourceLoaderPath=classpath:/VBS Template Files/
spring.velocity.prefix=
spring.velocity.suffix=.vm
spring.velocity.cache=false
spring.velocity.check-template-location=false
spring.velocity.content-type=text/html
spring.velocity.charset=UTF-8
spring.velocity.properties.input.encoding=UTF-8
spring.velocity.properties.output.encoding=UTF-8

从这一行抛出错误:

for (String table : tableNames) {
    mergeTemplate(table, "ISO-8859-1", velocityContext, writer);
}

堆栈追踪:

2018-03-20 23:21:38.960  INFO 16728 --- [  restartedMain] c.a.c.ConfigGeneratorApplication         : Started ConfigGeneratorApplication in 3.336 seconds (JVM running for 4.542)
2018-03-20 23:21:53.419  INFO 16728 --- [nio-8080-exec-3] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-03-20 23:21:53.420  INFO 16728 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-03-20 23:21:53.445  INFO 16728 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 25 ms
2018-03-20 23:21:53.748  INFO 16728 --- [nio-8080-exec-3] c.a.l.palconfig.ActionMonitor            : PAL Config request contained invalid request data
2018-03-20 23:21:53.916  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : VelocityBuilderAction processAction() started
2018-03-20 23:21:53.916  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : Starting
2018-03-20 23:21:53.916  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : ProcessConfigRequest received ...
2018-03-20 23:21:53.917  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : ConfigRequest
2018-03-20 23:21:53.917  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : Device = SAM01
2018-03-20 23:22:25.601 ERROR 16728 --- [nio-8080-exec-3] org.apache.velocity                      : ResourceManager : unable to find resource '/VBS Template Files/StandardVariables.vm' in any resource loader.
2018-03-20 23:25:01.886 ERROR 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityJythonAdapter  : Error
2018-03-20 23:25:01.888  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : VBS has returned the following data ...
2018-03-20 23:25:01.888  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : 
2018-03-20 23:25:01.889  INFO 16728 --- [nio-8080-exec-3] c.a.l.v.utilities.VelocityBuilderAction  : VelocityBuilderAction processAction() ended

1 个答案:

答案 0 :(得分:0)

如果您将resourceLoaderPath设置为/VBS Template Files/,则不得要求/VBS Template Files/StandardVariables.vm,否则Velocity将搜索/VBS Template Files/VBS Template Files/StandardVariables.vm

所以你只需要StandardVariables.vm