In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge points of the commonly used notes on SpringBean, which are detailed in content and clear in logic. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Annotation-based assembly
In the Spring framework, although Bean can be easily assembled using XML configuration files, if there are a large number of Bean to be assembled in the application, the XML configuration file will be too large to facilitate future upgrade and maintenance, so developers are more often recommended to use annotation to assemble Bean.
A series of annotations are defined in the Spring framework, and the annotations commonly used in the set are described below.
@ Component
This annotation is a generalized concept that represents only a component object (Bean) and can be applied at any level.
@ Repository
This annotation is used to identify the class of the data access layer (DAO) as Bean, that is, the annotation data access layer Bean, which has the same function as @ Component.
@ Service
This annotation is used to annotate a business logic component class (Service layer), which has the same function as @ Component.
@ Controller
This annotation is used to mark a controller component class (Spring MVC's Controller), which has the same function as @ Component.
@ Autowired
The annotation can mark the class member variables, methods and construction methods, and complete the work of automatic assembly. Eliminate the setter and getter methods by using @ Autowired. Assemble by default according to the type of Bean.
@ Resource
This annotation has the same function as @ Autowired, except that the injection is assembled by name by default, and the injection is assembled by type only if a Bean matching the name is not found. @ Autowired is assembled according to the type of Bean by default. If you want to assemble the injection by name, you need to use it with the @ Qualifier annotation.
@ Qualifier
This annotation is used in conjunction with the @ Aitowired annotation. When the @ Autowired annotation needs to assemble the injection by name, it needs to be used with the annotation, and the instance name of the Bean is defined by the parameter of the @ Qualifier annotation.
In the above annotations, although @ Repository, @ Service and @ Controller annotations have the same functions as @ Component annotations, in order to make the annotation of classes clearer (hierarchical), it is recommended to use @ Repository to label the data access layer (DAO layer), @ Service to label the business logic layer (Service layer), and @ Controller to label the controller layer (control layer).
These are all the contents of the article "what are the common notes for SpringBean?" Thank you for your reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.