question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Circular references about restTemplateBuilder

See original GitHub issue

Describe the bug A Spring Boot 2.7.4 application having dependencies on both spring-boot-starter-data-rest and spring-cloud-azure-starter-active-directory 4.4.0 fails to start due to circular references. Using spring-cloud-azure-starter-active-directory 4.3.0 works fine.

Exception or Stack Trace

***************************
APPLICATION FAILED TO START
***************************

Description:

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

   com.azure.spring.cloud.autoconfigure.aad.AadAuthenticationFilterAutoConfiguration
┌─────┐
|  restTemplateBuilder defined in class path resource [org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.class]
↑     ↓
|  restTemplateBuilderConfigurer defined in class path resource [org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.class]
↑     ↓
|  messageConverters defined in class path resource [org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.class]
↑     ↓
|  jacksonHttpMessageConverter defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]
↑     ↓
|  linkCollector defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]
↑     ↓
|  selfLinkProvider defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]
↑     ↓
|  org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration
↑     ↓
|  org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration
↑     ↓
|  com.azure.spring.cloud.autoconfigure.aad.configuration.AadOAuth2ClientConfiguration
└─────┘


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 Create a new Spring Boot project at https://start.spring.io/ and select the following dependencies:

  • Rest Repositories
  • Azure Active Directory
  • Spring Security
  • OAuth2 Client image

Then enable AAD in the application.yaml file:

spring:
  cloud:
    azure:
      active-directory:
        enabled: true
        credential:
          client-id: whatever
          client-secret: whatever
        profile:
          tenant-id: whatever
        user-group:
          allowed-group-names: whatever

Code Snippet N/A

Expected behavior The Spring Boot application starts (and immediately terminates because it’s not a web application) without error.

Screenshots N/A

Setup (please complete the following information):

  • OS: Windows
  • IDE: IntelliJ
  • Library/Libraries:
  • org.springframework.boot:spring-boot-starter-data-rest:2.7.4
  • org.springframework.boot:spring-boot-starter-oauth2-client:2.7.4
  • org.springframework.boot:spring-boot-starter-security:2.7.4
  • com.azure.spring:spring-cloud-azure-starter-active-directory:4.4.0
  • Java version: 11
  • App Server/Environment: N/A
  • Frameworks: Spring Boot 2.7.4

Additional context This could be related to https://github.com/Azure/azure-sdk-for-java/pull/31048 Downgrading to com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 solves the problem. Removing the org.springframework.boot:spring-boot-starter-data-rest dependency also “solves” the problem.

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
chenrujuncommented, Oct 17, 2022

Hi, @sigiswald, thanks for reaching out. I’ll investigate this issue and give feedback ASAP.

1reaction
fangjian0423commented, Nov 25, 2022

@saragluna could you please take a look at this issue, thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular Dependency in Spring Boot - Stack Overflow
I'm trying to use restTemplate in my bootspring project, when i compile giving me error like this:
Read more >
Circular Dependencies in Spring - Baeldung
A quick writeup on dealing with circular dependencies in Spring: how they occur and several ways to work around them.
Read more >
Spring Boot Reference Documentation
Try the How-to documents. They provide solutions to the most common questions. Learn the Spring basics. Spring Boot builds on many other Spring...
Read more >
[hawkbit-dev] Trouble with hawkbit-repository-jpa - Eclipse
This application has no explicit mapping for /error, so you are ... for resolving potential circular references 2018-01-25 10:38:49.922 INFO ...
Read more >
spring-projects/spring-boot - Gitter
How would I make an error handler available to be added by this method? ... bean is currently in creation: Is there an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found