Spring 当我要连接时,出现以下问题“错误”:“内部服务器错误”,“消息”:“无可用消息”,
@邮戳/签名Spring 当我要连接时,出现以下问题“错误”:“内部服务器错误”,“消息”:“无可用消息”,,spring,spring-boot,spring-security,jwt,jwt-auth,Spring,Spring Boot,Spring Security,Jwt,Jwt Auth,@邮戳/签名 public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) { System.out.println("a"+loginRequest.getUsername()+loginRequest.getPassword()); Authentication authentication = authenticationManager.auth
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {
System.out.println("a"+loginRequest.getUsername()+loginRequest.getPassword());
Authentication authentication = authenticationManager.authenticate(
new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword()));
System.out.println("a"+loginRequest.getUsername()+loginRequest.getPassword());
// new RuntimeException("Error: cccccc is not found.");
SecurityContextHolder.getContext().setAuthentication(authentication);
String jwt = jwtUtils.generateJwtToken(authentication);
new RuntimeException("Error: cccccc is not found."+ jwt);
// new RuntimeException("Error: cccccc is not found.");
UserDetailslmpl userDetails = (UserDetailslmpl) authentication.getPrincipal();
List<String> roles = userDetails.getAuthorities().stream()
.map(item -> item.getAuthority())
.collect(Collectors.toList());
// new RuntimeException("Error: aaaa is not found.");
return ResponseEntity.ok(new JwtResponse(jwt,
userDetails.getId(),
userDetails.getUsername(),
userDetails.getEmail(),
roles));
}
如注释中所述,它是控制器中的NullPointerException。 堆栈跟踪告诉您,在控制器的第56行中
String jwt = jwtUtils.generateJwtToken(authentication);
jwtUtils对象似乎为空。这只是一个NullPointerException,请查看此处:。请不要在明显离题/不好的问题上发布答案!