com.amuponda.estorehack.client.web.config.EstoreWebConfig.java Source code

Java tutorial

Introduction

Here is the source code for com.amuponda.estorehack.client.web.config.EstoreWebConfig.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.amuponda.estorehack.client.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 *
 * @author amuponda
 */
@EnableWebMvc
@Configuration
@ComponentScan("com.amuponda.estorehack.client.web.controller")
public class EstoreWebConfig extends WebMvcConfigurerAdapter {

    /**
     *
     * @return the view resolver for the application
     */
    @Bean
    public ViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        //Allows InternalResourceViewResolver to resolve JstlView instead of Internal
        //Resource view
        //JstlView allows use of locale specific JSTL tags and use of Spring message sources
        resolver.setViewClass(org.springframework.web.servlet.view.JstlView.class);
        return resolver;
    }

    /**
     * Tells DispatcherServlet to foward requests for static resources to the
     * servlet container's default servlet and not try to handle them itself
     *
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    /**
     * Add handlers to serve static resources such as images, js, and, 
     * css files from specific locations under web application root, the classpath, and others
     * @param registry 
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
    }
}