Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]Using Cosmos Auditing with latest spring boot version 2.6.1 throws Circular dependency errors #25755

Closed
3 tasks
Tracked by #25581
svankamamidi1 opened this issue Nov 30, 2021 · 6 comments
Assignees
Labels
azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. dependency-issue Issue that is caused by dependency conflicts needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@svankamamidi1
Copy link

Describe the bug
In order to resolve some security vulnerabilities from spring, we have upgraded to latest spring boot version 2.6.1 and we saw errors during application context initialization reporting circular dependencies between cosmosClient and CosmosAuditingHandler.

Exception or Stack Trace
Add the exception log and stack trace if available

2021-11-30 12:02:46.010 INFO 2764 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6148 ms
2021-11-30 12:02:46.897 WARN 2764 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cosmosHealthIndicatorConfig': Unsatisfied dependency expressed through field 'cosmosClient'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cosmosClientConfig': Unsatisfied dependency expressed through field 'cosmosAuditingHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cosmosAuditingHandler': Cannot create inner bean '(inner bean)#3d1cfad4' of type [com.azure.spring.data.cosmos.core.mapping.CosmosAuditingRegistrar$CosmosMappingContextLookup] while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#3d1cfad4': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'cosmosClientConfig': Requested bean is currently in creation: Is there an unresolvable circular reference?
2021-11-30 12:02:46.908 INFO 2764 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2021-11-30 12:02:46.971 INFO 2764 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-11-30 12:02:47.107 ERROR 2764 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

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

cosmosHealthIndicatorConfig (field private com.azure.cosmos.CosmosAsyncClient com.nuance.powershare.messaging.config.health.CosmosHealthIndicatorConfig.cosmosClient)
┌─────┐
| cosmosClientConfig (field private org.springframework.data.auditing.IsNewAwareAuditingHandler com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration.cosmosAuditingHandler)
↑ ↓
| cosmosAuditingHandler
↑ ↓
| (inner bean)#3d1cfad4
└─────┘

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.

To Reproduce
Steps to reproduce the behavior:

Using "@EnableCosmosAuditing" annotation on the AppConfiguration has circular dependencies and the latest spring boot doesn't allow that.

Code Snippet
Add the code snippet that causes the issue.

Here is our configuration class code:

@configuration
@EnableConfigurationProperties(CosmosProperties.class)
@EnableCosmosRepositories(basePackages = "com.nuance.powershare.messaging.repository.cosmos")
@EnableCosmosAuditing
public class CosmosClientConfig extends AbstractCosmosConfiguration {

@Autowired
private CosmosProperties properties;

@Override
public CosmosConfig cosmosConfig() {
    CosmosConfigBuilder cosmosConfigBuilder =
                    CosmosConfig.builder().enableQueryMetrics(properties.isQueryMetricsEnabled());

    if (properties.isLogResponseDiagnostics()) {
        cosmosConfigBuilder.responseDiagnosticsProcessor(new ResponseDiagnosticsProcessorImpl());
    }

    return cosmosConfigBuilder.build();
}

/**
 * @return cosmos db client builder
 */
@Bean
@DependsOn("expressionResolver")
public CosmosClientBuilder cosmosClientBuilder() {
    CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder();
    cosmosClientBuilder.endpoint(properties.getEndpoint()).credential(azureKeyCredential()).directMode();
    return cosmosClientBuilder;
}

/**
 * @return credential to connect cosmos db
 */
@Bean
public AzureKeyCredential azureKeyCredential() {
    return new AzureKeyCredential(properties.getKey());
}

@Override
protected String getDatabaseName() {
    return properties.getDatabase();
}

private static class ResponseDiagnosticsProcessorImpl implements ResponseDiagnosticsProcessor {

    private static final Logger LOG = LoggerFactory.getLogger(ResponseDiagnosticsProcessorImpl.class);
    private static final String NOT_AVAILABLE = "Not Available";

	@Override
	public void processResponseDiagnostics(final ResponseDiagnostics responseDiagnostics) {
		if (responseDiagnostics != null) {
			LOG.trace("{}", responseDiagnostics.getCosmosDiagnostics());
		}
	}
}

@Override
protected Collection<String> getMappingBasePackages() {
    return Collections.singletonList("xxx");
}

}

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] Eclipse
  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)] azure-spring-data-cosmos v3.14.0
  • Java version: [e.g. 8] 8
  • App Server/Environment: [e.g. Tomcat, WildFly, Azure Function, Apache Spark, Databricks, IDE plugin or anything special] Tomcat
  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc] Spring Boot

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please provide

  • verbose dependency tree (mvn dependency:tree -Dverbose)

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
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Nov 30, 2021
@joshfree joshfree added azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. dependency-issue Issue that is caused by dependency conflicts labels Nov 30, 2021
@ghost ghost added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Nov 30, 2021
@joshfree
Copy link
Member

@backwind1233 could you please follow up with @svankamamidi1?

@backwind1233
Copy link
Contributor

backwind1233 commented Dec 1, 2021

@samvaity Thanks for reaching us, I can reproduce your issue,
as you can see in the changelog,
image

I think the spring boot 2.6.1 is not compatible with azure-spring-data-cosmos v3.14.0;
Hi @kushagraThapar, could you please look into this issue?

@saragluna
Copy link
Member

saragluna commented Dec 1, 2021

@backwind1233 we need to make sure whether this will block our Spring Cloud Azure 4.0 GA since we're targeting Spring Boot 2.6.

@backwind1233 backwind1233 self-assigned this Dec 1, 2021
@backwind1233
Copy link
Contributor

@backwind1233 we need to make sure whether this will block our Spring Cloud Azure 4.0 GA since we're targeting Spring Boot 2.6.

@saragluna I will check and handle this.

@kushagraThapar
Copy link
Member

@backwind1233 @saragluna @svankamamidi1 - We don't support Spring Boot 2.6.x currently with azure-spring-data-cosmos SDK - This is work in progress on this PR - #25626

Once we upgrade to spring boot 2.6.x, then we should be good.
@svankamamidi1 - please check back in few weeks for updates on support of spring boot 2.6.x

@xinlian12
Copy link
Member

PR has merged and the fix will be released by the end of this week.

Repository owner moved this from Todo to Done in Spring Cloud Azure Dec 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
azure-spring All azure-spring related issues azure-spring-cosmos Spring cosmos related issues. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. dependency-issue Issue that is caused by dependency conflicts needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Archived in project
Development

No branches or pull requests

7 participants