Skip to content

Commit

Permalink
2024-12-07 09:03:14
Browse files Browse the repository at this point in the history
  • Loading branch information
yingzhuo committed Dec 7, 2024
1 parent e6b02f9 commit 9417177
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.Assert;
import spring.turbo.core.AspectUtils;
import spring.turbo.core.SpEL;
import spring.turbo.core.SpELForAspectAround;
import spring.turbo.exception.RuntimeExceptionSupplier;

import java.util.Map;

/**
* @author 应卓
* @see AvoidRepeatedInvocation
Expand All @@ -21,14 +19,20 @@
@Aspect
public class AvoidRepeatedInvocationAdvice implements Ordered {

/*
* 本切面逻辑需要手工注册
*/

private final RedisOperations<String, String> redisOperations;
private final RuntimeExceptionSupplier exceptionSupplier;
private final int order;

/**
* 构造方法
*
* @param redisOperations RedisOperations实例,通常是 {@link StringRedisTemplate}
* @param exceptionSupplier 异常提供器,如果判断为重复调用。使用这个东西产生异常并抛出
*/
public AvoidRepeatedInvocationAdvice(RedisOperations<String, String> redisOperations, RuntimeExceptionSupplier exceptionSupplier) {
this(redisOperations, exceptionSupplier, HIGHEST_PRECEDENCE);
}

/**
* 构造方法
*
Expand All @@ -52,17 +56,8 @@ public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
return joinPoint.proceed();
}

var method = AspectUtils.getMethod(joinPoint);

var redisKey = (String) SpEL.getValue(
annotation.value(),
(Object) null,
Map.of(
"args", joinPoint.getArgs(),
"method", method,
"target", joinPoint.getTarget()
)
);
var redisKey = SpELForAspectAround.newInstance(annotation.value(), joinPoint)
.getValue();

var success = redisOperations.opsForValue()
.setIfAbsent(redisKey, "1", annotation.leaseTime(), annotation.leaseTimeUnit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
@Data
@ConfigurationProperties(prefix = "springturbo.webmvc")
public class SpringBootWebMvcProperties implements Serializable {
public class SpringTurboWebMvcProperties implements Serializable {

private boolean dataBinderInitializingAdvice = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @since 1.3.0
*/
@AutoConfiguration
@EnableConfigurationProperties(SpringBootWebMvcProperties.class)
@EnableConfigurationProperties(SpringTurboWebMvcProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class WebMvcAutoConfiguration implements WebMvcConfigurer {

Expand Down

0 comments on commit 9417177

Please sign in to comment.