- JBoss Weld CDI for Java Platform
- Ken Finnegan
- 298字
- 2021-08-13 16:49:55
Resolving Weld deployment errors
Weld will abort the deployment of our application and provide helpful error messages in the server log, when it's unable to identify a single bean for each injection point with typesafe resolution. We would expect to see one or more of unsatisfied or ambiguous dependency errors in this situation.
An unsatisfied dependency occurs when there is not a single bean that is eligible for injection into an injection point. This can be resolved as follows:
- By creating a bean that implements the bean type of the injection point and declares all the qualifier annotations present at the injection point
- If we already have a bean of the correct bean type and all the qualifier annotations in our application, check whether the bean is on the classpath of the bean archive that contains the injection point with the error
- With
beans.xml
, enable an@Alternative
bean of the correct bean type and qualifier annotations
An ambiguous dependency occurs when there is more than a single bean eligible for injection into an injection point. This can be resolved with the help of the following steps:
- Add a new
@Qualifier
to disambiguate between the bean implementations that are eligible for injection. - Mark all but one of the bean implementations with
@Alternative
, thus disabling them by default. - Relocate the bean implementations into a separate bean archive that is not on the classpath of the injection point.
- With
beans.xml
, disable all but one@Alternative
bean that are eligible for injection to that injection point.
Note
There may be occasions where we do legitimately have an injection point with multiple beans that are eligible. In this instance, we need to use Instance
as the bean type of the injection point. We will cover this in the last section of this chapter.
- MySQL數據庫管理實戰
- Mastering JavaScript Functional Programming
- Python數據分析基礎
- Maven Build Customization
- 零基礎玩轉區塊鏈
- ASP.NET Core 2 and Vue.js
- Selenium Design Patterns and Best Practices
- 深入理解Java7:核心技術與最佳實踐
- 零基礎學MQL:基于EA的自動化交易編程
- INSTANT Django 1.5 Application Development Starter
- 精通Python設計模式(第2版)
- 硅谷Python工程師面試指南:數據結構、算法與系統設計
- Mastering Android Game Development
- Apache Solr PHP Integration
- Access數據庫應用教程(2010版)