Skip to content

[BUG] Using Cosmos Auditing with latest spring boot version 3.1.1 throws Circular references errors #35736

Description

@jsanmarco

Describe the bug
When updating to spring boot 3.1.1 and spring-cloud-azure-starter-data-cosmos 5.3.0 we are seeing errors during application context initialization reporting circular references between CosmosDataAutoConfiguration and CosmosAuditingHandler.

Exception or Stack Trace

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.1)
17:21:20.937 [restartedMain] US-IT01422 INFO  com.lac.entitlements.Application - Starting Application using Java 17.0.7 with PID 75250 (/Users/juan.sanmarco/projects/clippers/entitlements-microservice/build/classes/java/main started by juan.sanmarco in /Users/juan.sanmarco/projects/clippers/entitlements-microservice)
17:21:20.940 [restartedMain] US-IT01422 INFO  com.lac.entitlements.Application - No active profile set, falling back to 1 default profile: "default"
17:21:21.023 [restartedMain] US-IT01422 INFO  o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
17:21:21.023 [restartedMain] US-IT01422 INFO  o.s.b.d.e.DevToolsPropertyDefaultsPostProcessor - For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
17:21:22.066 [restartedMain] US-IT01422 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data cosmos repositories in DEFAULT mode.
17:21:22.080 [restartedMain] US-IT01422 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 10 ms. Found 0 cosmos repository interfaces.
17:21:22.085 [restartedMain] US-IT01422 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data cosmos repositories in DEFAULT mode.
17:21:22.087 [restartedMain] US-IT01422 INFO  o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 1 ms. Found 0 cosmos repository interfaces.
17:21:22.579 [restartedMain] US-IT01422 INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'springCloudAzureGlobalProperties' of type [com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:21:22.869 [restartedMain] US-IT01422 WARN  io.undertow.websockets.jsr - UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
17:21:22.899 [restartedMain] US-IT01422 INFO  io.undertow.servlet - Initializing Spring embedded WebApplicationContext
17:21:22.899 [restartedMain] US-IT01422 INFO  o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1875 ms
17:21:23.029 [restartedMain] US-IT01422 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cosmosAuditingHandler': Cannot resolve reference to bean 'cosmosMappingContext' while setting constructor argument
17:21:23.043 [restartedMain] US-IT01422 INFO  o.s.b.a.l.ConditionEvaluationReportLogger - 
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
17:21:23.063 [restartedMain] US-IT01422 ERROR o.s.b.d.LoggingFailureAnalysisReporter - 
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
|  cosmosAuditingHandler
↑     ↓
|  com.azure.spring.cloud.autoconfigure.implementation.data.cosmos.CosmosDataAutoConfiguration (field private org.springframework.data.auditing.IsNewAwareAuditingHandler com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration.cosmosAuditingHandler)
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
Process finished with exit code 0

To Reproduce
Steps to reproduce the behavior:

Using "@EnableCosmosAuditing" annotation in the Application class causes this error

Code Snippet
Add the code snippet that causes the issue.
Application.java

package com.lac.entitlements;
​
import com.azure.spring.data.cosmos.core.mapping.EnableCosmosAuditing;
import lombok.Generated;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
​
@EnableCosmosAuditing
@EnableAsync
@SpringBootApplication
public class Application {
​
  @Generated
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
​
}```

application.yml
```yaml
server:
  port: 8080
  servlet:
    context-path: /v1/entitlements-service
management:
  server:
    port: 8081
  endpoints:
    web:
      exposure:
        include: "*"
logging:
  pattern:
    console: "%d{HH:mm:ss.SSS} [%t] ${hostName} %-5level %logger{36} - %msg%n"
    file: "%d{HH:mm:ss.SSS} [%t] ${hostName} %-5level %logger{36} - %msg%n"
  level:
    root: info
  file:
    name: logs/entitlements.log
spring:
  application:
    name: entitlements
  cloud:
    azure:
      cosmos:
        database: ${spring.application.name}
        endpoint: ${COSMOS_ACCOUNT_ENDPOINT}
        key: ${COSMOS_ACCOUNT_KEY}
        direct-connection:
          connection-endpoint-rediscovery-enabled: true
        populate-query-metrics: ${COSMOS_QUERY_METRICS:false}
        client-telemetry-enabled: ${COSMOS_TELEMETRY:false}
        endpoint-discovery-enabled: true

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: [e.g. iOS]
  • IDE: [e.g. IntelliJ]
  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]
  • Java version: [e.g. 8]
  • App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special]
  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc]

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context
Add any other context about the problem here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Bug Description Added
  • Repro Steps Added
  • Setup information Added

Metadata

Metadata

Assignees

No one assigned

    Labels

    Azure.Spring - CosmosClientThis issue points to a problem in the data-plane of the library.azure-springAll azure-spring related issuesbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions