0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Spring Boot でコンポーネント自身のプロキシインスタンスを取得する

Posted at

前提

RequestScopeなどがついたコンポーネントから、(手を出せないところで同値チェックされているという理由で)プロキシのほうを保持したクラスを返す必要があった。

解決方法

こんなんでよかったのかわからないが、自分自身をAutowiredして実現できた。

@Component
@RequestScope
public class Hoge {
  private final Hoge proxyInstance;
  @AutoWired
  public(Hoge proxyInstance) {
    if (!(proxyInstance instanceof ScopedObject)) {
      throw new IllegalArgumentException("プロキシを渡して");
    }
    this.proxyInstance = proxyInstance;
  }

  public Fuga getFuga() {
    return new Fuga(proxyInstance);
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?