In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about why @ PostConstruct is not called. The content is detailed and the logic is clear. 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. Let's take a look at it.
The reason why @ PostConstruct is not called
If you configure the use of delayed loading in the configuration file
As shown in the picture
Classes annotated by @ Service and so on need to be initialized when the injection is used. Methods annotated with @ PostConstrut will not be executed if the TableInit class is only defined and not referenced elsewhere.
@ PostConstruct detailed definition
@ PostContruct is an annotation that comes with Java, and adding this annotation to the method executes the method when the project starts, or it can be understood to execute the method when the spring container is initialized.
Starting with the Java EE5 specification, Servlet adds two annotations that affect the Servlet life cycle, @ PostConstruct and @ PreDestroy, which are used to modify a non-static void () method.
Usage @ PostConstruct public void someMethod () {}
Or
Public @ PostConstruct void someMethod () {} function
The @ PostConstruct annotated method executes this method when the project starts, or it can be understood to be executed when the spring container starts, and can be used as a regular load of some data, such as data dictionaries.
Execution sequence
In fact, you can know from the literal meaning of dependency injection that to inject object p into object a, you must first generate object an and object p before the injection can be performed. So, if a member variable p in a class An is annotated with @ Autowried, then @ Autowired injection occurs after A's constructor is executed.
If you want to complete some initialization operations when the object is generated, but these initialization operations depend on dependency injection, you can't do it in the constructor for a long time. To do this, you can use @ PostConstruct to annotate a method to complete initialization, and the method annotated by @ PostConstruct will be called automatically after dependency injection is complete.
Constructor > > @ Autowired > > @ PostConstruct
These are all the contents of the article "@ PostConstruct is not called". Thank you for 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.