Spring报错解决一览

devtools/2025/3/1 13:31:41/

Spring错误持续更新贴…

问题一

springcloud-OAuth2.0配置的时候报错

Method springSecurityFilterChain in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration required a bean of type ‘org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateFactory’ that could not be found.

The following candidates were found but could not be injected:
- Bean method ‘userInfoRestTemplateFactory’ in ‘ResourceServerTokenServicesConfiguration’ not loaded because @ConditionalOnMissingBean (types: org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration; SearchStrategy: all) found beans of type ‘org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration’ org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration

Action:

Consider revisiting the entries above or defining a bean of type ‘org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoRestTemplateFactory’ in your configuration.

问题原因:

(1)做服务器端OAuth,引用了客户端的相关jar,并且还没有配置;

问题二:

spring cloud security oauth2.0 默认是禁用Client模式进行授权的;Oauth2.0 client模式无法授权;

allowFormAuthenticationForClients()方法开启;

问题三:

密码模式获取token的情况下, Basic校验写错了

{
“timestamp”: “2019-05-16T15:31:11.450+0000”,
“status”: 401,
“error”: “Unauthorized”,
“message”: “Unauthorized”,
“path”: “/oauth/token”
}

解决: 这个一种情况是Basic用户名密码写错了,在拦截器BasicAuthenticationFilter中校验不通过抛出异常

问题三:springSeurity明明配置了password授权,但是在做改动的时候提示如下

{
“error”: “unsupported_grant_type”,
“error_description”: “Unsupported grant type: password”
}

解答:AuthorizationServerEndpointsConfigurer类中获取所有的granter的时候,需要判断authenticationmananager是否为空,才能默认加载password权限分配器

问题四:

java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer@6d8b7ea9 to already built object
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.add(AbstractConfiguredSecurityBuilder.java:196) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.apply(AbstractConfiguredSecurityBuilder.java:133) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.builders.HttpSecurity.getOrApply(HttpSecurity.java:1501) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.builders.HttpSecurity.authorizeRequests(HttpSecurity.java:654) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer.configure(ResourceServerSecurityConfigurer.java:222) ~[spring-security-oauth2-2.3.4.RELEASE.jar:na]
at org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer.configure(ResourceServerSecurityConfigurer.java:59) ~[spring-security-oauth2-2.3.4.RELEASE.jar:na]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.configure(AbstractConfiguredSecurityBuilder.java:384) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:330) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.builders.WebSecurity.performBuild(WebSecurity.java:294) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.builders.WebSecurity.performBuild(WebSecurity.java:79) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:334) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:104) ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB415a6f9.CGLIB$springSecurityFilterChainKaTeX parse error: Undefined control sequence: \[ at position 17: …(<generated>) ~\̲[̲spring-security… E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB 415 a 6 f 9 415a6f9 415a6f9 F a s t C l a s s B y S p r i n g C G L I B FastClassBySpringCGLIB FastClassBySpringCGLIBKaTeX parse error: Undefined control sequence: \[ at position 31: …(<generated>) ~\̲[̲spring-security…BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB415a6f9.springSecurityFilterChain() ~[spring-security-config-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_162]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
… 22 common frames omitted

问题5:

{
“error”: “invalid_token”,
“error_description”: “eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsidXNlci1zZXJ2aWNlcyJdLCJleHAiOjE1NTg2NzcwNjgsInVzZXJfbmFtZSI6ImFkbWluIiwianRpIjoiYjlkMjY5YjgtOGE4Yi00ZDI1LTk4YzktMzkwNzRlNGNhMzk3IiwiY2xpZW50X2lkIjoibGl4aWFvaGFvIiwic2NvcGUiOlsidXNlciJdfQ.Pa03fAoN0APHQMh5FSUWRtxtQbn5vVN1JQGLu-Ql8k4”
}

解决: 原因多样,总的来说就是去服务器端根据token查询用户信息错误(1)就是token失效等 (2)地址在没有配置ssl的时候使用https等

问题6:

{
“error”: “access_denied”,
“error_description”: “Invalid token does not contain resource id (oauth2-resource)”
}

解决: 用户去资源服务器锁清秋的资源标识,在token中不存在; 如你生成的token中可用资源包括 查询用户信息,但是在请求用户信息的时候,它有拦截会查看你token中的标识是否跟自己的标识相同

问题7:

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens

解决:请求协议不一致,应该都为http或https

问题8:

Caused by: feign.FeignException: status 403 reading OAuthUserService#testautherization()
at feign.FeignException.errorStatus(FeignException.java:78)
at feign.codec.ErrorDecoder D e f a u l t . d e c o d e ( E r r o r D e c o d e r . j a v a : 93 ) a t f e i g n . S y n c h r o n o u s M e t h o d H a n d l e r . e x e c u t e A n d D e c o d e ( S y n c h r o n o u s M e t h o d H a n d l e r . j a v a : 149 ) a t f e i g n . S y n c h r o n o u s M e t h o d H a n d l e r . i n v o k e ( S y n c h r o n o u s M e t h o d H a n d l e r . j a v a : 78 ) a t f e i g n . R e f l e c t i v e F e i g n Default.decode(ErrorDecoder.java:93) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:149) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78) at feign.ReflectiveFeign Default.decode(ErrorDecoder.java:93)atfeign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:149)atfeign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:78)atfeign.ReflectiveFeignFeignInvocationHandler.invoke(ReflectiveFeign.java:103)
at com.sun.proxy. P r o x y 138. t e s t a u t h e r i z a t i o n ( U n k n o w n S o u r c e ) a t c o m . e n c i . t e s t . s e r v e r . m o d u l e . c o n t r o l l e r . P o l i c y C o n t r o l l e r . f e i g n R e q u e s t ( P o l i c y C o n t r o l l e r . j a v a : 151 ) a t c o m . e n c i . t e s t . s e r v e r . m o d u l e . c o n t r o l l e r . P o l i c y C o n t r o l l e r Proxy138.testautherization(Unknown Source) at com.enci.test.server.module.controller.PolicyController.feignRequest(PolicyController.java:151) at com.enci.test.server.module.controller.PolicyController Proxy138.testautherization(UnknownSource)atcom.enci.test.server.module.controller.PolicyController.feignRequest(PolicyController.java:151)atcom.enci.test.server.module.controller.PolicyController F a s t C l a s s B y S p r i n g C G L I B FastClassBySpringCGLIB FastClassBySpringCGLIB c 9349 f 5 f . i n v o k e ( < g e n e r a t e d > ) a t o r g . s p r i n g f r a m e w o r k . c g l i b . p r o x y . M e t h o d P r o x y . i n v o k e ( M e t h o d P r o x y . j a v a : 218 ) a t o r g . s p r i n g f r a m e w o r k . a o p . f r a m e w o r k . C g l i b A o p P r o x y c9349f5f.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy c9349f5f.invoke(<generated>)atorg.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)atorg.springframework.aop.framework.CglibAopProxyCglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy D y n a m i c A d v i s e d I n t e r c e p t o r . i n t e r c e p t ( C g l i b A o p P r o x y . j a v a : 688 ) a t c o m . e n c i . t e s t . s e r v e r . m o d u l e . c o n t r o l l e r . P o l i c y C o n t r o l l e r DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.enci.test.server.module.controller.PolicyController DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)atcom.enci.test.server.module.controller.PolicyController E n h a n c e r B y S p r i n g C G L I B EnhancerBySpringCGLIB EnhancerBySpringCGLIB$6f5b74e0.feignRequest()
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.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
… 102 more

