Regarding the difference between spring’s four annotations @Component. @Repository. @Service, and @Controller, check Spring’s official documents:http://spring.io/searchThe document only said that the annotation of the component should be at the component and the annotation of the service should be at the service, but their definitions are not different.
1. Since there is no difference, why define the four annotations separately?
2. Since he said in his definition, the specific scenario is as follows:
@Repository annotation: used to label data access components, i.e. DAO components @Service Annotation: used to annotate business layer components @Controller annotation: used to label control layer components (such as action in struts) @Component annotation: generally refers to components. when components are not easy to classify, we can use this annotation for annotation.
However, I saw in the project that all Dao layers did not add the annotation @Repository.
1. For example, in the Dao layer, is it the same effect to add @Repository and not to add @Respository annotation, there is no difference?
In fact, there is no functional difference between these annotations. You can use these as classification labels to make your code more readable.