SpringMvcConfiguration.java 4.89 KB
Newer Older
Rensq's avatar
Rensq committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
package com.testor.config;

import com.testor.biz.auth.interceptor.DataSignatureInterceptor;
import com.testor.biz.auth.interceptor.SanyuInterceptor;
import com.testor.common.interceptor.AuthInterceptor;
import com.testor.common.interceptor.SignInterceptor;
import com.testor.config.aspect.LogAspect;
import com.tongtech.tfw.backend.common.config.HttpMessageConverterWrapper;
import com.tongtech.tfw.backend.common.config.ParameterConverters;
import com.tongtech.tfw.backend.common.exception.GeneralExceptionHandler;
import com.tongtech.tfw.backend.common.server.UndertowServerFactoryCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * SpringMvcConfiguration
 *
 * @author Ivan
 * @version 1.0 Created by Ivan at 2020/3/18.
 */
@SpringBootConfiguration
public class SpringMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private SignInterceptor signInterceptor;

    @Bean
    public LogAspect getLogAspect() {
        return new LogAspect();
    }


//    @Bean
//    @ConditionalOnClass(ServerProperties.Undertow.class)
//    public UndertowServerFactoryCustomizer undertowServerFactoryCustomizer() {
//        return new UndertowServerFactoryCustomizer();
//    }

    @Override
    public void configureHandlerExceptionResolvers(
            List<HandlerExceptionResolver> exceptionResolvers) {
        exceptionResolvers.add(new GeneralExceptionHandler());
    }

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        converters.forEach(HttpMessageConverterWrapper.objectMapperWrapper());
    }

    @Bean
    @ConditionalOnMissingBean(RequestContextListener.class)
    public RequestContextListener requestContextListener() {
        return new RequestContextListener();
    }

    @Bean
    public ParameterConverters parameterConverters() {
        return new ParameterConverters();
    }

    /**
     * @param registry :
     * @return void
     * @author Created by Ivan at 2020/5/9.
     * <p>拦截器配置
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry
                .addInterceptor(this.getApiAuthInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/auth/**",
                        "/*.html",
                        "/*.ico",
                        "/webjars/**",
                        "/swagger-resources/**",
                        "/ureport/**",
                        "/druid/**",
                        "/excel/**",
                        "/app/**",
                        "/error/**",
                        "/flowable/**",
                        "/v2/api-docs/**",
                        "/v3/api-docs/**",
                        "/sys/login/**",
                        "/sys/getToken",
                        "/iam/user/**",
                        "/iam/message/push",
                        "/hireDepositoryManageBase/pushData",
                        "/hireDepositoryManageBase/zlFileLoad"
                );
        registry
                .addInterceptor(this.getDataSignatureInterceptor())
                .addPathPatterns("/area/**")
                .addPathPatterns("/dict/**")
                .addPathPatterns("/org/**")
                .addPathPatterns("/resource/**")
                .addPathPatterns("/role/**")
                .addPathPatterns("/user/**")
                .addPathPatterns("/auth/**")
                .excludePathPatterns(
                        "/*.html", "/webjars/**", "/swagger-resources/**", "/ureport/**", "/druid/**");
        registry.addInterceptor(this.getSanyuInterceptor()).addPathPatterns("/**").excludePathPatterns("/iam/user/**",
                "/iam/message/push","/hireDepositoryManageBase/pushData","/hireDepositoryManageBase/zlFileLoad");
        //registry.addInterceptor(this.signInterceptor).addPathPatterns("/**");
    }

    @Bean
    public AuthInterceptor getApiAuthInterceptor() {
        return new AuthInterceptor();
    }

    @Bean
    public DataSignatureInterceptor getDataSignatureInterceptor() {
        return new DataSignatureInterceptor();
    }

    @Bean
    public SanyuInterceptor getSanyuInterceptor() {
        return new SanyuInterceptor();
    }
}