如何关闭 Spring 中的 VelocityViewResolver 错误?

发布于 2024-10-16 02:29:31 字数 639 浏览 1 评论 0原文

我正在使用速度和弹簧。在 Spring 中,我将 VelocityViewResolverContentNegotiatingViewResolver 搭配使用。在大多数情况下,这非常有效。唯一的问题是 ContentNegotiatingViewResolver 使用许多不同的内容集查询 VelocityViewResolver(这是应该的)。

当 Velocity 引擎找不到特定模板时,会产生类似于以下内容的错误:

2011-02-04 13:37:15,074 错误 [http-8080-2] VelocityEngine: ResourceManager:无法在任何资源加载器中找到资源“foo.json.vm”。

这并不理想。理想情况下,如果找不到模板,则会生成警告或类似的内容。如果特定内容类型不存在模板,我并不关心...因为这意味着该视图解析器不支持该内容类型。

关于如何通过 VelocityViewResolverVelocityViewContentNegotiatingViewResolver 抑制此错误的任何想法?

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

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

发布评论

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

评论(3

擦肩而过的背影 2024-10-23 02:29:31

因此,我发现最好的方法是在我的日志配置文件中专门为 Velocity 引擎添加一个 logger 语句(Velocity 和我的项目都使用 Commons 日志记录)。我的记录器语句如下所示:

<logger name="org.apache.velocity.app">
    <level value="OFF" />
</logger>

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:

<logger name="org.apache.velocity.app">
    <level value="OFF" />
</logger>
撩人痒 2024-10-23 02:29:31

该问题将在 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.

离去的眼神 2024-10-23 02:29:31

发生这种情况是因为您的 ContentNegotiatingViewResolver 使用 VelocityViewResolver。您可以通过给它一个空(但非空)的视图解析器列表来阻止它这样做。

<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    ...
    <property name="viewResolvers">
          <list />
    </property>
</bean>

This happens because your ContentNegotiatingViewResolver uses VelocityViewResolver. You can stop it from doing that by giving it an empty (but non-null) list of view resolvers.

<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    ...
    <property name="viewResolvers">
          <list />
    </property>
</bean>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文