【发布时间】:2014-07-16 21:19:57
【问题描述】:
我的问题不同于WELD-001408 Unsatisfied dependencies when injecting EntityManager 和WELD-001408 Unsatisfied dependencies。虽然这些问题涉及尝试将托管 bean 注入到无状态 EJB 中,但我正试图做相反的事情。
尝试将@Stateless @Local 接口 bean 注入 Web 托管 bean 时,我得到一个“不满意的依赖项”。我正在构建一个带有各种 EJB 模块和一个 Web 模块的 EAR,在 JDK 8 上运行 Glassfish 4 build 89。以下是错误和项目配置的详细信息。
首先,这是错误:
SEVERE: Exception while loading the app
SEVERE: Undeployment failed for context /platform-app
SEVERE: Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [SessionSettingsBeanLocal] with qualifiers [@MyClient] at injection point [[BackedAnnotatedField] @Inject @MyClient private com.comp.jsf.dropdown.Settings.settingsBean]
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [SessionSettingsBeanLocal] with qualifiers [@MyClient] at injection point [[BackedAnnotatedField] @Inject @MyClient private com.comp.jsf.dropdown.Settings.settingsBean]
自定义限定符(在库项目中):
@Documented
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
public @interface MyClient
EJB 接口(在库项目中):
@Local
public interface SessionSettingsBeanLocal
EJB 实现(在 EJB 模块项目中):
@Stateless
@MyClient
public class SessionSettingsBean implements SessionSettingsBeanLocal
托管 bean(在 Web 项目中 - 用于 JSF):
@Named
@javax.faces.view.ViewScoped
public class Settings implements Serializable {
@Inject
@MyClient
private SessionSettingsBeanLocal settingsBean;
最后,我的所有 beans.xml 文件(EJB 模块、Web)如下所示。包含接口和限定符的库没有 beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">
</beans>
@Stateless EJB 应该注册自己,但没有找到。
【问题讨论】:
-
为什么要混合自定义 CDI 限定符和 EJB?
-
我对 GF 3.1 中的这个确切的东西没有任何问题。我使用限定符是因为我有多个 bean 实现相同的 @Local 接口。
-
我不认为这是要走的路。您应该使用 EJB 3.0 通过字符串消除歧义,而不是 CDI 限定符。
-
在这里。非常好的 EJB 3.0 消歧示例:oracle.com/technetwork/articles/java/…
标签: jakarta-ee ejb cdi glassfish-4 java-ee-7