All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.autoconfig.commonconfig.config.WebConfig Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
package org.apache.commons.autoconfig.commonconfig.config;


import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.apache.commons.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebConfig {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Bean
    public WebMvcConfigurerAdapter webMvcConfigurerAdapter(){
        WebMvcConfigurerAdapter webMvcConfigurerAdapter = new WebMvcConfigurerAdapter(){
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/").setViewName("login");
                registry.addViewController("/admin").setViewName("adminLogin");
            }

            @Override
            public void addInterceptors(InterceptorRegistry registry) {

                registry.addInterceptor(loginInterceptor).addPathPatterns("/main/**")
                        .excludePathPatterns("/main/subaccount/adminLogin","/main/subaccount/login"); //.excludePathPatterns("api/path/login");
            }

            @Override
            public void configureMessageConverters(List> converters) {
                super.configureMessageConverters(converters);
                FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter();
                FastJsonConfig fastJsonConfig=new FastJsonConfig();
                fastJsonConfig.setSerializerFeatures(
                        SerializerFeature.PrettyFormat
                );
                List fastMediaTypes = new ArrayList();
                fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
                fastConverter.setSupportedMediaTypes(fastMediaTypes);
                fastConverter.setFastJsonConfig(fastJsonConfig);
                converters.add(fastConverter);
            }
        };
        return webMvcConfigurerAdapter;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy