In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 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.
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.