代码编织梦想

 

java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor

    at org.springframework.security.core.userdetails.User.<init>(User.java:113)
    at org.springframework.security.core.userdetails.User$UserBuilder.build(User.java:535)
    at com.example.mz.spingsecurity_jwt_deepstudy.SpingsecurityJwtDeepstudyApplicationTests.testcreateJwtToken(SpingsecurityJwtDeepstudyApplicationTests.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1259)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.util.ArrayList.forEach(ArrayList.java:1259)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

 我先来讲一下我的问题背景:

我在做springsecurity和jwt结合的时候测试出现了问题,我想要测试创建token,就必须去builder springsecurity里面的User,但是在这里出现了问题。

我们打一个断点,进到builder里面

 我们可以很清晰的发现他需要一个password

而我却缺失了password,所以抛出了异常

所以我在我的测试类中加上了password,密码随意

        val user= User.builder()
                .username(username)
                .password("123456")
                .authorities(authorities)
                .build();

 结果自然是测试成功的

 

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/romantic6666/article/details/129648188

spring security参考手册_殇莫忆的博客-爱代码爱编程

Spring Security 参考手册 Ben Alex Luke Taylor Rob Winch Gunnar Hillert Table of Contents 前言入门简介 Spring Security是什么?历史发布版本号Getting Spring SecuritySpring

crazyjava_456878921324的博客-爱代码爱编程

可在百度文库中搜索:疯狂java讲义全知识点笔记摘录。 Data Type 1.//change the char to the int directly //Notice :the char use ‘ ’,the St

springsecurity之记住我功能的实现_哈哈我是大健的博客-爱代码爱编程

SpringSecurity之记住我功能的实现 Spring security记住我基本原理: 登录的时候,请求发送给过滤器UsernamePasswordAuthenticationFilter,当该过滤器认证成功后,会调用RememberMeService,会生成一个token,将token写入到浏览器cookie,同时RememberMeServ

spring data jpa - reference documentation-爱代码爱编程

Preface Spring Data JPA provides repository support for the Java Persistence API (JPA). It eases development of applications that need to access JPA data sources. 1. Project Met

Spring boot RequestBodyAdvice和ResponseBodyAdvice 用途-爱代码爱编程

在做项目的过程中啊,我们一般经常要做统一的处理,例如参数的加解密,格式的统一规范,如果我们写api开放出去的话,api个数越来越多,不做统一处理,放到业务里面去处理的话,我们会发现出现非常多的重复代码,而且不利于维护。 所以我们希望我们能在什么地方统一处理这些东西,而且不影响我们现有的业务逻辑,RequestBodyAdvice和ResponseBody

【转】Spring Data JDBC - Reference Documentation-爱代码爱编程

Spring Data JDBC - Reference Documentation Jens Schauder, Jay Bryant, Mark Paluch, Bastian Wilhelm Version 2.1.7, 2021-03-31 © 2018-2021 The original authors.声明:本文转自Spring官网,如果

SpringSecurity(一)-爱代码爱编程

在我们的业务处理中,对于安全的管理是必不可少的,也就是认证以及权限,在Spring横行的今天,学习如何使用SpringSecurity是必不可少的,所以最近想深入学习一下SpringSecurity并分享一下自己的学习历程,此次的学习主要以实践+部分源码为主,完成认证+权限+Oauth2+JWT+oos等,最后会做一个demo,来完成此次的SpringSe

Java教程-爱代码爱编程

在 Java 7 之前,String Pool 被放在运⾏行行时常量量池中,它属于永久代。⽽而在 Java 7,String Pool 被移到 堆中。这是因为永久代的空间有限,在⼤大量量使⽤用字符串串的场景下会导致 OutOfMemoryError 错误。 StackOverflow : What is String interning? 深⼊入解析 St

SpringSecurity-笔记-爱代码爱编程

SpringSecurity 1.学习目标 SpringSecurityOauth2SpringSecurity-Oauth2JWTSpringSecurityOauth2整合JWTSpringSecurityOauth2整合SSO2.SpringSecurity简介 2.1.1安全框架概述 什么是安全框架?解决系统安全问题的框架。如果没有安全框架

一些java笔试题解_nvd11的博客-爱代码爱编程

1) Which of the following techniques can a Java SE programmer use to increase the thread safety of a program? a.

1.权限认证java.lang.illegalargumentexception: cannot pass a null grantedauthority collection-爱代码爱编程

1.权限认证org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annot

pthread-爱代码爱编程

问题描述: 从业务抽离出来大概是这样:大概是如下的场景,这个程序跑了40分钟后,pthread_create返回11,创建失败。 int i=0; void play_handle(){     i=0;     for(;i<5;i++){         sleep(1);         printf("i=%d\n",i);    

前后端分离springsecurity+jwt_springsecurityjwt前后端分离-爱代码爱编程

文章预览 前言一、数据库准备1.1、用户表1.2、角色表1.3、用户角色表1.4、权限(菜单)表1.5、角色权限表 二、环境准备2.1、整合Mybatis-Plus2.1.1、导入依赖2.1.2、配置文件

spring data jdbc -爱代码爱编程

本文计划10月底开始翻译。 Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided t

biginteger 和bigdecimal-爱代码爱编程

出处:为什么会想到大数呢?是因为最近在写leetcode刷题的时候钻牛角尖非要实现数组加1的问题导致的。(leetcode 66 加1问题)不过ps自己对大数还是用的少了,导致害怕用,然后leetcode用了还报错。(