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

这篇具有很好参考价值的文章主要介绍了java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf,java,spring boot,单元测试,junit,spring

 文章来源地址https://www.toymoban.com/news/detail-760232.html

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里面

java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf,java,spring boot,单元测试,junit,spring

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

java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf,java,spring boot,单元测试,junit,spring

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

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

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

 结果自然是测试成功的

java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf,java,spring boot,单元测试,junit,spring

 

 

 

到了这里,关于java.lang.IllegalArgumentException: Cannot pass null or empty values to constructor at org.springf的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 关于Spring中java.lang.NullPointerException: Cannot invoke “xxx“ because “xxx“ is null 的问题

    当我好不容易编译成功,开始运行时,使用postman测试接口功能时却返回了一个错误: 编译成功开始运行: postman返回: 并在IDEA显示了 java.lang.NullPointerException: Cannot invoke “com.example.mybatisdemo.mapper.StudentMapper.ListStudent()” because “this.studentMapper” is null 错误指向了Service层调用的

    2024年02月05日
    浏览(32)
  • 报错:java.lang.IllegalArgumentException

    开发,测试环境运行正常的接口到现场报错,报错日志关键信息如下:java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986。 由于代码在开发测试环境测试通过,判断大概率是现场特殊数据导致问题。查资料得知,如果

    2024年02月04日
    浏览(35)
  • 解决java.lang.IllegalArgumentException异常的正确解决方法

    java.lang.IllegalArgumentException 是 Java 编程语言中的一个运行时异常,通常表示向方法传递了一个不合法或不适当的参数。当程序在运行时遇到此类异常,它会立即中断当前的执行流程,并抛出异常信息。理解这个异常的原因并学会如何正确解决,对于编写健壮的 Java 程序至关重

    2024年04月25日
    浏览(50)
  • org.elasticsearch.bootstrap.StartupException:java.lang.IllegalArgumentException:

    ES进入bin文件夹启动elasticsearch.bat文件后出现 org.elasticsearch.bootstrap.StartupException:java.lang.IllegalArgumentException: Plugin [analysis-ik] was built for Elasticsearch version Caused by: java.lang.IllegalArgumentException: Plugin [analysis-ik] was built for Elasticsearch version 7.17.4 but version 7.16.2 is running java.lang.IllegalArgum

    2024年02月11日
    浏览(31)
  • java.lang.IllegalArgumentException: bound must be positive

    IllegalArgumentException 是Java中的一个异常类,用于在方法中传递非法的参数值时抛出。具体的错误信息 bound must be positive 表示传入的参数边界必须是一个正数。 在Java中,一些方法或构造函数要求参数值是正数。如果传入了负数或零,就会抛出这个异常。要解决此问题,您需要检

    2024年02月04日
    浏览(35)
  • Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.Str

    这个异常意味着你尝试在Java程序中比较一个java.util.Date对象和一个java.lang.String对象,这是无效的比较。Java中的不同类型的对象只能在特定的比较操作中使用。通常,日期对象被用于表示日期和时间信息,而字符串对象用于表示文本信息。因此,Java不允许直接将它们进行比较

    2024年02月16日
    浏览(35)
  • 解决错误 “java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String“ 的

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到网站,这篇文章男女通用,看懂了就去分享给你的码吧。 在 Java 开发中,有时会遇到错误信息 “java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String”,

    2024年02月10日
    浏览(40)
  • 记报错信息:java.lang.IllegalArgumentException: MALFORMED解决方案

    在调用JDK自带的zipfile读取压缩包文件的时候,出现了以下错误: SjXcmcFeignClient:124 - BaseFeignClient 拦截到【未知系统异常】Exception异常: java.lang.IllegalArgumentException: MALFORMED[1] at java.util.zip.ZipCoder.toString(ZipCoder.java:65) at java.util.zip.ZipFile.getZipEntry(ZipFile.java:583) at java.util.zip.ZipFile.ac

    2024年02月05日
    浏览(36)
  • Request processing failed: java.lang.IllegalArgumentException: Name for argument of type [java.lang

    问题:使用spring-mvc进行获取前端参数时报错 具体报错如下: 我使用的是最新版的6.1.4版本的spring-webmvc,传参方式如下 按道理按照之前的写法,就算是没有加@RequestParam注解,这样子也不会报错,很奇怪。 后面发现这是新版本的问题,可能是新版的webmvc改了吧,简单类型应该

    2024年04月15日
    浏览(28)
  • 已解决java.lang.IllegalArgumentException异常的正确解决方法,亲测有效!!!

    已解决java.lang.IllegalArgumentException异常的正确解决方法,亲测有效!!! java.lang.IllegalArgumentException java.lang.IllegalArgumentException是Java中的一个异常,表示传递给方法的参数不合法。 下滑查看解决方法 这个异常通常在方法内部检查参数的有效性时抛出。要解决这个问题,你可以

    2024年02月04日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包