gpt4 book ai didi

spring-aop - 使用 spring aop 获取当前用户

转载 作者:行者123 更新时间:2023-12-04 01:35:37 29 4
gpt4 key购买 nike

我使用 spring boot 2 和 spring security。

使用 aop,我搜索以获取调用该方法的用户。

@Aspect
@Component
public class LogAspect {

@Before("execution(* com.moplogy.controller.*))")
public void getAllAdvice(JoinPoint joinPoint){

System.out.println("method called " + joinPoint.getSignature().getName());

}
}

有什么想法吗?

最佳答案

尝试在你的方法中添加这一行

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

关于spring-aop - 使用 spring aop 获取当前用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50041880/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com