解决:权限不足, 获取的token中锁允许访问的resource与实际访问的resource信息不匹配,被拒绝访问


http://www.ppmy.cn/devtools/163630.html

相关文章

RabbitMQ 高级配置与优化:从入门到精通

RabbitMQ 高级配置与优化:从入门到精通 引言 在分布式架构中,消息队列(MQ)是必不可少的一环,而 RabbitMQ 作为业界广泛使用的消息中间件,凭借其高吞吐、可扩展、可靠性等特性备受青睐。然而,很多开发者和运维人员在使用 RabbitMQ 时,仅仅停留在"能用"的层面…

DDD 架构之领域驱动设计【通俗易懂】

文章目录 1. 前言2. MVC 对比 DDD3. DDD 分层架构4. 完整业务流程 1. 前言 官方回答&#xff1a;DDD是一种应对复杂业务系统的设计方法&#xff0c;通过将软件设计与业务领域紧密结合&#xff0c;帮助开发人员构建清晰、可维护的领域模型。在复杂的业务系统中&#xff0c;它能…

c++中迭代器和指针有什么区别?

在 C 中&#xff0c;迭代器和指针虽然在某些场景下有相似的行为&#xff0c;但它们在设计目的、功能和使用场景上有本质区别。以下是详细对比和最佳实践&#xff1a; 一、核心区别对比表 特征指针迭代器本质原生数据类型&#xff0c;直接存储内存地址类对象&#xff0c;抽象容…

Android用ExoPlayer获取视频正确的尺寸

最近在实现视频预加载功能&#xff0c;遇到了较多的疑问未解决&#xff0c;但机缘巧合解决了困扰我很久的某些视频 展示异常的问题&#xff08;被压扁&#xff09;&#xff0c;如下图 我的实现方法&#xff1a; Overridepublic void onVideoSizeChanged(VideoSize videoSize)…

nuxt常用组件库html-validator应用解析

html-validator 主要用于自动验证nuxt服务器呈现的HTML(SSR和SSG)&#xff0c;以检测可能导致水合错误的HTML常见问题&#xff0c;有助于减少水合错误&#xff0c;检测常见的可访问性错误。 安装 npx nuxilatest module add html-validator配置 若自动更新nuxt.config.ts配置文…

鸿蒙开发-画布综合示例

以下是一个更复杂的ArkTS示例&#xff0c;它展示了如何在画布上绘制多个形状&#xff08;包括圆形、矩形和文本&#xff09;&#xff0c;并处理触摸事件来改变画布上的某些属性&#xff08;如颜色&#xff09;。 示例代码 import { Color, Point } from ohos.build.attr; imp…

【蓝桥杯集训·每日一题2025】 AcWing 5439. 农夫约翰真的种地 python

AcWing 5439. 农夫约翰真的种地 题目描述 Week 2 2月27日 农夫约翰在他的农场种植了 N N N 个芦笋&#xff0c;编号 1 ∼ N 1 \sim N 1∼N。 其中&#xff0c;第 i i i 个芦笋的初始高度为 h i h_i hi​&#xff0c;每经过一天高度会增长 a i a_i ai​。 给定一个 0…

Python在实际工作中的运用-指定目录内所有Excel文件转CSV

闲来无事浏览到《【办公自动化】使用Python批量处理Excel文件并转为csv文件》这篇博文&#xff0c;关于多层目录Excel转Csv在处理过程中略显繁复&#xff0c;而且灵活度不高&#xff0c;代码如下&#xff1a; import pandas as pd import os from datetime import datetime # …