如何关闭 Spring 中的 VelocityViewResolver 错误?
我正在使用速度和弹簧。在 Spring 中,我将 VelocityViewResolver
与 ContentNegotiatingViewResolver
搭配使用。在大多数情况下,这非常有效。唯一的问题是 ContentNegotiatingViewResolver
使用许多不同的内容集查询 VelocityViewResolver
(这是应该的)。
当 Velocity 引擎找不到特定模板时,会产生类似于以下内容的错误:
2011-02-04 13:37:15,074 错误 [http-8080-2] VelocityEngine: ResourceManager:无法在任何资源加载器中找到资源“foo.json.vm”。
这并不理想。理想情况下,如果找不到模板,则会生成警告或类似的内容。如果特定内容类型不存在模板,我并不关心...因为这意味着该视图解析器不支持该内容类型。
关于如何通过 VelocityViewResolver
、VelocityView
或 ContentNegotiatingViewResolver
抑制此错误的任何想法?
I'm using Velocity and Spring. Within Spring, I'm using the VelocityViewResolver
paired with the ContentNegotiatingViewResolver
. For the most part, this works great. The only problem is that the ContentNegotiatingViewResolver
queries the VelocityViewResolver
with many different content sets (as it should).
When the Velocity engine doesn't find the particular template, an error is produced similar to the following:
2011-02-04 13:37:15,074 ERROR [http-8080-2] VelocityEngine: ResourceManager : unable to find resource 'foo.json.vm' in any resource loader.
This is not ideal. Ideally, if a template isn't found, a warning or something similar would be produced. If a template doesn't exist for a particular content type, I don't really care... as that means that content type isn't supported through that view resolver.
Any idea on how I could suppress this error though the VelocityViewResolver
, VelocityView
, or ContentNegotiatingViewResolver
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因此,我发现最好的方法是在我的日志配置文件中专门为 Velocity 引擎添加一个 logger 语句(Velocity 和我的项目都使用 Commons 日志记录)。我的记录器语句如下所示:
So, I found that the best way to do this was to add a
logger
statement to my log config file specifically for the Velocity engine (Velocity and my project both use Commons logging). My logger statement looks like this:该问题将在 Spring 3.2 中修复,请参阅 SPR-8640。进行此改进后,您将能够配置 Velocity 视图解析器以仅检查未解析的视图一次。
The problem will be fixed in Spring 3.2, see SPR-8640. After this improvement you will be able to configure Velocity view resolver to check unresolved views only once.
发生这种情况是因为您的
ContentNegotiatingViewResolver
使用VelocityViewResolver
。您可以通过给它一个空(但非空)的视图解析器列表来阻止它这样做。This happens because your
ContentNegotiatingViewResolver
usesVelocityViewResolver
. You can stop it from doing that by giving it an empty (but non-null) list of view resolvers.