将本地启动配置文件拆分,方便各环境参数维护,同时增加knife4j的支持

This commit is contained in:
weiweiw 2024-09-27 13:26:44 +08:00
parent 28103703fe
commit 25872802bc
20 changed files with 273 additions and 159 deletions

View File

@ -0,0 +1,21 @@
# Tomcat
server:
port: 18081
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,7 +1,3 @@
# Tomcat
server:
port: 18081
# Spring
spring:
application:
@ -10,21 +6,6 @@ spring:
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#加密组件
jasypt:

View File

@ -92,4 +92,9 @@ public class HttpStatus
*/
public static final int WARN = 601;
/**
* 系统警告消息
*/
public static final int REPEATE_ERROR = 602;
}

View File

@ -39,14 +39,16 @@ public class RedisService
/**
* 缓存基本的对象IntegerString实体类等
*
* @param key 缓存的键值
* @param value 缓存的值
* @param timeout 时间
* @param key 缓存的键值
* @param value 缓存的值
* @param timeout 时间
* @param timeUnit 时间颗粒度
* @return
*/
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit)
public <T> Boolean setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit)
{
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
return null;
}
/**

View File

@ -0,0 +1,24 @@
package com.bonus.common.security.annotation;
import java.lang.annotation.*;
/**
* 自定义注解防止表单重复提交
*
*/
@Inherited
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface PreventRepeatSubmit
{
/**
* 间隔时间(s)小于此时间视为重复提交
*/
public int interval() default 3;
/**
* 提示消息
*/
public String message() default "不允许重复提交,请稍候再试";
}

View File

@ -30,6 +30,7 @@ public class PermisssionOrInnerAuthAspect
@Around("@annotation(RequiresPermissionsOrInnerAuth)")
public Object innerAround(ProceedingJoinPoint point, RequiresPermissionsOrInnerAuth permissionsOrInnerAuth) throws Throwable
{
log.info("******************RequiresPermissionsOrInnerAuth**********");
MethodSignature signature = (MethodSignature) point.getSignature();
RequiresPermissionsOrInnerAuth auth = signature.getMethod().getAnnotation(RequiresPermissionsOrInnerAuth.class);

View File

@ -0,0 +1,67 @@
package com.bonus.common.security.aspect;
import com.alibaba.fastjson2.JSON;
import com.bonus.common.core.exception.RepeatCommitException;
import com.bonus.common.redis.service.RedisService;
import com.bonus.common.security.annotation.PreventRepeatSubmit;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
@Aspect
@Component
@Slf4j
public class PreventRepeatSubmitAspect {
private static final String header = "Authorization";
@Autowired
private RedisService redisCache;
// 定义一个切入点待测试使用
@Pointcut("@annotation(com.bonus.sgzb.common.security.annotation.PreventRepeatSubmit)")
public void preventRepeatSubmit() {
}
public Object checkPrs(ProceedingJoinPoint pjp) throws Throwable {
log.debug("进入preventRepeatSubmit切面");
//得到request对象
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String requestURI = request.getRequestURI();
log.debug("防重复提交的请求地址:{} ,请求方式:{}",requestURI,request.getMethod());
log.debug("防重复提交拦截到的类名:{} ,方法:{}",pjp.getTarget().getClass().getSimpleName(),pjp.getSignature().getName());
//获取请求参数
Object[] args = pjp.getArgs();
String argStr = JSON.toJSONString(args);
//这里替换是为了在redis可视化工具中方便查看
argStr=argStr.replace(":","#");
// 唯一值没有消息头则使用请求地址
String submitKey = request.getHeader(header).trim();
// 唯一标识指定key + url +参数+token
String cacheRepeatKey = "repeat_submit:" + requestURI+":" +argStr+":"+ submitKey;
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method method=ms.getMethod();
PreventRepeatSubmit preventRepeatSubmit=method.getAnnotation(PreventRepeatSubmit.class);
int interval = preventRepeatSubmit.interval();
log.debug("获取到preventRepeatSubmit的有效期时间"+interval);
//redis分布式锁
Boolean aBoolean = redisCache.setCacheObject(cacheRepeatKey, 1, (long) preventRepeatSubmit.interval(), TimeUnit.SECONDS);
//aBoolean为true则证明没有重复提交
if(!aBoolean){
throw new RepeatCommitException("重复提交,请稍后重试");
}
return pjp.proceed();
}
}

View File

@ -92,6 +92,11 @@
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>${jasypt-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-ui</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,36 @@
# Tomcat
server:
port: 18080
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
sentinel:
# 取消控制台懒加载
eager: true
transport:
# 控制台地址
dashboard: 192.168.0.14:18858
# nacos配置持久化
datasource:
ds1:
nacos:
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
dataId: sentinel-bonus-gateway
groupId: DEFAULT_GROUP
data-type: json
rule-type: gw-flow

View File

@ -1,6 +1,3 @@
# Tomcat
server:
port: 18080
# Spring
spring:
application:
@ -9,37 +6,6 @@ spring:
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
sentinel:
# 取消控制台懒加载
eager: true
transport:
# 控制台地址
dashboard: 192.168.0.14:18858
# nacos配置持久化
datasource:
ds1:
nacos:
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
dataId: sentinel-bonus-gateway
groupId: DEFAULT_GROUP
data-type: json
rule-type: gw-flow
#加密组件
jasypt:

View File

@ -0,0 +1,21 @@
# Tomcat
server:
port: 9300
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,31 +1,9 @@
# Tomcat
server:
port: 9300
# Spring
spring:
application:
# 应用名称
name: bonus-file
# servlet:
# multipart:
# max-file-size: 5GB
# max-request-size: 5GB
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,21 @@
# Tomcat
server:
port: 9202
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
config:
# 配置中心地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,7 +1,3 @@
# Tomcat
server:
port: 9202
# Spring
spring:
application:
@ -9,19 +5,4 @@ spring:
name: bonus-gen
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
config:
# 配置中心地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
active: dev

View File

@ -0,0 +1,20 @@
# Tomcat
server:
port: 9203
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
config:
# 配置中心地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,7 +1,3 @@
# Tomcat
server:
port: 9203
# Spring
spring:
application:
@ -10,18 +6,3 @@ spring:
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
config:
# 配置中心地址
server-addr: 192.168.0.56:8848
namespace: 9cde1ce1-98bc-4b9c-9213-f1fbf8a5b3cc
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -0,0 +1,22 @@
# Tomcat
server:
port: 18082
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,7 +1,3 @@
# Tomcat
server:
port: 18082
# Spring
spring:
application:
@ -10,23 +6,6 @@ spring:
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
# namespace: f648524d-0a7b-449e-8f92-64e05236fd51
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
# namespace: f648524d-0a7b-449e-8f92-64e05236fd51
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#加密组件
jasypt:

View File

@ -0,0 +1,22 @@
# Tomcat
server:
port: 9100
# Spring
spring:
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

View File

@ -1,7 +1,3 @@
# Tomcat
server:
port: 9100
# Spring
spring:
application:
@ -10,21 +6,6 @@ spring:
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
config:
# 配置中心地址
server-addr: 192.168.0.14:8848
namespace: f648524d-0a7b-449e-8f92-64e05236fd51
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
#加密组件
jasypt: