daadaadaah / review-study-app

0 stars 0 forks source link

2번째 순환 참조 문제 #83

Open daadaadaah opened 2 months ago

daadaadaah commented 2 months ago

2번째 순환 참조 문제

에러 메시지

Description:

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

   localMethodExecutionTimeLoggingAspect defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/common/aop/LocalMethodExecutionTimeLoggingAspect.class]
┌─────┐
|  discordNotificationService defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/service/notification/DiscordNotificationService.class]
↑     ↓
|  restTemplateHttpClient defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/infrastructure/resttemplate/RestTemplateHttpClient.class]
↑     ↓
|  appConfig defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/common/config/AppConfig.class]
↑     ↓
|  gitHubApiLoggingInterceptor defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/infrastructure/resttemplate/interceptor/GitHubApiLoggingInterceptor.class]
↑     ↓
|  logDirectSaveGoogleSheetsService defined in file [/Users/daheekwak/Desktop/review-study-app/out/production/classes/com/example/review_study_app/service/log/LogDirectSaveGoogleSheetsService.class]
└─────┘

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 1

에러 메시지 해석

문제

문제 원인

해결책 (관련 commit)

daadaadaah commented 2 months ago

2번째 순환 참조 문제 관련 코드

@Autowired
public DiscordNotificationService(
    RestTemplateHttpClient restTemplateHttpClient
) {
    this.restTemplateHttpClient = restTemplateHttpClient;
}
@Autowired
public RestTemplateHttpClient(
   RestTemplate restTemplate
) {
     this.restTemplate = restTemplate;
}

@Configuration
public class AppConfig {

    @Autowired
    public AppConfig(
        GitHubApiLoggingInterceptor gitHubApiLoggingInterceptor
    ) {
        this.gitHubApiLoggingInterceptor = gitHubApiLoggingInterceptor;
    }

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        // ... 생략
        return restTemplate;
    }
}
@Autowired
public GitHubApiLoggingInterceptor(
    LogService logService
) {
    this.logService = logService;
}
@Autowired
public LogDirectSaveGoogleSheetsService(
    NotificationService notificationService
) {
    this.notificationService = notificationService;
}
@Autowired
public DiscordNotificationService(
   RestTemplateHttpClient restTemplateHttpClient
) {
    this.restTemplateHttpClient = restTemplateHttpClient;
}