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 3 years have passed since last update.

WELD-001408: Unsatisfied dependencies for type ClassName with qualifiers

Last updated at Posted at 2020-08-25

事象 : Unsatisfied dependencies for type HogeServiceMock with qualifiers @Mock

  • 環境
    • Windows10 64bit バージョン1909
    • openjdk 11 2018-09-25
    • Eclipse IDE for Enterprise Java Developers Version: 2020-03 (4.15.0)
    • JSF 2.3.9
Payaraを起動したらエラーで起動できなかった
2020-07-17T10:21:26.264+0900|重大: Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException: CDI deployment failure:WELD-001408: Unsatisfied dependencies for type HogeServiceMock with qualifiers @Mock
  at injection point [BackedAnnotatedField] @Inject @Mock private com.example.project.service.factory.HogeServiceFactory.serviceMock
  at com.example.project.service.factory.HogeServiceFactory.serviceMock(HogeServiceFactory.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
  - Managed Bean [class com.example.project.service.mock.HogeServiceMock] with qualifiers [@Any @Default]
 -- WELD-001408: Unsatisfied dependencies for type HogeServiceMock with qualifiers @Mock

原因 : アノテーションがないから

HogeServiceMock
/** Hogeサービス実装クラス(Mock). */
public class HogeServiceMock extends BaseServiceMock implements Serializable, HogeService {
HogeServiceFactory
/** HogeサービスFactory. */
@ApplicationScoped
public class HogeServiceFactory extends BaseFactory<HogeServiceMock, HogeServiceImpl> {

対応 : アノテーションをつける

/** Hogeサービス実装クラス(Mock). */
@Mock
@ApplicationScoped
public class HogeServiceMock extends BaseServiceMock implements Serializable, HogeService {

事象 : Unsatisfied dependencies for type HogeBean with qualifiers @Default

  • 環境
    • Windows10 64bit バージョン1909
    • openjdk 11 2018-09-25
    • Eclipse IDE for Enterprise Java Developers Version: 2020-03 (4.15.0)
    • JSF 2.3.9
ダイアログのエラー
cannot Deploy app-name
deploy is failing=Error occurred during deployment:
 Exception while loading the app :
 CDI deployment failure:WELD-001408:
 Unsatisfied dependencies for type HogeBean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private jp.co.ç.bean
  at jp.co.ponsuke.HogeController.bean(HogeController.java:0)
 -- WELD-001408: Unsatisfied dependencies for type HogeBean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject private jp.co.ponsuke.HogeController.bean
  at jp.co.ponsuke.HogeController.bean(HogeController.java:0).
 Please see server.log for more details.

原因 : CDIにBeanとして認識してもらえていないオブジェクトに@Injectをつけているから

CDIでインジェクトするクラスは、何らかのスコープアノテーションを付けねばなりません。
わかりやすいJava EE ウェブシステム入門 - 秀和システム

HogeController.java
    /** 表示用bean. */
    @Getter
    @Inject
    private HogeBean bean;

スコープアノテーションもない・・・
Serializableインターフェースも実装していない・・・

HogeBean.java
import lombok.Builder;
import lombok.Value;

@Value
@Builder
public class HogeBean {
    @NonNull
    Integer fileSize;

    @NonNull
    String extensions;
}

対応 : @Injectを削除する

そもそも付けなくても良かったので削除する。

HogeController.java
    /** 表示用bean. */
    @Getter
    private HogeBean bean;

他の対応方法

いつかのために・・・@Modelをつけたりbeans.xmlに書いたりしても対応できるらしい。
jsf - WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default - Stack Overflow

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?