how to make spring data lib compatiable in spring boot 2.x?

佐手、 提交于 2021-01-28 11:00:46

问题


when I run my app using:

java -jar soa-happy-rain-service-1.0.0-SNAPSHOT.jar

throw this error:

 :: Spring Boot ::        (v2.2.2.RELEASE)

2020-01-02 21:20:52.817  INFO [soa-happy-rain-service,,,] 994 --- [           main] com.sportswin.soa.happy.rain.AppStarter  : No active profile set, falling back to default profiles: default
2020-01-02 21:20:55.478 ERROR [soa-happy-rain-service,,,] 994 --- [           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.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$AutoConfiguredAnnotationRepositoryConfigurationSource.<init>(AbstractRepositoryConfigurationSourceSupport.java:128)

The following method did not exist:

    org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Lorg/springframework/beans/factory/support/BeanNameGenerator;)V

The method's class, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource, is available from the following locations:

    jar:file:/Users/dolphin/source/dabai/microservice/soa-happy-rain/soa-happy-rain-service/build/libs/soa-happy-rain-service-1.0.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-data-commons-2.1.6.RELEASE.jar!/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSource.class

It was loaded from the following location:

    jar:file:/Users/dolphin/source/dabai/microservice/soa-happy-rain/soa-happy-rain-service/build/libs/soa-happy-rain-service-1.0.0-SNAPSHOT.jar!/BOOT-INF/lib/spring-data-commons-2.1.6.RELEASE.jar!/


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource

my gradle(6.0) config like this:

id "org.springframework.boot" version "2.2.2.RELEASE"
apply plugin: 'org.springframework.boot'


implementation "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
       implementation "org.springframework.boot:spring-boot-starter-web"
        implementation "org.springframework.boot:spring-boot-starter-data-redis"
        implementation "org.springframework.boot:spring-boot-starter-cache"
        implementation "org.springframework:spring-aspects:${springVersion}"
        implementation "org.springframework:springloaded:1.2.8.RELEASE"
        implementation "org.springframework.boot:spring-boot-starter-test"
        implementation "org.springframework:spring-test:${springVersion}"
        implementation "org.springframework.boot:spring-boot-starter-actuator"

I am already using plugin to manage the dependencies.How to find out where is gong wrong? what should I do to fix this.This is my project build command:

gradle build -x test


回答1:


You have a mixture of dependencies managed by Spring Boot and dependencies you are explicitly managing. This may be causing the conflict, so try the following:

implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-data-redis"
implementation "org.springframework.boot:spring-boot-starter-cache"
implementation "org.springframework.boot:spring-boot-starter-aop"
implementation "org.springframework.boot:spring-boot-starter-actuator"
implementation "org.springframework.boot:spring-boot-starter-test"

Use the starters as much as possible unless you have a reason to include individual Spring dependencies.

Additionally, the org.springframework:springloaded was moved to the "attic":

  • https://spring.io/projects (bottom of page)
  • https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#hot-swapping

Use the spring-boot-devtools instead: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools`



来源:https://stackoverflow.com/questions/59564275/how-to-make-spring-data-lib-compatiable-in-spring-boot-2-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!