feat(修复): 查询以及分类和配置两次跨域失效
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
c8574d097d
commit
7b06d59e57
|
@ -1,7 +1,6 @@
|
||||||
package com.atguigu.config;
|
package com.atguigu.config;
|
||||||
|
|
||||||
import com.atguigu.interceptor.LoginAuthInterceptor;
|
import com.atguigu.interceptor.LoginAuthInterceptor;
|
||||||
import com.atguigu.properties.InterceptorsProperties;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -14,8 +13,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
|
||||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LoginAuthInterceptor loginAuthInterceptor;
|
private LoginAuthInterceptor loginAuthInterceptor;
|
||||||
@Autowired
|
|
||||||
private InterceptorsProperties interceptorsProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 解决跨域
|
* * 解决跨域
|
||||||
|
@ -38,9 +35,9 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||||
*/
|
*/
|
||||||
protected void addInterceptors(InterceptorRegistry registry) {
|
protected void addInterceptors(InterceptorRegistry registry) {
|
||||||
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
||||||
|
|
||||||
// 需要拦截的
|
// 需要拦截的
|
||||||
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**")
|
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**")
|
||||||
.excludePathPatterns(interceptorsProperties.getNoAuthUrls());
|
.excludePathPatterns("/admin/system/index/login", "/admin/system/index/generateValidateCode", "/admin/product/category/exportData");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
package com.atguigu.properties;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@ConfigurationProperties(prefix = "bunny")
|
|
||||||
@Data
|
|
||||||
public class InterceptorsProperties {
|
|
||||||
private List<String> noAuthUrls;
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.atguigu.properties;
|
package com.atguigu.spzx.manger.properties;
|
||||||
|
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
|
@ -2,7 +2,7 @@ package com.atguigu.spzx.manger.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.atguigu.exception.BunnyException;
|
import com.atguigu.exception.BunnyException;
|
||||||
import com.atguigu.properties.MinioProperties;
|
import com.atguigu.spzx.manger.properties.MinioProperties;
|
||||||
import com.atguigu.spzx.manger.service.FileUploadService;
|
import com.atguigu.spzx.manger.service.FileUploadService;
|
||||||
import io.minio.BucketExistsArgs;
|
import io.minio.BucketExistsArgs;
|
||||||
import io.minio.MakeBucketArgs;
|
import io.minio.MakeBucketArgs;
|
||||||
|
@ -36,7 +36,7 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||||
String dir = DateUtil.format(new Date(), "yyyy-MM-dd");
|
String dir = DateUtil.format(new Date(), "yyyy-MM-dd");
|
||||||
String uuid = UUID.randomUUID().toString();
|
String uuid = UUID.randomUUID().toString();
|
||||||
String filename = dir + "/" + uuid + "-" + file.getOriginalFilename();
|
String filename = dir + "/" + uuid + "-" + file.getOriginalFilename();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
boolean bucketExists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||||
// 判断桶是否存在
|
// 判断桶是否存在
|
||||||
|
|
|
@ -16,9 +16,3 @@ bunny:
|
||||||
bucket-name: spzx-bucket
|
bucket-name: spzx-bucket
|
||||||
accessKey: "bunny"
|
accessKey: "bunny"
|
||||||
secretKey: "02120212"
|
secretKey: "02120212"
|
||||||
|
|
||||||
noAuthUrls:
|
|
||||||
- /admin/system/index/login
|
|
||||||
- /admin/system/index/generateValidateCode
|
|
||||||
- /admin/product/category/exportData
|
|
||||||
|
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
|
|
||||||
<contextName>logback</contextName>
|
|
||||||
|
|
||||||
<!-- 日志的输出目录 -->
|
|
||||||
<property name="log.path" value="logs//spzx-manager//logs"/>
|
|
||||||
|
|
||||||
<!--控制台日志格式:彩色日志-->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<!-- boldMagenta:粗红-->
|
|
||||||
<!-- cyan:青色 -->
|
|
||||||
<!-- white:白色 -->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<property name="CONSOLE_LOG_PATTERN"
|
|
||||||
value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) %highlight([%-5level]) %green(%logger) %msg%n"/>
|
|
||||||
|
|
||||||
<!--文件日志格式-->
|
|
||||||
<property name="FILE_LOG_PATTERN" value="%date{yyyy-MM-dd HH:mm:ss} [%-5level] %thread %file:%line %logger %msg%n"/>
|
|
||||||
|
|
||||||
<!--编码-->
|
|
||||||
<property name="ENCODING" value="UTF-8"/>
|
|
||||||
|
|
||||||
<!-- 控制台日志 -->
|
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<!-- 临界值过滤器 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
|
||||||
<level>INFO</level>
|
|
||||||
</filter>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 文件日志 -->
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
|
||||||
<file>${log.path}//log.log</file>
|
|
||||||
<append>true</append>
|
|
||||||
<encoder>
|
|
||||||
<pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%n</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 开发环境 -->
|
|
||||||
<springProfile name="dev">
|
|
||||||
<!-- com.atguigu日志记录器:业务程序INFO级别 -->
|
|
||||||
<logger name="com.atguigu" level="INFO"/>
|
|
||||||
<!-- 根日志记录器:INFO级别 -->
|
|
||||||
<root level="INFO">
|
|
||||||
<appender-ref ref="CONSOLE"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
|
||||||
</springProfile>
|
|
||||||
|
|
||||||
</configuration>
|
|
|
@ -1,16 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<!DOCTYPE configuration PUBLIC
|
|
||||||
"-//mybatis.org//DTD Config 3.0//EN"
|
|
||||||
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
|
||||||
<configuration>
|
|
||||||
<settings>
|
|
||||||
<!-- 设置驼峰标识 -->
|
|
||||||
<setting name="mapUnderscoreToCamelCase" value="true"/>
|
|
||||||
<!-- 打印SQL语句 -->
|
|
||||||
<setting name="logImpl" value="STDOUT_LOGGING"/>
|
|
||||||
</settings>
|
|
||||||
<plugins>
|
|
||||||
<!-- 分页插件 -->
|
|
||||||
<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
|
|
||||||
</plugins>
|
|
||||||
</configuration>
|
|
|
@ -2,8 +2,10 @@ package com.atguigu.gateway;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan("com.atguigu")
|
||||||
public class GatewayApplication {
|
public class GatewayApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(GatewayApplication.class, args);
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
|
|
|
@ -11,21 +11,22 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
namespace: ${bunny.nacos.discovery.namespace}
|
namespace: ${bunny.nacos.discovery.namespace}
|
||||||
server-addr: ${bunny.nacos.server-addr}
|
server-addr: ${bunny.nacos.server-addr}
|
||||||
|
log-name: logs/${spring.application.name}
|
||||||
gateway:
|
gateway:
|
||||||
discovery:
|
discovery:
|
||||||
locator:
|
locator:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 解决跨域
|
# 解决跨域
|
||||||
globalcors:
|
# globalcors:
|
||||||
cors-configurations:
|
# cors-configurations:
|
||||||
'[/**]':
|
# '[/**]':
|
||||||
allowedOriginPatterns: "*"
|
# allowedOriginPatterns: "*"
|
||||||
# 允许请求中携带的头信息
|
# # 允许请求中携带的头信息
|
||||||
allowedHeaders: "*"
|
# allowedHeaders: "*"
|
||||||
# 运行跨域的请求方式
|
# # 运行跨域的请求方式
|
||||||
allowedMethods: "*"
|
# allowedMethods: "*"
|
||||||
# 跨域检测的有效期,单位s
|
# # 跨域检测的有效期,单位s
|
||||||
maxAge: 36000
|
# maxAge: 36000
|
||||||
# 路由
|
# 路由
|
||||||
routes:
|
routes:
|
||||||
- id: service-product
|
- id: service-product
|
||||||
|
@ -41,4 +42,4 @@ logging:
|
||||||
pattern:
|
pattern:
|
||||||
dateformat: HH:mm:ss:SSS
|
dateformat: HH:mm:ss:SSS
|
||||||
file:
|
file:
|
||||||
path: "logs/${spring.application.name}"
|
path: logs/${spring.application.name}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
|
|
||||||
<contextName>logback</contextName>
|
|
||||||
|
|
||||||
<!-- 日志的输出目录 -->
|
|
||||||
<property name="log.path" value="logs/service-product/logs"/>
|
|
||||||
|
|
||||||
<!--控制台日志格式:彩色日志-->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<!-- boldMagenta:粗红-->
|
|
||||||
<!-- cyan:青色 -->
|
|
||||||
<!-- white:白色 -->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<property name="CONSOLE_LOG_PATTERN"
|
|
||||||
value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) %highlight([%-5level]) %green(%logger) %msg%n"/>
|
|
||||||
|
|
||||||
<!--文件日志格式-->
|
|
||||||
<property name="FILE_LOG_PATTERN" value="%date{yyyy-MM-dd HH:mm:ss} [%-5level] %thread %file:%line %logger %msg%n"/>
|
|
||||||
|
|
||||||
<!--编码-->
|
|
||||||
<property name="ENCODING" value="UTF-8"/>
|
|
||||||
|
|
||||||
<!-- 控制台日志 -->
|
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<!-- 临界值过滤器 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
|
||||||
<level>INFO</level>
|
|
||||||
</filter>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 文件日志 -->
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
|
||||||
<file>${log.path}//log.log</file>
|
|
||||||
<append>true</append>
|
|
||||||
<encoder>
|
|
||||||
<pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%n</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 开发环境 -->
|
|
||||||
<springProfile name="dev">
|
|
||||||
<!-- com.atguigu日志记录器:业务程序INFO级别 -->
|
|
||||||
<logger name="com.atguigu" level="INFO"/>
|
|
||||||
<!-- 根日志记录器:INFO级别 -->
|
|
||||||
<root level="INFO">
|
|
||||||
<appender-ref ref="CONSOLE"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
|
||||||
</springProfile>
|
|
||||||
|
|
||||||
</configuration>
|
|
|
@ -18,6 +18,10 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- redis的起步依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -2,8 +2,12 @@ package com.atguigu.product;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ComponentScan("com.atguigu")
|
||||||
|
@EnableCaching// 开启缓存注解
|
||||||
public class ProductApplication {
|
public class ProductApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(ProductApplication.class, args);
|
SpringApplication.run(ProductApplication.class, args);
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
package com.atguigu.product.service.impl;
|
package com.atguigu.product.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.atguigu.product.mapper.CategoryMapper;
|
import com.atguigu.product.mapper.CategoryMapper;
|
||||||
import com.atguigu.product.service.CategoryService;
|
import com.atguigu.product.service.CategoryService;
|
||||||
import com.atguigu.spzx.model.entity.product.Category;
|
import com.atguigu.spzx.model.entity.product.Category;
|
||||||
import com.atguigu.utils.CategoryHelper;
|
import com.atguigu.utils.CategoryHelper;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CategoryServiceImpl implements CategoryService {
|
public class CategoryServiceImpl implements CategoryService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CategoryMapper categoryMapper;
|
private CategoryMapper categoryMapper;
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询以及分类
|
* 查询以及分类
|
||||||
|
@ -21,7 +26,19 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Category> selectOneCategory() {
|
public List<Category> selectOneCategory() {
|
||||||
return categoryMapper.findOneCategory();
|
Object categoryOne = redisTemplate.opsForValue().get("category:one");
|
||||||
|
String categoryJsonString = JSON.toJSONString(categoryOne);
|
||||||
|
|
||||||
|
// 如果Redis包含以及分类,直接返回
|
||||||
|
if (categoryOne != null) {
|
||||||
|
return JSON.parseArray(categoryJsonString, Category.class);
|
||||||
|
}
|
||||||
|
List<Category> dbCategory = categoryMapper.findOneCategory();
|
||||||
|
|
||||||
|
// 查到的数据放到Redis中
|
||||||
|
redisTemplate.opsForValue().set("category:one", dbCategory, 7, TimeUnit.DAYS);
|
||||||
|
|
||||||
|
return dbCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,7 +34,7 @@ logging:
|
||||||
pattern:
|
pattern:
|
||||||
dateformat: HH:mm:ss:SSS
|
dateformat: HH:mm:ss:SSS
|
||||||
file:
|
file:
|
||||||
path: "logs/${spring.application.name}"
|
path: logs/${spring.application.name}
|
||||||
|
|
||||||
mybatis:
|
mybatis:
|
||||||
type-aliases-package: com.atguigu.spzx.model
|
type-aliases-package: com.atguigu.spzx.model
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
|
|
||||||
<contextName>logback</contextName>
|
|
||||||
|
|
||||||
<!-- 日志的输出目录 -->
|
|
||||||
<property name="log.path" value="logs/service-product/logs"/>
|
|
||||||
|
|
||||||
<!--控制台日志格式:彩色日志-->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<!-- boldMagenta:粗红-->
|
|
||||||
<!-- cyan:青色 -->
|
|
||||||
<!-- white:白色 -->
|
|
||||||
<!-- magenta:洋红 -->
|
|
||||||
<property name="CONSOLE_LOG_PATTERN"
|
|
||||||
value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) %highlight([%-5level]) %green(%logger) %msg%n"/>
|
|
||||||
|
|
||||||
<!--文件日志格式-->
|
|
||||||
<property name="FILE_LOG_PATTERN" value="%date{yyyy-MM-dd HH:mm:ss} [%-5level] %thread %file:%line %logger %msg%n"/>
|
|
||||||
|
|
||||||
<!--编码-->
|
|
||||||
<property name="ENCODING" value="UTF-8"/>
|
|
||||||
|
|
||||||
<!-- 控制台日志 -->
|
|
||||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<!-- 临界值过滤器 -->
|
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
|
||||||
<level>INFO</level>
|
|
||||||
</filter>
|
|
||||||
<encoder>
|
|
||||||
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 文件日志 -->
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
|
||||||
<file>${log.path}//log.log</file>
|
|
||||||
<append>true</append>
|
|
||||||
<encoder>
|
|
||||||
<pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%n</pattern>
|
|
||||||
<charset>${ENCODING}</charset>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- 开发环境 -->
|
|
||||||
<springProfile name="dev">
|
|
||||||
<!-- com.atguigu日志记录器:业务程序INFO级别 -->
|
|
||||||
<logger name="com.atguigu" level="INFO"/>
|
|
||||||
<!-- 根日志记录器:INFO级别 -->
|
|
||||||
<root level="INFO">
|
|
||||||
<appender-ref ref="CONSOLE"/>
|
|
||||||
<appender-ref ref="FILE"/>
|
|
||||||
</root>
|
|
||||||
</springProfile>
|
|
||||||
|
|
||||||
</configuration>
|
|
Loading…
Reference in New Issue