EJB 和 CDI 在@FacesValidator 和@FacesConverter 中的注入点无法通过较新版本的 JSF 中的 OmniFaces 工作
EJB and CDI inject points in @FacesValidator and @FacesConverter fail to work by means of OmniFaces in newer versions of JSF
我正在使用,
- Mojarra 2.3.0-m01
- OmniFaces 2.0.
- PrimeFaces 5.1 最终版本
- PrimeFaces 扩展 3.0.0
- GlassFish 服务器 4.1
和其他 Java EE 工件。
@FacesValidator
中的注入点如下,
@FacesValidator(value="testValidator")
public class TestValidator implements Validator {
@Inject
private DemoEJB ejb;
@Inject
private ManagedBean managedBean;
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
// Use the injected EJB and/or managed bean here.
}
}
那些注入点仍然存在 null
(我没有明确尝试注入 EJB,但它不应该像托管 bean 那样发生)。
由于 above-mentioned Mojarra 版本仍可作为快照使用,我尝试使用相同版本的 OmniFaces 将其降级到 2.2.10,即 2.0(或者也尝试使用 OmniFaces 2.1-SNAPSHOT - 在两者上Mojarra 2.2.10 和 2.3.0-m01 交替使用)但无济于事。
当我将 Majarra 降级到 2.2.8-02 时(尝试使用 OmniFaces 1.8.1、2.0 和 2.1-SNAPSHOT 交替使用),这有效。我没有尝试其他 Mojarra 版本。
是否支持通过 OmniFaces 为 EJB 和 CDI 注入点创建 @FacesValidator
和 @FacesConverter
候选对象(这反过来不需要任何附加依赖项 and/or 配置)已删除更新版本的 Mojarra?
我还没有在 @FacesConverter
中明确尝试过,只是因为使用有问题的 NetBeans IDE 交替地更改了这么多库,这在 [=57] 上也很慢=] 从天亮到 dusk.
天生就花了一整天
编辑:
服务器产生以下与焊接相关的警告。
WARN: WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
WARN: WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ApplicationProducer@b15a70 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ApplicationMapProducer@db0450 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ViewMapProducer@1c55365 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ExternalContextProducer@14b1a6 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.FacesContextProducer@1048acb declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ViewProducer@275cfa declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
这是由 Mojarra 2.2.9 中的更改引起的。它在 2.2.8 中运行良好。我在 GlassFish 4.1 和 WildFly 8.2 中都复制了它。将 2.2.9 release notes and the associated change bundles, it appears to be the consequence of backport of issue 3552 中列出的所有问题扫描到 JSF 2.2.x 后。他们在内部禁用检查组件、行为、验证器和转换器的可注入性,这些组件、行为、验证器和转换器隐式地将它们注册为 CDI 托管 bean 候选者。换句话说,在 2.2.x 到 2.2.9 期间,Mojarra 无意中提供了对上述工件的 "native" @Inject
支持。
为了通过 OmniFaces 在 @FacesConverter
和 @FacesValidator
中进行注入,您需要添加一个空 /WEB-INF/beans.xml
或至少一个 bean-discovery-mode
集all
而不是 annotated
.
<?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"
xmlns:weld="http://jboss.org/schema/weld/beans"
bean-discovery-mode="all"
>
<!-- ... -->
</beans>
它已经是默认值,您也可以省略 bean-discovery-mode
属性。
技术上的区别在于bean-discovery-mode="all"
会将所有符合条件的类注册为CDI托管bean,而bean-discovery-mode="annotated"
只注册类 带有显式 CDI 范围注释,例如 @RequestScoped
作为 CDI 管理的 bean,因此对于 @FacesConverter
和 @FacesValidator
.
会失败
我正在使用,
- Mojarra 2.3.0-m01
- OmniFaces 2.0.
- PrimeFaces 5.1 最终版本
- PrimeFaces 扩展 3.0.0
- GlassFish 服务器 4.1
和其他 Java EE 工件。
@FacesValidator
中的注入点如下,
@FacesValidator(value="testValidator")
public class TestValidator implements Validator {
@Inject
private DemoEJB ejb;
@Inject
private ManagedBean managedBean;
@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
// Use the injected EJB and/or managed bean here.
}
}
那些注入点仍然存在 null
(我没有明确尝试注入 EJB,但它不应该像托管 bean 那样发生)。
由于 above-mentioned Mojarra 版本仍可作为快照使用,我尝试使用相同版本的 OmniFaces 将其降级到 2.2.10,即 2.0(或者也尝试使用 OmniFaces 2.1-SNAPSHOT - 在两者上Mojarra 2.2.10 和 2.3.0-m01 交替使用)但无济于事。
当我将 Majarra 降级到 2.2.8-02 时(尝试使用 OmniFaces 1.8.1、2.0 和 2.1-SNAPSHOT 交替使用),这有效。我没有尝试其他 Mojarra 版本。
是否支持通过 OmniFaces 为 EJB 和 CDI 注入点创建 @FacesValidator
和 @FacesConverter
候选对象(这反过来不需要任何附加依赖项 and/or 配置)已删除更新版本的 Mojarra?
我还没有在 @FacesConverter
中明确尝试过,只是因为使用有问题的 NetBeans IDE 交替地更改了这么多库,这在 [=57] 上也很慢=] 从天亮到 dusk.
编辑:
服务器产生以下与焊接相关的警告。
WARN: WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
WARN: WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.omnifaces.VetoAnnotatedTypeExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.gf.cdi.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ApplicationProducer@b15a70 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ApplicationMapProducer@db0450 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ViewMapProducer@1c55365 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ExternalContextProducer@14b1a6 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.FacesContextProducer@1048acb declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
WARN: WELD-001473: javax.enterprise.inject.spi.Bean implementation com.sun.faces.cdi.ViewProducer@275cfa declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with a passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.
这是由 Mojarra 2.2.9 中的更改引起的。它在 2.2.8 中运行良好。我在 GlassFish 4.1 和 WildFly 8.2 中都复制了它。将 2.2.9 release notes and the associated change bundles, it appears to be the consequence of backport of issue 3552 中列出的所有问题扫描到 JSF 2.2.x 后。他们在内部禁用检查组件、行为、验证器和转换器的可注入性,这些组件、行为、验证器和转换器隐式地将它们注册为 CDI 托管 bean 候选者。换句话说,在 2.2.x 到 2.2.9 期间,Mojarra 无意中提供了对上述工件的 "native" @Inject
支持。
为了通过 OmniFaces 在 @FacesConverter
和 @FacesValidator
中进行注入,您需要添加一个空 /WEB-INF/beans.xml
或至少一个 bean-discovery-mode
集all
而不是 annotated
.
<?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"
xmlns:weld="http://jboss.org/schema/weld/beans"
bean-discovery-mode="all"
>
<!-- ... -->
</beans>
它已经是默认值,您也可以省略 bean-discovery-mode
属性。
技术上的区别在于bean-discovery-mode="all"
会将所有符合条件的类注册为CDI托管bean,而bean-discovery-mode="annotated"
只注册类 带有显式 CDI 范围注释,例如 @RequestScoped
作为 CDI 管理的 bean,因此对于 @FacesConverter
和 @FacesValidator
.