init
This commit is contained in:
@@ -97,7 +97,7 @@ public class TenantConfig {
|
||||
registration.setFilter(new TenantFilter());
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("tenantFilter");
|
||||
registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
|
||||
// registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE + 1000);
|
||||
return registration;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,10 @@ public class TenantFilter implements Filter {
|
||||
}else{
|
||||
TenantHelper.setTenantId(tenantHeader);
|
||||
}
|
||||
if(StringUtils.isBlank(TenantHelper.getTenantId())){
|
||||
ServletUtils.renderString(response, JSONUtil.toJsonStr(R.fail("未找到对应的平台")));
|
||||
return;
|
||||
}
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} finally {
|
||||
TenantHelper.clearTenant();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.ruoyi.component.web.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
|
||||
@@ -15,7 +13,7 @@ import java.util.Locale;
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@AutoConfiguration(before = WebMvcAutoConfiguration.class)
|
||||
//@AutoConfiguration(before = WebMvcAutoConfiguration.class)
|
||||
public class I18nConfig {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.ruoyi.component.web.config;
|
||||
|
||||
import com.ruoyi.component.web.interceptor.PlusWebInvokeTimeInterceptor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
@@ -28,25 +30,22 @@ public class ResourcesConfig implements WebMvcConfigurer {
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
public FilterRegistrationBean corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
// 设置访问源地址
|
||||
config.addAllowedOriginPattern("*");
|
||||
// 设置访问源请求头
|
||||
config.addAllowedHeader("*");
|
||||
// 设置访问源请求方法
|
||||
config.addAllowedMethod("*");
|
||||
// 有效期 1800秒
|
||||
config.setMaxAge(1800L);
|
||||
// 添加映射路径,拦截一切请求
|
||||
config.setAllowCredentials(true); // 允许cookies跨域
|
||||
config.addAllowedOriginPattern("*");// #允许向该服务器提交请求的URI,*表示全部允许,自定义可以添加多个,在SpringMVC中,如果设成*,会自动转成当前请求头中的Origin
|
||||
config.addAllowedHeader("*");// #允许访问的头信息,*表示全部,可以添加多个
|
||||
config.addAllowedMethod("*");// 允许提交请求的方法,*表示全部允许,一般OPTIONS,GET,POST三个够了
|
||||
config.setMaxAge(1800L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
// 返回新的CorsFilter
|
||||
return new CorsFilter(source);
|
||||
source.registerCorsConfiguration("/**", config);//对所有接口都有效
|
||||
FilterRegistrationBean registration = new FilterRegistrationBean(new CorsFilter(source));
|
||||
registration.addUrlPatterns("/*");
|
||||
registration.setName("corsFilter");
|
||||
registration.setOrder(Ordered.HIGHEST_PRECEDENCE); // 优先级最高
|
||||
return registration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
com.ruoyi.component.web.config.CaptchaConfig
|
||||
com.ruoyi.component.web.config.FilterConfig
|
||||
com.ruoyi.component.web.config.I18nConfig
|
||||
com.ruoyi.component.web.config.ResourcesConfig
|
||||
com.ruoyi.component.web.config.UndertowConfig
|
||||
|
||||
Reference in New Issue
Block a user