我学习Java EE有一段时间了,发现Java EE提供了两种注入(inject)机制
- 资源注入(inject)
- 依赖注入(inject)
请指导我理解资源注入(inject)和依赖注入(inject)之间的区别。
最佳答案
来自 source :
Resource injection enables you to inject any resource available in the JNDI namespace into any container-managed object, such as a servlet, an enterprise bean, or a managed bean. For eg, we can use resource injection to inject data sources, connectors, or any other desired resources available in the JNDI namespace.
Dependency injection enables us to turn regular Java classes into managed objects and to inject them into any other managed object (objects wich are managed by the container).
Difference between Resource Injection and Dependency Injection The differences between the RI and DI are listed below.
Resource Injection can inject JNDI Resources directly whereas Dependency Injection cannot.
Dependency Injection can inject Regular Classes (managed bean) directly whereas Resource Injection cannot.
Resource Injection resolves by resource name whereas Dependency Injectin resolves by type.
Dependency Injection is typesafe whereas Resoiurce Injection is not.
关于java - Java中的资源注入(inject)和依赖注入(inject)(CDI)有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30060876/