C1 - Core Technologies
C1 - Core Technologies
C1 - Core Technologies
Dependency injection (DI) is a specialized form of IoC, whereby objects define their dependencies (that is, the ot
or properties that are set on the object instance after it is constructed or returned from a factory method.
The IoC container then injects those dependencies when it creates the bean. This process is fundamentally the i
using direct construction of classes or a mechanism such as the Service Locator pattern.
The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s
- The BeanFactory interface provides an advanced configuration mechanism capable of managing any type
- ApplicationContext is a sub-interface of BeanFactory. It adds:
- Easier integration with Spring’s AOP features
- Message resource handling (for use in internationalization)
- Event publication
- Application-layer specific contexts such as the WebApplicationContext for use in web applications.
2. Container Overview
Interface đại diện cho Spring IoC container là org.springframework.context.ApplicationContext, nó đảm nhận việ
Ta có thể tạo instance của interface ApplicationContext thông qua các class sau:
- Đối với standalone application:
- AnnotationConfigApplicationContext
- ClassPathXmlApplicationContext
Configuration Metadata
This configuration metadata represents how you, as an application developer, tell the Spring container to instan
XML-based Configuration
Rule:
Phải để file config trong folder [main/resources]
Template: XML-based configuration metadata configures these beans as <bean/> elements inside a top-level <b
</beans>
- The id attribute is a string that identifies the individual bean definition. The value of the id attribute can be use
- The class attribute defines the type of the bean and uses the fully qualified class name.
Nếu dùng XML-based Configuration thì ta sẽ khởi tạo container bằng class ClassPathXmlApplicationContext
Sau khi khởi tạo được container, ta có thể lấy được các object (bean) được khởi tạo từ container ra qua method
ol (IoC) principle.
ependencies (that is, the other objects they work with) only through constructor arguments, arguments to a factory method,
ed from a factory method.
ocess is fundamentally the inverse (hence the name, Inversion of Control) of the bean itself controlling the instantiation or location of its d
onContext, nó đảm nhận việc khởi tạo (initialize) object, tuy biến (configuration) và assemply
e Spring container to instantiate, configure, and assemble the components in your application.
ml", "daos.xml");