In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the content of sample analysis of IOC code in Spring. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Inversion of control (Inversion of Control, abbreviated as IoC) handing over the right to create objects to the framework is an important feature of the framework, not a special term for object-oriented programming. It includes dependency injection (DI) and dependency lookup (Dependency Lookup).
IOC changes the way the program acquires objects, from the initial new of an object to the creation and injection of third-party frameworks. Third-party frameworks typically specify which implementation to inject through configuration, thereby reducing source code coupling.
What are the biggest benefits of ioc?
Because the object generation is defined in XML, when we need to change the implementation of a subclass will become very simple (usually such objects are realistic in a certain interface), as long as modify the XML, so that we can even achieve hot plugging objects (a bit like the USB interface and SCIS hard disk).
According to the way of implementation, IOC can be divided into dependency injection (DI) and dependency lookup.
DI is the main technical way to control inversion, which is divided into setter injection and constructor injection.
Setter injection
After bean is instantiated by calling a no-parameter constructor or static no-parameter factory method, the setter method of bean is called to implement setter injection.
Public class JDBCDataSource () {private String driver; public void setDriver (String driver) {Class.forName (driver); this.driver=driver;}}. .
Next, implement the setter injection configuration xml file
Constructor injection
This is achieved by calling the constructor with parameters, and when the bean is instantiated, the container executes the constructor based on the parameter type.
Public class OracleUserDao implements UserDao {private JDBCDataSource dataSource; public OracleUserDao (JDBCDataSource dataSource) {this.dataSource=dataSource;}}.
Specify injection by construction parameter index
Thank you for reading! This is the end of this article on "sample Analysis of IOC Code in Spring". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.