In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the principle of spring @ Component annotation". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the principle of spring @ Component annotations"?
1.@controller controller (injection service)
2.@service service (injecting dao)
3.@repository dao (for dao access)
4.@component (instantiate a normal pojo into a spring container, equivalent to that in a configuration file)
5. Add the classes annotated by the Repository and put them into the spring container for management.
@ Servicepublic class UserServiceImpl implements UserService {} @ Repositorypublic class UserDaoImpl implements UserDao {}
6.
In this way, you can use @ Resource, @ PostConstruct, @ PreDestroy, @ PersistenceContext, @ Autowired, @ Required and other annotations to achieve automatic injection.
7.
Spring provides us with a simplified configuration of context:annotation-config, automatically helps you complete the declaration, and automatically searches @ Component, @ Controller, @ Service, @ Repository and other annotated classes.
In addition to the context:annotation-config function of context:component-scan, context:component-scan can also scan and register javabean under the specified package. It also has the ability to automatically register objects with annotations such as @ component,@service,@Repository in the spring container.
So when you use context:component-scan, you can remove context:annotation-config.
8.spring ioc control inversion
-- Private member variables
@ Autowired@Qualifier ("batchNo") private IdGenerator idGenerator
Equivalent to using @ Component ("")
At this point, I believe you have a deeper understanding of "what is the principle of spring @ Component annotations". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.