Java 覆盖默认AutoWiredNotationBeanPostProcessor以停止JSR-330支持

Java 覆盖默认AutoWiredNotationBeanPostProcessor以停止JSR-330支持,java,spring,spring-boot,Java,Spring,Spring Boot,Spring boot auto config支持JSR-330 javax.inject.inject注释(如果在类路径中可用)。我想停止此操作,因为在CDI上使用javax.enterprise.event.event时,它会抛出NPE 之所以这样做是因为Spring auto register 4默认为BeanPostProcessings,而AutowiredAnnotationBeanPostProcessor处理@Autowired和@Value。但也要检查类路径以注册@Inject

Spring boot auto config支持JSR-330 javax.inject.inject注释(如果在类路径中可用)。我想停止此操作,因为在CDI上使用javax.enterprise.event.event时,它会抛出NPE

之所以这样做是因为Spring auto register 4默认为BeanPostProcessings,而AutowiredAnnotationBeanPostProcessor处理@Autowired和@Value。但也要检查类路径以注册@Inject

错误示例:

@Named
@视域
公共类FormMB实现了可序列化{
@注入
私人事件myEvent;
[...]
}
引发异常:

原因:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有javax.enterprise.event.event类型的合格bean可用:至少需要1个符合autowire候选条件的bean。依赖项注释:{@javax.inject.inject()}
深入挖掘,我发现当Spring的
AutoWiredNotationBeanPostProcessor
在类路径中出现时,JSR-330
@Inject
注释作为
AutoWiredNotationTypes
包含。 有没有建议阻止Spring尝试Autowire
@注入注释,或者至少阻止他Autowire
javax.enterprise.event.event
尝试过这个:但没有成功

@SuppressWarnings(“未选中”)
公共AutowiredNotationBeanPostProcessor(){
this.autowiredAnnotationTypes.add(Autowired.class);
this.autowiredNotationTypes.add(Value.class);
试一试{

this.autowiredAnnotationTypes.add((ClassJust exclude
@Named
组件在您的组件扫描中被检测到。或者排除
javax.inject
依赖项,该依赖项也将禁用检测。然而奇怪的是,您会得到一个
NullPointerException
,因为实际上您应该得到一个不可启动的应用程序,因为注入点不能满足。好的,这样做并保持上下文隔离,一个用于JEE事物,另一个用于Spring功能。这样我就可以在
中使用
@Inject
。但是如果我需要在
@组件中使用
@Inject Event
问题仍然存在。有什么建议吗?Spring不会注入
事件
因为它对此一无所知。您可以使用SpringCDI桥接器(有2或3个)让它工作但不确定。在Spring组件中使用CDI事件不是很奇怪吗?只需在组件扫描中排除
@命名的
组件。或者排除
javax.inject
依赖项,该依赖项也将禁用检测。然而奇怪的是,您得到了
NullPointerException
因为实际上你应该得到一个不可启动的应用程序,因为注入点无法满足。好吧,这样做并保持上下文隔离,一个用于JEE,另一个用于Spring功能。这样我就可以在
@Named
内部使用
@Inject
。但是如果我需要在
@Comp内部使用
@Inject Event
OneNet
问题仍然存在。有什么建议吗?Spring不会注入
事件,因为它对此一无所知。您可以通过使用Spring CDI桥接器(有2或3个)让它工作,但不确定。您想在Spring组件中使用CDI事件也不奇怪。。。