me.bulat.jivr.webmin.config.WebAppConfig.java Source code

Java tutorial

Introduction

Here is the source code for me.bulat.jivr.webmin.config.WebAppConfig.java

Source

/*
 * Licensed to JIVR under one or more contributor
 *  license agreements. See the NOTICE file distributed with
 *  this work for additional information regarding copyright
 *  ownership. JIVR licenses this file to you under
 *  the Apache License, Version 2.0 (the "License"); you may
 *  not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */

package me.bulat.jivr.webmin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;

/**
 * @author Alex Bogatikov
 *         Created on 25/08/16.
 */
@Configuration
@EnableWebMvc
@ComponentScan({ "me.bulat.jivr.webmin.web.root", "me.bulat.jivr.webmin.web.defended" })
public class WebAppConfig extends WebMvcConfigurerAdapter {

    /*
    - The ContentNegotiatingViewResolver delegates to the InternalResourceViewResolver and BeanNameViewResolver,
    - and uses the requested media type (determined by the path extension) to pick a matching view.
    - When the media type is 'text/html', it will delegate to the InternalResourceViewResolver's JstlView,
    - otherwise to the BeanNameViewResolver.
    */
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/jsp/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }

    /*
    - Message source for this context, loaded from localized "messages_xx" files.
    - Files are stored inside src/main/resources
     */
    @Bean
    public ResourceBundleMessageSource messageSource() {
        ResourceBundleMessageSource source = new ResourceBundleMessageSource();
        source.setBasename("messages/messages");
        source.setUseCodeAsDefaultMessage(true);
        return source;
    }

    /*
    serve static resources (*.html, ...) from src/main/webapp/
    Required when both servlet-mapping is '/' and static resources need to be served
    */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}