1

I am generating metrics using prometheus in spring-boot2 and I am using webflux and r2dbc lib for reactive programming, however I am not sure if these works together. Please help me to understand what i am doing wrong.

It gives following error

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 

My build.gradle looks like this:

 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")
  }

Controller function look like this:

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

1 回答 1

0

使用 spring 初始化程序生成新项目时,它将为您提供以下依赖项:

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将引入其传递依赖关系。

由于 R2DBC 仍处于试验阶段,其自动配置尚未合并到 Spring Boot 中,必须单独包含。我已经向开发人员提出了一个问题,并要求到目前为止这部分应该在官方文档中提及。

于 2020-01-06T03:33:11.073 回答