In annotaion configuration annotations, @component is used to represent a generic annotation that describes a class as a spring container-managed class. That is, the class has been pulled into spring management. And @controller, @Service, @Repository is @component refinement, these three annotations have more semantics than @component, they correspond to the control layer, service layer, persistence layer class.
The @Repository label is used to define a name for the class of the persistence layer, so that spring is associated with the class by that name.
For example:
@Repository ("Userdao")
public class Userdaoimpl implements userdao{
........................................
}
Declares the name of the Userdaoimpl in the spring container called Userdao.
@Service is a Iserviceimpl class file for the service layer, and functions similar to @repository.
Another label: @autowired used to inject.
For example:
@autowired
Private Userdao Userdao;
This is injected into the equivalent of a new implementation class, so we don't have to write the setter method.
We also have to have a configuration file to configure:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.