Refactoring, thread-safety, and DI improvements in EurekaServerInitializerConfiguration

オープン
#4,570 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@alihsan-tsdln がすでに取り組んでいます。

2026年5月21日 から。

  • #4571 @alihsan-tsdln による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
リファクタリング
明瞭さ
説明が足りない
活発さ
静か
技術スタック
java, spring
領域
backend

調査の方向性

EurekaServerInitializerConfiguration を見つけ、start() メソッドとその TODO コメントから始めてください。まず、クラスが引き続き必要かどうか、また提案されている変更のうちどれが対象範囲に含まれるかをメンテナに確認してください。完了は、任意のリファクタリングの全リストではなく、合意済みでテスト可能なサブセットにかかっています。

索引モデルが issue の本文から書いたものです。

説明

waiting-for-triage

Hi team Spring Team,

To open this issue more professionally and cleanly, I used AI to help. Please accept my apologize.

While reviewing the codebase, I came across EurekaServerInitializerConfiguration and noticed a few areas that could benefit from modernization, thread-safety improvements, and consistency.

Before diving into the details, I noticed the inline comment inside the start() method:
// TODO: is this class even needed now?
First and foremost, I wanted to ask if this class is slated for removal or deprecation. If it is going to stay, I would love to submit a PR to clean it up.

Here are the specific points I've identified:

1. Thread Visibility Issue (volatile flag)
The running boolean flag is modified inside a manually created background thread (new Thread(() -> {...}).start()), but it is read by the container via the isRunning() method (likely on a different thread). Currently, it lacks the volatile keyword, which could lead to visibility issues in a concurrent environment.

2. Interface Segregation (Event Publishing)
The class currently autowires the entire ApplicationContext just to publish two events (EurekaRegistryAvailableEvent and EurekaServerStartedEvent). To adhere better to the interface segregation principle, it would be cleaner to inject ApplicationEventPublisher instead of the full context.

3. Dependency Injection Style
The class heavily relies on field injection (@Autowired on fields). Refactoring this to Constructor Injection would make the class immutable, easier to test, and align with current Spring best practices.

4. Inconsistent Injection Mechanisms (Aware Interfaces vs. DI)
The class implements ServletContextAware to obtain the ServletContext, while simultaneously using @Autowired for other framework components like ApplicationContext. In modern Spring, ServletContext can simply be injected via standard dependency injection (preferably Constructor Injection). Removing the Aware interface would standardize the injection mechanism and reduce framework coupling.

5. Raw Thread Creation
Instead of spinning up a raw new Thread(...), it might be safer to utilize a Spring-managed TaskExecutor or ThreadPoolTaskExecutor if asynchronous startup is still strictly required here.

6. Missing Documentation (Javadoc)
The class currently lacks class-level Javadoc explaining its primary role within the Eureka lifecycle, which makes it harder for new contributors to understand its context.

Proposal

If you agree that this class is still needed, I am more than happy to draft a PR to:

  • Add volatile to the running flag.
  • (Optional, based on your feedback) Refactor all field injections and ServletContextAware into a single Constructor Injection block.
  • Replace ApplicationContext with ApplicationEventPublisher.
  • Add descriptive Javadoc to clarify the component's role and lifecycle.
  • (Optional, based on your feedback) Refactor the raw thread creation.

I'm looking forward to contributing to this fix and would love to help out with similar tech-debt/refactoring tasks across the repository in the future.

Let me know your thoughts. Thank You

主要言語
Java
スター
5k
フォーク
2.5k
平均マージ
2日 9時間
マージ済み PR(30日)
11

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

spring-cloud/spring-cloud-netflix のほかの issue

spring-cloud/spring-cloud-netflix の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。