在CDI实现项目中包含空beans.xml的目的是什么? [英] what is the purpose of including empty beans.xml in CDI implemenations projects?

查看:145
本文介绍了在CDI实现项目中包含空beans.xml的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的JSF-EJB-JPA Web应用程序中使用 weld ,一个CDI的RI作为依赖注入组件。我在项目中看到我们在 META-INF / beans.xml 中的 ejb.jar 中有空beans.xml,我的WAR中的 WEB-INF / beans.xml 。我不明白为什么我们需要保留空 beans.xml 当该文件中没有定义任何内容时?

I am using weld,a RI of CDI as dependency injection component in my JSF-EJB-JPA web app. I see in my project we have empty beans.xml in META-INF/beans.xml in ejb.jar and WEB-INF/beans.xml in my WAR. I don't get it why we need to keep empty beans.xml when there nothing defined in that file?

推荐答案

CDI需要在启动时扫描bean存档的所有类并触发一堆事件,因为几乎任何类都自动成为托管bean(阅读更多这里),即使它没有有任何注释。

CDI needs to scan all the classes of a bean archive at start-up and fire a bunch of events because almost any class is automatically a managed bean (read more here), even if it doesn't have any annotations.

这会产生相当多的开销,特别是对于那些没有任何bean的jar文件,因此明确指出哪个是有益的应该通过包含 beans.xml 来扫描bean归档。

This would incur quite a bit of overhead, especially for jar files that are not meant to have any beans, and it is therefore beneficial to explicitly indicate which bean archives should be scanned by including the beans.xml.

这篇关于在CDI实现项目中包含空beans.xml的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