J2EE WITHOUT EJB Reading Notes - Light Weight Container & Ioc

zhaozj2021-02-16  83

The services that should be provided by the container include: 1. Lifecycle Management 2. Find: Find references for managed objects 3. Configuration: Use consistent ways to configure managed objects 4. Dependent parsing:

There are two strategies for IOC: 1. Dependency lookup: Traditional method similar to JNDI 2. Dependent Injection: The method of using JavaBean Property is called SETTER injection or TYPE 2, which is injected with the constructor parameters or TYPE 3.

Setter Injection: The SETTER method of JavaBean is executed immediately after the object instance is constructed by the container, and before any business method calls. It works well for the object with default values, meaningless to provide all of the Properties. Setter There is no contract to express it, not all must be called before use, so objects may only be partially configured. (Spring can avoid this) Construction Injection: Constructor receives incoming parameters, and Assigning its Property. Each managed object can be guaranteed to be fully configured. You cannot support the existing valuable legacy code, such as the COMMONS DBCP. After the collaboration parameters are incompatible and initialize the member variable, it cannot change the object. These references.

转载请注明原文地址:https://www.9cbs.com/read-12406.html

New Post(0)