- 为JwtAccessDeniedHandler添加详细注释和中文错误提示- 在JwtAuthenticationEntryPoint中优化响应编码和状态码设置 - 统一使用UTF-8字符编码确保中文正确显示- 设置响应内容类型为JSON格式 - 明确设置HTTP状态码403和401对应权限问题- 添加WebConfig中静态资源处理器配置注释- 配置"/uploads/**"路径映射到服务器"uploads/"目录- 更新生肖文档结构,增加章节标题和内容调整
35 lines
1.3 KiB
Java
35 lines
1.3 KiB
Java
package com.test.bijihoudaun.config;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
@Configuration
|
|
public class WebConfig implements WebMvcConfigurer {
|
|
|
|
@Override
|
|
public void addCorsMappings(CorsRegistry registry) {
|
|
registry.addMapping("/**")
|
|
.allowedOriginPatterns("*") // 使用allowedOriginPatterns
|
|
.allowedMethods("*")
|
|
.allowedHeaders("*")
|
|
.allowCredentials(true) // 允许凭证
|
|
.maxAge(3600); // 预检请求缓存时间
|
|
}
|
|
|
|
/**
|
|
* 重写父类方法,配置静态资源处理器
|
|
* 该方法用于配置静态资源的访问路径和实际存储位置
|
|
*
|
|
* @param registry 资源处理器注册对象,用于注册静态资源处理器
|
|
*/
|
|
@Override
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
// 添加资源处理器,配置"/uploads/**"路径下的请求
|
|
// 将这些请求映射到服务器的"uploads/"目录
|
|
registry.addResourceHandler("/uploads/**")
|
|
.addResourceLocations("file:uploads/");
|
|
}
|
|
}
|