package com.ycl.jxkg.config.spring.mvc; import com.ycl.jxkg.config.RuoYiConfig; import com.ycl.jxkg.config.property.SystemConfig; import com.ycl.jxkg.config.spring.wx.TokenHandlerInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.*; import java.io.File; import java.util.List; /** * @version 3.5.0 * @description: The type Web mvc configuration. * Copyright (C), 2020-2024, 武汉思维跳跃科技有限公司 * @date 2021/12/25 9:45 */ @Configuration public class WebMvcConfiguration extends WebMvcConfigurationSupport { private final TokenHandlerInterceptor tokenHandlerInterceptor; private final SystemConfig systemConfig; private final RuoYiConfig ruoYiConfig; /** * Instantiates a new Web mvc configuration. * * @param tokenHandlerInterceptor the token handler interceptor * @param systemConfig the system config */ @Autowired public WebMvcConfiguration(TokenHandlerInterceptor tokenHandlerInterceptor, SystemConfig systemConfig, RuoYiConfig ruoYiConfig) { this.tokenHandlerInterceptor = tokenHandlerInterceptor; this.systemConfig = systemConfig; this.ruoYiConfig = ruoYiConfig; } @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addRedirectViewController("/", "/student/index.html"); registry.addRedirectViewController("/student", "/student/index.html"); registry.addRedirectViewController("/admin", "/admin/index.html"); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/api/files" + "/**") .addResourceLocations("file:" + ruoYiConfig.getUrl() + File.separator); registry.addResourceHandler("/**") .addResourceLocations("classpath:/static/") .setCachePeriod(31556926); } @Override public void addInterceptors(InterceptorRegistry registry) { List securityIgnoreUrls = systemConfig.getWx().getSecurityIgnoreUrls(); String[] ignores = new String[securityIgnoreUrls.size()]; registry.addInterceptor(tokenHandlerInterceptor) .addPathPatterns("/api/wx/**") .excludePathPatterns(securityIgnoreUrls.toArray(ignores)); super.addInterceptors(registry); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowCredentials(true) .allowedMethods("*") .allowedOrigins("*") .allowedHeaders("*"); super.addCorsMappings(registry); } }