Java EE 7 教程 第二部分 平台基础 第4章 注入

原文:https://docs.oracle.com/javaee/7/tutorial/injection.htm
翻译:石卓林 shizhuolin@hotmail.com

4 Injection

This chapter provides an overview of injection in Java EE and describes the two injection mechanisms provided by the platform: resource injection and dependency injection.

Java EE provides injection mechanisms that enable your objects to obtain references to resources and other dependencies without having to instantiate them directly. You declare the required resources and other dependencies in your classes by decorating fields or methods with one of the annotations that mark the field as an injection point. The container then provides the required instances at runtime. Injection simplifies your code and decouples it from the implementations of its dependencies.

The following topics are addressed here:

4 注入

本章概述了Java EE中的注入并介绍平台提供的两种注入机制: 资源注入和依赖注入.

Java EE提供注入机制使对象获取引用资源和其它依赖项且无须直接实例化它们. 在类中通过修饰字段或方法注解声明需求资源和其它依赖项, 标记其为注入点.容器在运行时提供需求的实例. 使用注入可简化代码并解耦它的依赖项和其实现.

以下的是话题地址:

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.

Proudly powered by WordPress   Premium Style Theme by www.gopiplus.com
渝公网安渝公网安备 50010702500270号 渝ICP备09056628号-7