Today, when writing a program, I saw a note (@Component) that I had not seen before, and after searching the web, I decided to record it after practice.
1. @controller controller (injection service)
- Used to label the control layer, equivalent to the action layer in struts
2. @service service (injected into DAO)
- Used for labeling service tiers, primarily for business logic processing
3. @repository (for DAO Access)
- Used to label the data access layer, or to label data access Components, DAO components.
4, @component (the normal pojo is instantiated into the spring container, the equivalent of the configuration file
<bean id="" class=""/>)
- Refers to various components, that is, when our class is not in the various categories (not @controller, @Services, etc.), we can use @component to label this class.
Case:
<context:component-scan base-package=”com.*”>
The above example is an example of the introduction of the component component, where base-package is represented as all the sub-packages that need to be scanned.
Common denominator: Classes that are annotated by @controller, @service, @repository, @component will be managed by incorporating these classes into the spring container
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. 78558010
The role of @component in "turn" spring