{"id":452985,"date":"2025-03-23T21:00:54","date_gmt":"2025-03-23T21:00:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=452985"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=452985","title":{"rendered":"<span>\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0438\u043d\u0430 \u0432 Spring<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0438\u043d\u0430 \u0432 Spring \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u043e\u0432<\/strong>: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u0442-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435.<br \/><strong>\u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong> \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <strong>\u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e<\/strong> \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c AOP, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 (Instantiation)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0438\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043d\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438:<\/strong> \u0412\u044b \u043a\u0443\u043f\u0438\u043b\u0438 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443, \u043d\u043e \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u0435\u0435 \u043a \u0441\u0435\u0442\u0438 \u0438 \u043d\u0435 \u0437\u0430\u043b\u0438\u043b\u0438 \u0432\u043e\u0434\u0443.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 2. \u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Dependency Injection)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0431\u0438\u043d \u0432\u0441\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\ud83d\udccc <strong>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f:<\/strong> \u0412\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443 \u043a \u0441\u0435\u0442\u0438 \u0438 \u0437\u0430\u043b\u0438\u043b\u0438 \u0432\u043e\u0434\u0443.<\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/strong> \u2013 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <strong>final<\/strong> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0435<\/strong> &#8212; <strong>@Autowired<\/strong> \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u0435, \u0438 Spring \u0432\u043d\u0435\u0434\u0440\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 <strong>\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u0435\u0435 \u044f\u0432\u043d\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u0441\u0435\u0442\u0442\u0435\u0440\u044b<\/strong> \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0438\u043d\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Value, @Qualifier \u0438 \u0434\u0440.<\/strong> \u2013 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0431\u0438\u043d\u0430 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 3. Aware-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u0431\u0438\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 BeanNameAware, BeanFactoryAware, ApplicationContextAware, Spring \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u043c\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438:<\/strong> \u041a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0442\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<ul>\n<li>\n<p>BeanNameAware \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 <strong>\u0438\u043c\u044f \u0431\u0438\u043d\u0430<\/strong><\/p>\n<\/li>\n<li>\n<p>BeanFactoryAware \u2014 \u0434\u043e\u0441\u0442\u0443\u043f \u043a <strong>BeanFactory<\/strong><\/p>\n<\/li>\n<li>\n<p>ApplicationContextAware \u2014 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e <strong>\u0432\u0441\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 Spring<\/strong><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u26a0\ufe0f \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u0445 \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0434 \u043a Spring API \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<\/blockquote>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 4. BeanPostProcessor \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 postProcessBeforeInitialization \u0443 \u0432\u0441\u0435\u0445 BeanPostProcessor.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0434 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/strong> \u2013 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (@Profile).<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong> \u2013 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0431\u0438\u043d\u0435 \u043f\u0435\u0440\u0435\u0434 \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 5. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (init)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>@PostConstruct<\/p>\n<\/li>\n<li>\n<p>InitializingBean#afterPropertiesSet()<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 @Bean(initMethod = &#171;init&#187;)<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong> \u041a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0432\u0430\u0435\u0442 \u0432\u043e\u0434\u0443 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0444\u0435.<\/p>\n<blockquote>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0431\u0438\u043d\u0430 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0411\u0414).<\/p>\n<\/blockquote>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 6. BeanPostProcessor \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 postProcessAfterInitialization \u0443 BeanPostProcessor.<\/p>\n<p><strong>\u0413\u0434\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 AOP-\u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 @Transactional, @Async \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong> \u2013 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043b\u0438 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u26a0\ufe0f \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f Spring-\u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 (<strong>\u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0438 instanceof<\/strong>).<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 7. \u0423\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 (destroy)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>@PreDestroy<\/p>\n<\/li>\n<li>\n<p>DisposableBean#destroy()<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 @Bean(destroyMethod = &#171;cleanup&#187;)<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong> \u0412\u044b \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0435 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443, \u0441\u043b\u0438\u0432\u0430\u0435\u0442\u0435 \u0432\u043e\u0434\u0443, \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0444\u0438\u043b\u044c\u0442\u0440 \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0435\u0435.<\/p>\n<p>\u26a0\ufe0f \u0414\u043b\u044f prototype-\u0431\u0438\u043d\u043e\u0432 \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u2014 \u0438\u0445 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/summary>\n<div class=\"spoiler__content\">\n<h4>\ud83d\udccc \u041a\u043e\u0434<\/h4>\n<pre><code class=\"java\">\/\/ \u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0431\u0438\u043d \u0441 \u043b\u043e\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0430\u043f\u043e\u0432 @Component class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {          private String beanName;     private ApplicationContext context;      public MyBean() {         System.out.println(\"1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyBean \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation)\");     }      @Autowired     public void setDependency(MyDependency dependency) {         System.out.println(\"2. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c MyDependency \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 (DI)\");     }      @Override     public void setBeanName(String name) {         this.beanName = name;         System.out.println(\"3. BeanNameAware: \u0418\u043c\u044f \u0431\u0438\u043d\u0430 - \" + name);     }      @Override     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {         this.context = applicationContext;         System.out.println(\"3. ApplicationContextAware: \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\");     }      @PostConstruct     public void postConstruct() {         System.out.println(\"5. @PostConstruct: \u0411\u0438\u043d \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\");     }      @Override     public void afterPropertiesSet() {         System.out.println(\"5. InitializingBean: \u0411\u0438\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e\");     }      @PreDestroy     public void preDestroy() {         System.out.println(\"7. @PreDestroy: \u041f\u0435\u0440\u0435\u0434 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0438\u043d\u0430\");     }      @Override     public void destroy() {         System.out.println(\"7. DisposableBean: \u0411\u0438\u043d \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\");     } }  \/\/ \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u043d \u0434\u043b\u044f DI @Component class MyDependency {     public MyDependency() {         System.out.println(\"1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyDependency \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation)\");     } }  \/\/ BeanPostProcessor \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0430\u043f\u043e\u0432 postProcessBeforeInitialization \u0438 postProcessAfterInitialization @Component class MyBeanPostProcessor implements BeanPostProcessor {          @Override     public Object postProcessBeforeInitialization(Object bean, String beanName) {         if (bean instanceof MyBean) {             System.out.println(\"4. BeanPostProcessor: Before Init - \" + beanName);         }         return bean;     }      @Override     public Object postProcessAfterInitialization(Object bean, String beanName) {         if (bean instanceof MyBean) {             System.out.println(\"6. BeanPostProcessor: After Init - \" + beanName);         }         return bean;     } }  @SpringBootApplication public class DemoApplication {     public static void main(String[] args) {         SpringApplication.run(DemoApplication.class, args);     }  }<\/code><\/pre>\n<h4>\ud83d\udccc \u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/h4>\n<pre><code class=\"java\">1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyDependency \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation) 1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyBean \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation) 2. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c MyDependency \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 (DI) 3. BeanNameAware: \u0418\u043c\u044f \u0431\u0438\u043d\u0430 - myBean 3. ApplicationContextAware: \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d 4. BeanPostProcessor: Before Init - myBean 5. @PostConstruct: \u0411\u0438\u043d \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d 5. InitializingBean: \u0411\u0438\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e 6. BeanPostProcessor: After Init - myBean &gt;&gt;&gt; \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d  &gt;&gt;&gt; \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 7. @PreDestroy: \u041f\u0435\u0440\u0435\u0434 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0438\u043d\u0430 7. DisposableBean: \u0411\u0438\u043d \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b:<\/h4>\n<ul>\n<li>\n<p><strong>BeanPostProcessor \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u0438 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>Aware-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u0430\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a Spring-\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u043d\u043e \u043d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0439\u0442\u0435 \u0438\u043c\u0438<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @PostConstruct \u0438 @PreDestroy \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/893614\/\"> https:\/\/habr.com\/ru\/articles\/893614\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0431\u0438\u043d\u0430 \u0432 Spring \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 <strong>\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u043e\u0432<\/strong>: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043f\u043e\u0441\u0442-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430\u043c\u0438 \u0438 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435.<br \/><strong>\u041f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/strong> \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <strong>\u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e<\/strong> \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c AOP, \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438.<br \/>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u0442\u0430\u043f \u043d\u0430 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445:<\/p>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 (Instantiation)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0438\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430, \u043d\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438:<\/strong> \u0412\u044b \u043a\u0443\u043f\u0438\u043b\u0438 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443, \u043d\u043e \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u0435\u0435 \u043a \u0441\u0435\u0442\u0438 \u0438 \u043d\u0435 \u0437\u0430\u043b\u0438\u043b\u0438 \u0432\u043e\u0434\u0443.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 2. \u0412\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 (Dependency Injection)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0431\u0438\u043d \u0432\u0441\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<p>\ud83d\udccc <strong>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u044f:<\/strong> \u0412\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443 \u043a \u0441\u0435\u0442\u0438 \u0438 \u0437\u0430\u043b\u0438\u043b\u0438 \u0432\u043e\u0434\u0443.<\/p>\n<p><strong>\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440<\/strong> \u2013 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0432 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0441 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c <strong>final<\/strong> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0435<\/strong> &#8212; <strong>@Autowired<\/strong> \u043c\u043e\u0436\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u0435, \u0438 Spring \u0432\u043d\u0435\u0434\u0440\u0438\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 <strong>\u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u0435\u0435 \u044f\u0432\u043d\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u0441\u0435\u0442\u0442\u0435\u0440\u044b<\/strong> \u2013 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0431\u0438\u043d\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0427\u0435\u0440\u0435\u0437 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @Value, @Qualifier \u0438 \u0434\u0440.<\/strong> \u2013 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0431\u0438\u043d\u0430 \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 3. Aware-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0415\u0441\u043b\u0438 \u0431\u0438\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 BeanNameAware, BeanFactoryAware, ApplicationContextAware, Spring \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u043c\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435.<\/p>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438:<\/strong> \u041a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 \u0432 \u0441\u0435\u0442\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<ul>\n<li>\n<p>BeanNameAware \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 <strong>\u0438\u043c\u044f \u0431\u0438\u043d\u0430<\/strong><\/p>\n<\/li>\n<li>\n<p>BeanFactoryAware \u2014 \u0434\u043e\u0441\u0442\u0443\u043f \u043a <strong>BeanFactory<\/strong><\/p>\n<\/li>\n<li>\n<p>ApplicationContextAware \u2014 \u0434\u043e\u0441\u0442\u0443\u043f \u043a\u043e <strong>\u0432\u0441\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 Spring<\/strong><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p>\u26a0\ufe0f \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u0445 \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0434 \u043a Spring API \u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<\/blockquote>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 4. BeanPostProcessor \u0434\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 postProcessBeforeInitialization \u0443 \u0432\u0441\u0435\u0445 BeanPostProcessor.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0434 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432<\/strong> \u2013 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (@Profile).<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong> \u2013 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0431\u0438\u043d\u0435 \u043f\u0435\u0440\u0435\u0434 \u0435\u0433\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 5. \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (init)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b:<\/p>\n<ul>\n<li>\n<p>@PostConstruct<\/p>\n<\/li>\n<li>\n<p>InitializingBean#afterPropertiesSet()<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 @Bean(initMethod = &#171;init&#187;)<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong> \u041a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0435\u0432\u0430\u0435\u0442 \u0432\u043e\u0434\u0443 \u043f\u0435\u0440\u0435\u0434 \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0444\u0435.<\/p>\n<blockquote>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0431\u0438\u043d\u0430 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0411\u0414).<\/p>\n<\/blockquote>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 6. BeanPostProcessor \u043f\u043e\u0441\u043b\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 postProcessAfterInitialization \u0443 BeanPostProcessor.<\/p>\n<p><strong>\u0413\u0434\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 AOP-\u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439 @Transactional, @Async \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/strong> \u2013 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0431\u0438\u043d\u043e\u0432<\/strong> \u2013 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043b\u0438 \u043e\u0431\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u26a0\ufe0f \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0438\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f Spring-\u043e\u0431\u0435\u0440\u0442\u043a\u043e\u0439 (<strong>\u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0438 instanceof<\/strong>).<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udfe2 \u042d\u0442\u0430\u043f 7. \u0423\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0438\u043d\u0430 (destroy)<\/summary>\n<div class=\"spoiler__content\">\n<p>Spring \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>@PreDestroy<\/p>\n<\/li>\n<li>\n<p>DisposableBean#destroy()<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 @Bean(destroyMethod = &#171;cleanup&#187;)<\/p>\n<\/li>\n<\/ul>\n<p>\ud83d\udccc <strong>\u041f\u0440\u0438\u043c\u0435\u0440:<\/strong> \u0412\u044b \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0435 \u043a\u043e\u0444\u0435\u0432\u0430\u0440\u043a\u0443, \u0441\u043b\u0438\u0432\u0430\u0435\u0442\u0435 \u0432\u043e\u0434\u0443, \u0447\u0438\u0441\u0442\u0438\u0442\u0435 \u0444\u0438\u043b\u044c\u0442\u0440 \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0435\u0435.<\/p>\n<p>\u26a0\ufe0f \u0414\u043b\u044f prototype-\u0431\u0438\u043d\u043e\u0432 \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u2014 \u0438\u0445 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/summary>\n<div class=\"spoiler__content\">\n<h4>\ud83d\udccc \u041a\u043e\u0434<\/h4>\n<pre><code class=\"java\">\/\/ \u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0431\u0438\u043d \u0441 \u043b\u043e\u0433\u0430\u043c\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0430\u043f\u043e\u0432 @Component class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {          private String beanName;     private ApplicationContext context;      public MyBean() {         System.out.println(\"1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyBean \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation)\");     }      @Autowired     public void setDependency(MyDependency dependency) {         System.out.println(\"2. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c MyDependency \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 (DI)\");     }      @Override     public void setBeanName(String name) {         this.beanName = name;         System.out.println(\"3. BeanNameAware: \u0418\u043c\u044f \u0431\u0438\u043d\u0430 - \" + name);     }      @Override     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {         this.context = applicationContext;         System.out.println(\"3. ApplicationContextAware: \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\");     }      @PostConstruct     public void postConstruct() {         System.out.println(\"5. @PostConstruct: \u0411\u0438\u043d \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\");     }      @Override     public void afterPropertiesSet() {         System.out.println(\"5. InitializingBean: \u0411\u0438\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e\");     }      @PreDestroy     public void preDestroy() {         System.out.println(\"7. @PreDestroy: \u041f\u0435\u0440\u0435\u0434 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0438\u043d\u0430\");     }      @Override     public void destroy() {         System.out.println(\"7. DisposableBean: \u0411\u0438\u043d \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\");     } }  \/\/ \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0431\u0438\u043d \u0434\u043b\u044f DI @Component class MyDependency {     public MyDependency() {         System.out.println(\"1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyDependency \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation)\");     } }  \/\/ BeanPostProcessor \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u0430\u043f\u043e\u0432 postProcessBeforeInitialization \u0438 postProcessAfterInitialization @Component class MyBeanPostProcessor implements BeanPostProcessor {          @Override     public Object postProcessBeforeInitialization(Object bean, String beanName) {         if (bean instanceof MyBean) {             System.out.println(\"4. BeanPostProcessor: Before Init - \" + beanName);         }         return bean;     }      @Override     public Object postProcessAfterInitialization(Object bean, String beanName) {         if (bean instanceof MyBean) {             System.out.println(\"6. BeanPostProcessor: After Init - \" + beanName);         }         return bean;     } }  @SpringBootApplication public class DemoApplication {     public static void main(String[] args) {         SpringApplication.run(DemoApplication.class, args);     }  }<\/code><\/pre>\n<h4>\ud83d\udccc \u0412\u044b\u0432\u043e\u0434 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c<\/h4>\n<pre><code class=\"java\">1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyDependency \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation) 1. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 MyBean \u0432\u044b\u0437\u0432\u0430\u043d (Instantiation) 2. \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c MyDependency \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0430 (DI) 3. BeanNameAware: \u0418\u043c\u044f \u0431\u0438\u043d\u0430 - myBean 3. ApplicationContextAware: \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d 4. BeanPostProcessor: Before Init - myBean 5. @PostConstruct: \u0411\u0438\u043d \u043f\u0440\u043e\u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d 5. InitializingBean: \u0411\u0438\u043d \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e 6. BeanPostProcessor: After Init - myBean &gt;&gt;&gt; \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d  &gt;&gt;&gt; \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 7. @PreDestroy: \u041f\u0435\u0440\u0435\u0434 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0438\u043d\u0430 7. DisposableBean: \u0411\u0438\u043d \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b:<\/h4>\n<ul>\n<li>\n<p><strong>BeanPostProcessor \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u0438 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>Aware-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u0430\u044e\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a Spring-\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443, \u043d\u043e \u043d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0439\u0442\u0435 \u0438\u043c\u0438<\/strong>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 @PostConstruct \u0438 @PreDestroy \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/893614\/\"> https:\/\/habr.com\/ru\/articles\/893614\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-452985","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=452985"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/452985\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=452985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=452985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=452985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}