как заставить прометей webflux r2db c весной работать вместе? Выдает ошибку при попытке запустить актуальный apis из сервиса - PullRequest
0 голосов
/ 06 января 2020

Я генерирую метрики, используя prometheus в spring-boot2, и я использую webflux и r2db c lib для реактивного программирования, однако я не уверен, работают ли они вместе. Пожалуйста, помогите мне понять, что я делаю неправильно.

Это выдает следующую ошибку

java.lang.NoSuchMethodError: org.springframework.transaction.reactive.TransactionSynchronizationManager.currentTransaction()Lreactor/core/publisher/Mono;
    at org.springframework.data.r2dbc.connectionfactory.ConnectionFactoryUtils.doGetConnection(ConnectionFactoryUtils.java:88) ~[spring-data-r2dbc-1.0.0.M2.jar:1.0.0.M2]   at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.data.repository.core.support.MethodInvocationValidator.invoke(MethodInvocationValidator.java:99) ~[spring-data-commons-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at 

Мой build.gradle выглядит так:

 plugins {    
        id("org.springframework.boot") version "2.2.2.RELEASE",
        id ("io.spring.dependency-management") version "1.0.8.RELEASE"
     }
   dependencies {
       implementation ("org.springframework.boot.experimental:spring-boot-starter-r2dbc")
       implementation ("org.springframework.boot.experimental:spring-boot-starter-data-r2dbc")
       implementation ("org.springframework.boot:spring-boot-starter")
       implementation("org.springframework.boot:spring-boot-starter-actuator")
       implementation("io.micrometer:micrometer-registry-prometheus")
       implementation ("org.springframework.boot:spring-boot-starter-webflux")
       testImplementation ("io.projectreactor:reactor-test")
  }

Функция контроллера выглядит как это:

@Timed(histogram = true )
@GetMapping("/abc")
fun process(@PathVariable ab: String): Mono<xyz> {
    return service.getXYZ(xyz)
 }

1 Ответ

0 голосов
/ 06 января 2020

при создании нового проекта с использованием инициализатора пружины он предоставит вам следующие зависимости:

dependencies {
    implementation 'org.springframework.boot.experimental:spring-boot-actuator-autoconfigure-r2dbc'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot.experimental:spring-boot-starter-data-r2dbc'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.boot.experimental:spring-boot-test-autoconfigure-r2dbc'
    testImplementation 'io.projectreactor:reactor-test'
}

Кажется, что вы пропустили spring-boot-actuator-autoconfigure-r2dbc, и вы можете удалить

implementation ("org.springframework.boot.experimental:spring-boot-starter-r2dbc")

Поскольку spring-boot-starter-data-r2dbc извлекает свои транзитивные зависимости.

Поскольку R2DB C все еще является экспериментальным, его автоконфигурация еще не объединена с пружинной загрузкой и должна быть включена отдельно. Я открыл вопрос для разработчиков и попросил, чтобы на данный момент эта часть упоминалась в официальных документах.

...