官术网_书友最值得收藏!

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:

  1. Add a new @Qualifier to disambiguate between the bean implementations that are eligible for injection.
  2. Mark all but one of the bean implementations with @Alternative, thus disabling them by default.
  3. Relocate the bean implementations into a separate bean archive that is not on the classpath of the injection point.
  4. 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.

主站蜘蛛池模板: 绥棱县| 南宫市| 夏津县| 禹州市| 西乌珠穆沁旗| 谢通门县| 华坪县| 招远市| 上蔡县| 勃利县| 垫江县| 通州市| 长沙市| 普兰店市| 碌曲县| 东港市| 武宁县| 富平县| 塔河县| 莱阳市| 铜川市| 清新县| 皋兰县| 斗六市| 平陆县| 黑山县| 武安市| 通榆县| 来凤县| 宜昌市| 定陶县| 巴东县| 九江县| 陵川县| 河曲县| 顺义区| 扎囊县| 嘉兴市| 乌审旗| 北辰区| 越西县|