Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 为什么使用其他参数从AOP传递到控制器的模型的所有属性都为空_Spring_Spring Aop - Fatal编程技术网

Spring 为什么使用其他参数从AOP传递到控制器的模型的所有属性都为空

Spring 为什么使用其他参数从AOP传递到控制器的模型的所有属性都为空,spring,spring-aop,Spring,Spring Aop,AOP 周围( “执行(*net.inter.warp.bridge.controller.*.*(..,net.inter.warp.bridge.model.User))&”+ 参数(..,authenticatedUser) ) 具有authenticatedUser的公共对象(ProceedingJoinPoint joinPoint,User authenticatedUser)抛出Throwable{ System.out.println(joinPoint+“->”+authent

AOP

周围( “执行(*net.inter.warp.bridge.controller.*.*(..,net.inter.warp.bridge.model.User))&”+ 参数(..,authenticatedUser) ) 具有authenticatedUser的公共对象(ProceedingJoinPoint joinPoint,User authenticatedUser)抛出Throwable{ System.out.println(joinPoint+“->”+authenticatedUser); User=null; 身份验证=SecurityContextHolder.getContext().getAuthentication(); if(身份验证!=null) user=(user)userService.loadUserByUsername(authentication.getName()); 其他的 抛出新的未授权异常(“错误1”); if(user==null) 抛出新的未授权异常(“错误2”); 返回joinPoint.procedure(新对象[]{user}); } 控制器(authenticatedUser的所有属性均为空)

package net.inter.warp.bridge.controller;
@GetMapping(“/box/{id}”)
public ResponseEntity getBoxById(@PathVariable(value=“id”)Long-boxId,用户身份验证用户)
抛出NodeDynamicTableFoundException,ResourceNotFoundException{}
控制器(这是因为除了authenticatedUser之外没有其他参数)

package net.inter.warp.bridge.controller;
@GetMapping(“/box/{id}”)
公共响应属性getBoxById(用户身份验证用户)
抛出NodeDynamicTableFoundException,ResourceNotFoundException{}
AOP似乎讨厌其他参数。。。authenticatedUser不为null,authenticatedUser的每个属性都为null

型号(我不确定此问题是否与此相关)

@实体
@表(name=“users”)
@托斯特林
公共类用户扩展AuthEntity实现UserDetails
{
@凌驾
公共收藏试试这个,:


放弃你的方面,因为它会破坏正确调用方法,Spring Security已经支持这种开箱即用的方法,你不需要AOP。在你的方法参数上使用
@AuthenticationPrincipal
。我只能通过@AuthenticationPrincipal获得用户名、密码、启用等,但我的用户o中还有其他参数对象位于模型文件夹中。如果您使用自己的
User
对象,则不必使用Spring Security
User
对象。我知道有很多方法,但不希望控制器冗余,因此最后选择了此-@GetMapping(“/binders”)公共页listBinder(@AuthenticationPrincipal AccessTokenUserInfo AccessTokenUserInfo){/*现在,不需要这个…User User=userRepository.findByEmail(AccessTokenUserInfo.getUsername()).OrelsThrow(()->new UsernameNotFoundException(“电子邮件:“+AccessTokenUserInfo.getUsername()+”未找到”));*/return binderService.findByPage(1,2,accessTokenUserInfo.getId(),accessTokenUserInfo.getOrganization_id());}
@Around(
"execution(* net.inter.warp.bridge.controller.*.*(..) && " +
"args(authenticatedUser,..)"