【已解决】An attempt was made to call a method that does not exist.
·
1. 报错
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerPropertiesMapper.asAuthorizationServerSettings(OAuth2AuthorizationServerPropertiesMapper.java:55)
The following method did not exist:
'org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder.multipleIssuersAllowed(boolean)'
The calling method's class, org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerPropertiesMapper, was loaded from the following location:
jar:file:/C:/../.m2/repository/org/springframework/boot/spring-boot-autoconfigure/3.3.4/spring-boot-autoconfigure-3.3.4.jar!/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesMapper.class
The called method's class, org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder, is available from the following locations:
jar:file:/C:/../.m2/repository/org/springframework/security/spring-security-oauth2-authorization-server/1.1.2/spring-security-oauth2-authorization-server-1.1.2.jar!/org/springframework/security/oauth2/server/authorization/settings/AuthorizationServerSettings$Builder.class
The called method's class hierarchy was loaded from the following locations:
org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings.Builder: file:/C:/../.m2/repository/org/springframework/security/spring-security-oauth2-authorization-server/1.1.2/spring-security-oauth2-authorization-server-1.1.2.jar
org.springframework.security.oauth2.server.authorization.settings.AbstractSettings.AbstractBuilder: file:/C:/../.m2/repository/org/springframework/security/spring-security-oauth2-authorization-server/1.1.2/spring-security-oauth2-authorization-server-1.1.2.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.security.oauth2.server.servlet.OAuth2AuthorizationServerPropertiesMapper and org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings$Builder
Disconnected from the target VM, address: '127.0.0.1:51495', transport: 'socket'
Process finished with exit code 1
2. 原因
日志第一行即指出,系统试图调用一个不存在的方法(An attempt was made to call a method that does not exist.)。
接着的 The following method did not exist、The calling method's class、The called method's class 分别告诉开发人员以下信息:
- 不存在的方法是
AuthorizationServerSettings.Builder.multipleIssuersAllowed(boolean)。 - 调用该方法的类是
org.springframework.boot的OAuth2AuthorizationServerPropertiesMapper,版本是 3.3.4。 - 被调用的类是
org.springframework.security的AuthorizationServerSettings$Builder,版本是 1.1.2。
结合 Action 可以知道,报错的原因是 org.springframework.boot 和 org.springframework.security 的版本不匹配。
具体是,系统使用了 Spring Boot 3.3.4,并尝试调用 AuthorizationServerSettings.Builder.multipleIssuersAllowed(boolean) 方法,而它使用的 Spring Authorization Server 版本中还没有这个方法。
3. 解决方案
方案一
保持 Spring Boot 3.3.4 的版本不变,将 org.springframework.security 的版本升级。
如下:
- 修改前的 pom.xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId>
<version>1.1.2</version>
</dependency>
- 修改后的 pom.xml
<!-- 去掉 version 标签,由 Spring Boot 自动引入匹配的版本 -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId>
</dependency>
方案二
保持 org.springframework.security 的版本不变,将 Spring Boot 3.3.4 的版本降级。
更多推荐



所有评论(0)