package com.hz.employmentsite.config; import com.hz.employmentsite.filter.TokenInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.concurrent.ConcurrentTaskExecutor; import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; @Configuration public class WebConfiguration implements WebMvcConfigurer { @Autowired private TokenInterceptor tokenInterceptor; /** * 解决跨域请求 * @param registry */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedHeaders("*") .allowedMethods("*") // .allowedOrigins("*") .allowedOriginPatterns("*") .allowCredentials(true); } /** * 异步请求配置 * @param configurer */ @Override public void configureAsyncSupport(AsyncSupportConfigurer configurer) { configurer.setTaskExecutor(new ConcurrentTaskExecutor(Executors.newFixedThreadPool(3))); configurer.setDefaultTimeout(30000); } /** * 配置拦截器、拦截路径 * 每次请求到拦截的路径,就会去执行拦截器中的方法 * @param registry */ @Override public void addInterceptors(InterceptorRegistry registry) { List excludePath = new ArrayList<>(); //排除拦截,除了注册登录(此时还没token),其他都拦截 excludePath.add("/api/account/login"); //登录 excludePath.add("/api/account/appLogin"); //登录 excludePath.add("/api/account/register"); //注册 excludePath.add("/api/account/captcha"); //验证码 excludePath.add("/api/account/test"); excludePath.add("/api/oauth/getOAuthUrl");//单点登录 excludePath.add("/api/oauth/getToken");//单点登录 excludePath.add("/api/oauth/oauthLogin");//单点登录 excludePath.add("/api/system/file/downFileToUrl/**"); //下载附件 excludePath.add("/api/system/file/downloadApk"); //下载APP安装包 excludePath.add("/api/common/getQRCode"); excludePath.add("/api/user/getUserInfo"); excludePath.add("/api/jobusermgr/recommendmgt/getListById"); excludePath.add("/api/jobUserService/jobUser/getEducationList");//查询某求职人员所有教育经验 excludePath.add("/api/jobUserService/jobUser/getExperienceList");//查询某求职人员所有工作经验 //扫码填写求职、企业信息所用API接口 excludePath.add("/api/jobUserService/jobUser/getDataByID");//查询单条求职人员数据 excludePath.add("/api/companyService/company/getCompanyByID");//查询单条企业信息数据 excludePath.add("/api/companyService/post/getPostByID");//查询单条岗位信息数据 excludePath.add("/api/companyService/post/getList");//查询某企业所有 岗位信息(分页) excludePath.add("/api/jobUserService/experience/getById"); //获取单条工作经验 excludePath.add("/api/jobUserService/experience/getListByJobUserID");//查询某求职人员所有工作经验(分页) excludePath.add("/api/jobUserService/education/getById"); //获取单条教育经历 excludePath.add("/api/jobUserService/education/getListByJobUserID");//查询某求职人员所有教育经验(分页) excludePath.add("/api/jobUserService/jobHunt/get"); //获取单条求职意向 excludePath.add("/api/jobUserService/jobHunt/getList");//查询某求职人员所有求职意向(分页) excludePath.add("/api/user/getUserInfo");//查询当前登录人信息 excludePath.add("/api/system/dictionary/getDictionaryItemByCodeList");//查询相关字典信息 excludePath.add("/api/system/area/getCityList");//查询相关市区信息 excludePath.add("/api/system/area/getAreaList");//查询相关街道信息 excludePath.add("/api/jobusermgr/recommendmgt/getProfessionLevelList");//查询所有求职岗位信息 excludePath.add("/api/jobusermgr/recommendmgt/getWorkCategoryLevelList");//查询所有工种信息 excludePath.add("/api/jobusermgr/recommendmgt/getOccupationCategoryList");//查询所有职业资格类别 excludePath.add("/api/jobusermgr/recommendmgt/getAllIndustryList");//查询所有企业所属行业信息 excludePath.add("/api/siteInfo/getDataList"); excludePath.add("/api/companyService/company/getSiteList"); excludePath.add("/api/companyService/company/save"); excludePath.add("/api/companyService/company/normalFirm"); // 按企业名称匹配企业信息 excludePath.add("/api/companyService/post/save"); excludePath.add("/api/jobUserService/education/save"); excludePath.add("/api/jobUserService/experience/save"); excludePath.add("/api/jobUserService/jobHunt/save"); excludePath.add("/api/jobUserService/jobUser/baseInfoSave"); excludePath.add("/api/wx/**"); excludePath.add("/gdgovMapApi"); excludePath.add("/static/**"); //静态资源 excludePath.add("/mobile/**"); //静态资源 excludePath.add("/web/**"); //静态资源 excludePath.add("/doc/**"); //静态资源 excludePath.add("/"); //首页跳转 excludePath.add("/MP_verify_PBhj75Una8Wk5r3v.txt"); registry.addInterceptor(tokenInterceptor) .addPathPatterns("/**") .excludePathPatterns(excludePath); WebMvcConfigurer.super.addInterceptors(registry); } }