Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Velocity view resolver in Spring Boot

We use Spring Boot in our application along with AngularJS and HTML. We use Velocity only for email templates but not for view resolver.

@Bean(name = "velocityEngine")
public VelocityEngineFactoryBean velocityEngineFactoryBean() {
    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Properties p = new Properties();
    p.put("resource.loader", "class");
    p.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    vefb.setVelocityProperties(p);
    return vefb;
}

Even though we don't use Velocity view resolver, we get the following error due to auto-configuration:

ERROR org.apache.velocity - ResourceManager: unable to find a resource 'LoadList' in any resource loader. ERROR org.apache.velocity - ResourceManager: unable to find resource 'index' in any resource loader.

I tried to disable Velocity auto configuration:

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,VelocityAutoConfiguration.class })
@SuppressWarnings("PMD")
@EnableAsync
public class Application {

Also added the following in the application.properties file:

spring.velocity.check-template-location=false

But I'm still getting the above error. Is there any way to disable the Velocity view resolver alone?

like image 333
user1578872 Avatar asked May 11 '15 17:05

user1578872


People also ask

What is the default view resolver in spring boot?

Thymeleaf view resolver works by surrounding the view name with a prefix and suffix. The default values of prefix and suffix are 'classpath:/templates/' and '. html', respectively. Spring Boot also provides an option to change the default value of prefix and suffix by setting spring.

What is the default view resolver in Spring MVC?

2) The InternalResourceViewResolver is also the default view resolver of DispatcherServlet class, which acts as the front controller in the Spring MVC framework.

Is abstract view resolver is a type of view resolver?

An abstract view resolver which takes care of caching views. Often views need preparation before they can be used, extending this view resolver provides caching of views. An implementation of ViewResolver that accepts a configuration file written in XML with the same DTD as Spring's XML bean factories.

How does Spring View resolver work?

Spring MVC is a Web MVC Framework for building web applications. In generic all MVC frameworks provide a way of working with views. Spring does that via the ViewResolvers, which enables you to render models in the browser without tying the implementation to specific view technology.


2 Answers

I know this question is quite old, but it is quite easy to disable:

just add

spring.velocity.enabled = false

to the application.properties

Source: http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

like image 179
Coco Avatar answered Oct 14 '22 19:10

Coco


In Spring boot, With Annotation, you can exclude the VelocityAutoConfiguration like

@SpringBootApplication
@EnableAutoConfiguration(exclude = {VelocityAutoConfiguration.class})
@EnableGlobalMethodSecurity(securedEnabled = true)
public class Application extends SpringBootServletInitializer {
}
like image 44
Kul Bhushan Prasad Avatar answered Oct 14 '22 17:10

Kul Bhushan Prasad