Correct the classpath of your application so that it contains a single, compatible version of 包名

版本

SpringCloud Gateway Zuul 改造成Gateway

OAuth2 升级成最新

SpringBoot、SpringCloud、SpringCloudAlibaba 对应的版本

 <spring-boot.version>2.5.3</spring-boot.version>
    <spring-cloud.version>2020.0.3</spring-cloud.version>
    <spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
    <spring-security-oauth2.version>2.2.5.RELEASE</spring-security-oauth2.version>

        <!-- oauth2-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
            <version>${spring-security-oauth2.version}</version>
        </dependency>

报错内容

2021-08-17 15:22:57.465  WARN 29317 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.reactive.WebFluxSecurityConfiguration': Unsatisfied dependency expressed through method 'setSecurityWebFilterChains' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [com/zclh/gsch/gateway/config/ResourceServerConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.web.server.SecurityWebFilterChain]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtDecoder' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerJwkConfiguration$JwtConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.jwt.ReactiveJwtDecoder]: Factory method 'jwtDecoder' threw exception; nested exception is java.lang.NoSuchMethodError: com.nimbusds.jose.proc.JWSVerificationKeySelector.<init>(Ljava/util/Set;Lcom/nimbusds/jose/jwk/source/JWKSource;)V
2021-08-17 15:22:57.465  INFO 29317 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-0} closing ...
2021-08-17 15:22:57.490  INFO 29317 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-08-17 15:22:57.503 ERROR 29317 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.security.oauth2.jwt.NimbusReactiveJwtDecoder$JwkSetUriReactiveJwtDecoderBuilder.jwsKeySelector(NimbusReactiveJwtDecoder.java:366)

The following method did not exist:

    com.nimbusds.jose.proc.JWSVerificationKeySelector.<init>(Ljava/util/Set;Lcom/nimbusds/jose/jwk/source/JWKSource;)V

The method's class, com.nimbusds.jose.proc.JWSVerificationKeySelector, is available from the following locations:

    jar:file:/Users/eistert/.m2/repository/com/nimbusds/nimbus-jose-jwt/8.16/nimbus-jose-jwt-8.16.jar!/com/nimbusds/jose/proc/JWSVerificationKeySelector.class

The class hierarchy was loaded from the following locations:

    com.nimbusds.jose.proc.JWSVerificationKeySelector: file:/Users/eistert/.m2/repository/com/nimbusds/nimbus-jose-jwt/8.16/nimbus-jose-jwt-8.16.jar
    com.nimbusds.jose.proc.AbstractJWKSelectorWithSource: file:/Users/eistert/.m2/repository/com/nimbusds/nimbus-jose-jwt/8.16/nimbus-jose-jwt-8.16.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.nimbusds.jose.proc.JWSVerificationKeySelector

Disconnected from the target VM, address: '127.0.0.1:49668', transport: 'socket'

意思就是pom.xml里面的依赖包有重复,需要将重复的依赖包删除

我这里的原因是

        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>nimbus-jose-jwt</artifactId>
            <version>8.16</version>
        </dependency>


    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-oauth2-jose</artifactId>
    </dependency>

这两个依赖存在冲突,在最外层排掉排掉这个依赖就可以启动网关了。

        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>nimbus-jose-jwt</artifactId>
            <version>8.16</version>
        </dependency>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你在开发Java应用时,遇到"Correct the classpath of your application to contain a single, compatible version of cn.hutool"这样的错误,意味着你的项目中存在多个不同版本的Hutool库(cn.hutool是一个流行的Java工具包),这可能会导致类加载冲突或找不到正确依赖的问题。 Hutool库的版本不兼容可能会引发运行时错误,因为它们可能有不同的API实现或行为。为了解决这个问题,你需要确保你的应用只包含一个版本的Hutool,通常遵循以下步骤: 1. **检查Maven或Gradle配置**:如果你使用Maven,检查pom.xml文件中的<dependencies>部分,确保没有重复的Hutool依赖。如果是Gradle,检查build.gradle文件中的dependencies块。 2. **排除不必要的依赖**:如果你有多个模块或依赖管理工具(如Gradle的dependencyManagement),移除不需要的Hutool依赖项。 3. **使用范围限定(scope)**:在Maven中,可以通过`<dependency>`元素的`<scope>`标签来指定依赖的使用范围,例如`runtime`或`provided`,确保它们不会被打包到最终的应用JAR中。 4. **使用精确版本号**:当引入Hutool时,指定一个精确的版本号,避免因依赖解析问题引入不同版本。 5. **使用依赖管理工具**:如果项目庞大,可以考虑使用像Gradle的Module Dependency或Maven的Import-Package来管理Hutool的版本。 6. **确认最终发布构建**:在构建应用时,确保所有的依赖都已合并为一个单一版本,并且会在最终的部署中一起打包。 一旦完成这些步骤,你应该就能解决类路径冲突,让你的应用使用单个、兼容的Hutool版本了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值