package com.sv.api;

import com.sv.api.interceptor.AccessTokensInterceptorNew;
import com.sv.api.interceptor.PlatformInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * Spring Mvc Configuration
 *
 * @author xingkong1221
 * @since 2017-07-12
 */
@Configuration
public class InterceptorConfigurer extends WebMvcConfigurerAdapter {

    @Resource
    private AccessTokensInterceptorNew accessTokensInterceptorNew;

    @Resource
    private PlatformInterceptor platformInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(accessTokensInterceptorNew).addPathPatterns("/**");
        registry.addInterceptor(platformInterceptor).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

    /**
     * 线程池
     * @return
     */
    @Bean(name = "executor")
    public Executor initExecutor(){
        return Executors.newFixedThreadPool(10);
    }
}
