发布 v2.3.2

This commit is contained in:
疯狂的狮子li
2021-06-11 09:29:21 +08:00
45 changed files with 457 additions and 163 deletions

View File

@@ -3,6 +3,7 @@ package com.ruoyi.framework.aspectj;
import com.ruoyi.common.annotation.RedisLock;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisLockManager;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -33,7 +34,7 @@ import java.util.concurrent.TimeUnit;
public class RedisLockAspect {
@Autowired
private RedissonClient redissonClient;
private RedisLockManager redisLockManager;
@Pointcut("@annotation(com.ruoyi.common.annotation.RedisLock)")
public void annotationPointcut() {
@@ -70,14 +71,16 @@ public class RedisLockAspect {
key = Constants.REDIS_LOCK_KEY + key;
Object res;
try {
if (acquire(key, expireTime, TimeUnit.SECONDS)) {
if (redisLockManager.getLock(key, expireTime, TimeUnit.SECONDS)) {
log.info("lock => key : " + key + " , ThreadName : " + Thread.currentThread().getName());
try {
res = joinPoint.proceed();
return res;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
release(key);
redisLockManager.unLock(key);
log.info("unlock => key : " + key + " , ThreadName : " + Thread.currentThread().getName());
}
} else {
throw new RuntimeException("redis分布式锁注解参数异常");
@@ -133,32 +136,4 @@ public class RedisLockAspect {
return listPar;
}
/**
* 加锁RLock带超时时间的
*/
private boolean acquire(String key, long expire, TimeUnit expireUnit) {
try {
//获取锁对象
RLock mylock = redissonClient.getLock(key);
//加锁,并且设置锁过期时间,防止死锁的产生
mylock.tryLock(expire, expire, expireUnit);
} catch (InterruptedException e) {
return false;
}
log.info("lock => key : " + key + " , ThreadName : " + Thread.currentThread().getName());
//加锁成功
return true;
}
/**
* 锁的释放
*/
private void release(String lockName) {
//获取所对象
RLock mylock = redissonClient.getLock(lockName);
//释放锁(解锁)
mylock.unlock();
log.info("unlock => key : " + lockName + " , ThreadName : " + Thread.currentThread().getName());
}
}

View File

@@ -11,6 +11,11 @@ import java.util.Arrays;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
/**
* 异步配置
*
* @author Lion Li
*/
@EnableAsync
@Configuration
public class AsyncConfig extends AsyncConfigurerSupport {

View File

@@ -6,15 +6,20 @@ import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.redisson.spring.cache.CacheConfig;
import org.redisson.spring.cache.RedissonSpringCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* redis配置
@@ -67,4 +72,15 @@ public class RedisConfig extends CachingConfigurerSupport {
.setDnsMonitoringInterval(singleServerConfig.getDnsMonitoringInterval());
return Redisson.create(config);
}
/**
* 整合spring-cache
*/
@Bean
public CacheManager cacheManager(RedissonClient redissonClient) {
Map<String, CacheConfig> config = new HashMap<>();
config.put("redissonCacheMap", new CacheConfig(30*60*1000, 10*60*1000));
return new RedissonSpringCacheManager(redissonClient, config, JsonJacksonCodec.INSTANCE);
}
}

View File

@@ -15,7 +15,7 @@ import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
/**
* 通用配置
*
*
* @author ruoyi
*/
@Configuration
@@ -31,8 +31,7 @@ public class ResourcesConfig implements WebMvcConfigurer
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/");
/** swagger配置 */
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
}
/**
@@ -63,4 +62,4 @@ public class ResourcesConfig implements WebMvcConfigurer
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
}
}

View File

@@ -3,6 +3,7 @@ package com.ruoyi.framework.config;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.ruoyi.framework.config.properties.SwaggerProperties;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -13,18 +14,16 @@ import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.List;
/**
* Swagger2的接口配置
* Swagger 文档配置
*
* @author Lion Li
*/
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig {
@@ -36,7 +35,7 @@ public class SwaggerConfig {
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
return new Docket(DocumentationType.OAS_30)
.enable(swaggerProperties.getEnabled())
// 用来创建该API的基本信息展示在文档的页面中自定义展示的信息
.apiInfo(apiInfo())
@@ -60,7 +59,7 @@ public class SwaggerConfig {
*/
private List<SecurityScheme> securitySchemes() {
List<SecurityScheme> apiKeyList = new ArrayList<SecurityScheme>();
apiKeyList.add(new ApiKey("Authorization", "Authorization", "header"));
apiKeyList.add(new ApiKey("Authorization", "Authorization", In.HEADER.toValue()));
return apiKeyList;
}
@@ -72,7 +71,7 @@ public class SwaggerConfig {
securityContexts.add(
SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("^(?!auth).*$"))
.operationSelector(o -> o.requestMappingPattern().matches("/.*"))
.build());
return securityContexts;
}

View File

@@ -6,7 +6,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 验证码 配置属性
* swagger 配置属性
*
* @author Lion Li
*/

View File

@@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 验证码 配置属性
* 线程池 配置属性
*
* @author Lion Li
*/

View File

@@ -4,6 +4,11 @@ import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* token 配置属性
*
* @author Lion Li
*/
@Data
@Component
@ConfigurationProperties(prefix = "token")

View File

@@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 验证码 配置属性
* xss过滤 配置属性
*
* @author Lion Li
*/