Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off VelocityViewResolver errors in Spring?

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?

like image 779
Polaris878 Avatar asked Feb 04 '11 19:02

Polaris878


3 Answers

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>
like image 123
Polaris878 Avatar answered Nov 18 '22 14:11

Polaris878


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.

like image 2
Aleksey Otrubennikov Avatar answered Nov 18 '22 13:11

Aleksey Otrubennikov


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>
like image 1
Mike Avatar answered Nov 18 '22 13:11

Mike