Skip to content

Cyclic bean definition when a Spring Data repository is a dependency of a MeterBinder #27591

@joshiste

Description

@joshiste

I'm using a MeterBinder as suggested by the docs to register a gauge.
While this worked perfectly fine on Spring Boot 2.4.9 it results in a bean definition cycle with 2.5.3,

Minimal project to reproduce the issue:
https://github.com/joshiste/issues/tree/boot-meterbinder

the dependencies of some of the beans in the application context form a cycle:

┌─────┐
|  service defined in com.example.demo.DemoApplication
↑     ↓
|  usersRepository defined in com.example.demo.UsersRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration
↑     ↓
|  metricsRepositoryMethodInvocationListener defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/data/RepositoryMetricsAutoConfiguration.class]
↑     ↓
|  simpleMeterRegistry defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/simple/SimpleMetricsExportAutoConfiguration.class]
↑     ↓
|  userMetrics defined in com.example.demo.DemoApplication
└─────┘

My Bean definitions:

   @Bean
    UserService service(UsersRepository repsitory) {
        return new UserService(repsitory);
    }

    @Bean
    MeterBinder userMetrics(UserService userService) {
        return registry -> Gauge.builder("user.cout", userService::count);
    }

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions