{"id":462439,"date":"2025-06-09T03:02:22","date_gmt":"2025-06-09T03:02:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=462439"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=462439","title":{"rendered":"<span>\u041e\u0442 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043a \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0435. \u041d\u043e\u0432\u044b\u0439 API \u043f\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044e \u0431\u0438\u043d\u043e\u0432 \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>\u0412 Spring Framework 7 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 API \u2014 BeanRegistry, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e Spring Data. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 <a href=\"https:\/\/t.me\/+QmrKn0wA8CdkNjAy\" rel=\"noopener noreferrer nofollow\">Spring \u0410\u0439\u041e<\/a>, <a href=\"https:\/\/t.me\/mipo256\" rel=\"noopener noreferrer nofollow\">\u041c\u0438\u0445\u0430\u0438\u043b\u0430 \u041f\u043e\u043b\u0438\u0432\u0430\u0445\u0438<\/a>, \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a Spring Data \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u043d\u044c\u0448\u0435;<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0434\u043e BeanRegistrar, \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u043d\u043e\u0432\u044b\u0439 API \u0441\u0432\u044f\u0437\u0430\u043d \u0441\u043e Spring AOT.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Spring Framework \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c Bean-\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0418 \u0432\u043e\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Spring Framework 7 \u0437\u0430\u0432\u043e\u0437\u044f\u0442 \u043d\u043e\u0432\u044b\u0439 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u044d\u0442\u043e \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u043d\u043e\u0432\u044b\u0439 \u0437\u0432\u0435\u0440\u044c, \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Spring Data, \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443.<\/p>\n<p><strong>NOTE<\/strong>: Spring Framework 7 \u0435\u0449\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 GA \u0440\u0435\u043b\u0438\u0437\u0430, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043e\u043d \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u0448\u0435\u043b. \u0412\u0441\u0435, \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f <strong>\u043d\u043e\u0432\u043e\u0433\u043e<\/strong> API \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a 7-\u043e\u043c\u0443 Milestone \u0440\u0435\u043b\u0438\u0437\u0443 Spring Framework. \u0412\u0440\u044f\u0434 \u043b\u0438 API \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e \u0438\u043c\u0435\u0439\u0442\u0435 \u044d\u0442\u043e \u0432 \u0432\u0438\u0434\u0443.<\/p>\n<h3>Spring Data. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432<\/h3>\n<p>\u0427\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 Spring Data:<\/p>\n<ol>\n<li>\n<p>\u041e\u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041b\u044e\u0431\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043e\u0431\u044f\u0437\u0430\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0431\u043e<a href=\"http:\/\/org.springframework.data\" rel=\"noopener noreferrer nofollow\"> org.springframework.data<\/a>.repository.Repository, \u043b\u0438\u0431\u043e \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443 \u0438 \u0434\u0430\u043b\u0435\u0435 Spring Data \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c classpath \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0448\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0438\u043d\u044b.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 &#8212; Spring Data \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043d\u043e\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435<\/strong>. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u044d\u0442\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u043d\u044b. \u041f\u043e\u0434 &#171;\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439&#187; \u0437\u0434\u0435\u0441\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432 &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e API Spring-\u0430, \u0430 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u043d\u0430\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Component<\/code> \u0438 \u0435\u0451 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435.<\/p>\n<p>\u041d\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435, Spring Framework 7 \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u0448\u0435\u043b, \u0432\u0441\u0435 \u0447\u0442\u043e \u0443 \u043d\u0430c \u0435\u0441\u0442\u044c, \u044d\u0442\u043e Milestone \u0440\u0435\u043b\u0438\u0437, \u043d\u043e<a href=\"https:\/\/github.com\/spring-projects\/spring-data-jpa\/tree\/1.3.5.RELEASE\" rel=\"noopener noreferrer nofollow\"> Spring Data JPA, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 10 \u043b\u0435\u0442<\/a>. \u041a\u0430\u043a \u0434\u043e \u044d\u0442\u043e\u0433\u043e Spring Data \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0431\u0438\u043d\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432 \u0435\u0449\u0435 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u044b\u0448\u043b\u0430?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h3>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0411\u0438\u043d\u043e\u0432. \u0418\u0441\u0442\u043e\u043a\u0438<\/h3>\n<p>\u0412 \u0447\u0435\u043c \u0436\u0435 \u0434\u0435\u043b\u043e. <strong>\u0410 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0443\u0436\u0435 \u0431\u044b\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f (\u043e \u0442\u043e\u043c, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u043d\u0430\u043c \u043d\u043e\u0432\u044b\u0439 API, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435)<\/strong>.<\/p>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0443\u0436\u0435 \u0434\u043e\u043b\u0433\u0438\u0435 \u0433\u043e\u0434\u044b \u0432 Spring Framework \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>SingletonBeanRegistry<\/code>. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u043e\u0432:<\/p>\n<pre><code class=\"java\">class MyFirst {  private final MySecond mySecond;  MyFirst(MySecond mySecond) { this.mySecond = mySecond; } }  class MySecond { }  class ProgrammaticBeanRegistrationApplicationTest {  @Test void testRegisterSingletonMethod() { GenericApplicationContext applicationContext = new GenericApplicationContext(); MySecond second = new MySecond();  applicationContext.getBeanFactory().registerSingleton(\"mySecond\", second); applicationContext.getBeanFactory().registerSingleton(\"myFirst\", new MyFirst(second));  applicationContext.refresh();  assertThat(applicationContext.containsBean(\"myFirst\")).isTrue(); assertThat(applicationContext.containsBean(\"mySecond\")).isTrue(); } }<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b &#8212; \u0447\u0435\u0433\u043e \u043c\u0443\u0434\u0440\u0438\u0442\u044c, \u0432\u043e\u0442 \u043e\u043d\u043e, \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <strong>\u041d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong>. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0434\u0430\u043d\u043d\u044b\u0439 API \u043d\u0435 \u0434\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>BeanDefinition<\/code>. \u0414\u043b\u044f \u044f\u0441\u043d\u043e\u0441\u0442\u0438: <code>BeanDefinition<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0438\u043d\u0430, \u043d\u0430\u0431\u043e\u0440 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>Scope \u0431\u0438\u043d\u0430. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <em>Singleton<\/em>, \u043d\u043e \u0438 <em>Session<\/em> \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p>Init \u043c\u0435\u0442\u043e\u0434\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0447\u044c \u043f\u0440\u043e <code>@PostConstruct<\/code> \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>afterPropertiesSet()<\/code>, \u0445\u043e\u0442\u044f \u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430.<\/p>\n<\/li>\n<li>\n<p><code>Primary<\/code>\/<code>Fallback<\/code> \u0444\u043b\u0430\u0433\u0438. \u0418\u0445, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 <code>@Primary<\/code> \u0438 <code>@Fallback<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<\/li>\n<\/ol>\n<p>\u0438 \u0442.\u0434.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>SingletonBeanRegistry<\/code> \u0435\u0449\u0435 \u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e. \u041e\u043d\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 <code>@PostConstruct<\/code>\/<code>@PreDestroy<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0438. <strong>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0431\u0438\u043d \u0443\u0436\u0435 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d<\/strong>. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 Singleton, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 <code>ApplicationContext<\/code>:<\/p>\n<pre><code class=\"java\">class WithCallback implements InitializingBean {  private boolean callbackCalled;  @Override public void afterPropertiesSet() throws Exception { System.out.println(\"Hey from the callback\"); callbackCalled = true; }  public boolean isCallbackCalled() { return callbackCalled; } }  class ProgrammaticBeanRegistrationApplicationTest {  @Test void testRegisterSingletonMethod_noCallbacksInvoked() { GenericApplicationContext applicationContext = new GenericApplicationContext();  applicationContext.getBeanFactory().registerSingleton(\"mySecond\", new WithCallback()); applicationContext.refresh();  assertThat(applicationContext.containsBean(\"mySecond\")).isTrue(); \/\/ \u0411\u0438\u043d-\u0442\u043e \u0435\u0441\u0442\u044c assertThat(applicationContext.getBean(\"mySecond\", WithCallback.class).isCallbackCalled()).isFalse(); \/\/ \u0410 \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d } }<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u0437\u044f\u0442\u044c \u0431\u0438\u043d \u0438\u0437 <code>BeanFactory<\/code>\/<code>ApplicationContext<\/code>-\u0430 \u0447\u0435\u0440\u0435\u0437 <code>getBean()<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<h3>\u041c\u044b \u041c\u043e\u0436\u0435\u043c \u041b\u0443\u0447\u0448\u0435! BeanDefinitionRegistry<\/h3>\n<p>\u041d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044f\u0441\u043d\u0430 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0430. \u0418 \u0442\u0443\u0442 \u0432 \u0434\u0432\u0435\u0440\u044c \u0441 \u043d\u043e\u0433\u0438 \u0432\u043b\u0430\u043c\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>BeanDefinitionRegistry<\/code>!<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>BeanDefinitionRegistry<\/code> \u0442\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 Spring Framework \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u0430\u0432\u043d\u043e. <strong>\u0418 \u0434\u0430, \u0435\u0441\u043b\u0438 \u0412\u0430\u043c-\u0442\u0430\u043a\u0438 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0436\u0435 Spring Data \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u0432\u043e\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442 \u2013 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <\/strong><code><strong>BeanDefinitionRegistry<\/strong><\/code><strong>.<\/strong> \u0412\u043e\u0442<a href=\"https:\/\/github.com\/spring-projects\/spring-data-commons\/blob\/main\/src\/main\/java\/org\/springframework\/data\/repository\/config\/RepositoryConfigurationDelegate.java#L138\" rel=\"noopener noreferrer nofollow\"> \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432 Spring Data Commons<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 <code>BeanDefinition<\/code>-\u043e\u0432. \u0421\u0430\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 <code>RepositoryFactorySupport<\/code>, \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0436\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 API <code>BeanDefinitionRegistry<\/code>:<\/p>\n<pre><code class=\"java\">class ProgrammaticBeanRegistrationApplicationTest {  @Test void testDynamicBeansRegistration_beanDefinitionRegistry() { GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProgrammaticBeanRegistry.class);  WithCallback firstBean = applicationContext.getBean(\"withCallback\", WithCallback.class); WithCallback secondBean = applicationContext.getBean(\"withCallback\", WithCallback.class);  assertThat(firstBean.isCallbackCalled()).isTrue(); \/\/ \u041a\u043e\u043b\u043b\u0431\u0435\u043a\u0438 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438! assertThat(secondBean.isCallbackCalled()).isTrue();  assertThat(firstBean).isNotSameAs(secondBean); \/\/ \u0418 \u0431\u0438\u043d \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u043d\u0435 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435, prototype! }  @Component static class ProgrammaticBeanRegistry implements BeanDefinitionRegistryPostProcessor {  @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { registry.registerBeanDefinition(\"withCallback\", BeanDefinitionBuilder.genericBeanDefinition(WithCallback.class).setPrimary(true).setLazyInit(false) .setScope(\"prototype\").getBeanDefinition()); } } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u043e\u043d\u043a\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>BeanDefinition<\/code>-a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e, \u0432 \u0442\u0435\u043e\u0440\u0438\u0438, \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>BeanDefinitionRegistry<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e <code>BeanDefinitionRegistryPostProcessor<\/code>.<a href=\"https:\/\/spring.io\/blog\/2017\/03\/01\/spring-tips-programmatic-bean-registration-in-spring-framework-5\" rel=\"noopener noreferrer nofollow\"> \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0438\u0434\u0435\u043e \u043e\u0442 Josh-a Long-a<\/a>, Spring Framework Developer Advocate-\u0430, \u0433\u0434\u0435 \u043e\u043d \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 API \u0447\u0435\u0440\u0435\u0437 <code>BeanDefinitionRegistryPostProcessor<\/code>.<\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e init \u043c\u0435\u0442\u043e\u0434\u044b, scope-\u044b, primary, lazy-init \u2013 \u044d\u0442\u043e \u0432\u0441\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/strong>. \u041f\u043e\u0447\u0435\u043c\u0443? \u0427\u0438\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u043a\u0446\u0438\u044e \u043d\u0438\u0436\u0435. \u0418 Spring Data \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 API \u043f\u043e \u0441\u0435\u0439 \u0434\u0435\u043d\u044c. <strong>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442<\/strong> <strong>\u0432\u043e\u043f\u0440\u043e\u0441: \u201c\u0427\u0435\u043c \u043e\u043d \u043d\u0430\u043c \u043d\u0435 \u0443\u0433\u043e\u0434\u0438\u043b?\u201d<\/strong><\/p>\n<h3>\u041d\u043e\u0432\u044b\u0439 API. BeanRegistry<\/h3>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Spring Framework 7, \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 BeanRegistry API. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0447\u0432\u0443 \u0434\u043b\u044f \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>BeanRegistry<\/code> \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438:<\/p>\n<pre><code class=\"java\">class ProgrammaticBeanRegistrationApplicationTest {  @Test void testDynamicBeansRegistration_beanRegistry() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( BeanRegistryConfiguration.class);  BeanDefinition beanDefinition = applicationContext.getBeanDefinition(\"prodBean\");  assertThat(beanDefinition.getScope()).isEqualTo(\"prototype\"); assertThat(beanDefinition.isPrimary()).isTrue(); assertThat(beanDefinition.isLazyInit()).isTrue(); }  \/**  * application.properties \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:  * &lt;p&gt;  * &lt;pre class=\"code\"&gt;  *   spring.profiles.active=prod  * &lt;\/pre&gt;  *\/ @Configuration @PropertySource(\"application.properties\") @Import(MyBeanRegistry.class) static class BeanRegistryConfiguration { }  @Component static class MyBeanRegistry implements BeanRegistrar {  @Override public void register(BeanRegistry registry, Environment env) { if (env.matchesProfiles(\"dev|qa\")) { registry.registerBean(\"testBean\", WithCallback.class, spec -&gt; spec.fallback().lazyInit().order(Ordered.HIGHEST_PRECEDENCE)); } else if (env.matchesProfiles(\"prod\")) { registry.registerBean(\"prodBean\", WithCallback.class, spec -&gt; spec.primary().prototype().lazyInit()); } } } }<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0442\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043b\u0438\u0448\u044c API \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0445 \u043d\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>BeanDefinitionRegistryPostProcessor<\/code> \u0438\u043b\u0438 \u0442.\u043f. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0443 \u043d\u0430\u0441 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 <code>Environment<\/code> \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <code>@Value<\/code>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 <code>BeanDefinitionRegistryPostProcessor<\/code>?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c <code>Environment<\/code> \u0432 <code>BeanDefinitionRegistryPostProcessor<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u043e\u0432 \u0441 \u0443\u043f\u043e\u0440\u043e\u043c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437<a href=\"http:\/\/application.properties\" rel=\"noopener noreferrer nofollow\"> application.properties<\/a>? <strong>\u0414\u0430, \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441.<\/strong><\/p>\n<p>\u041e\u043d \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c <code>@Autowired Environment env;<\/code>. \u041f\u043e\u0447\u0435\u043c\u0443? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>BeanDefinitionRegistryPostProcessor<\/code> \u2013 \u044d\u0442\u043e <code>BeanFactoryPostProcessor<\/code>. \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, <code>BeanFactoryPostProcessor<\/code><a href=\"https:\/\/github.com\/spring-projects\/spring-framework\/issues\/25754\" rel=\"noopener noreferrer nofollow\"> \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043e\u0447\u0435\u043d\u044c \u0440\u0430\u043d\u043e (\u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f BeanDefinition-\u043e\u0432)<\/a>, \u0434\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u044f\u0434\u043e\u0432\u044b\u0445 \u0431\u0438\u043d\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 <code>@Autowired<\/code> \u043d\u0435\u0447\u0435\u0433\u043e \u2013 Spring \u0435\u0449\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043b. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0437\u0430 \u0441\u0447\u0435\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0431\u043e\u0442\u044b <code>BeanFactoryPostProcessor<\/code>-\u043e\u0432 \u0435\u0449\u0435 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0431\u0438\u043d\u043e\u0432 \u043d\u0435\u0442, Spring \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 <code>BeanDefinition<\/code>-\u044b \u043a \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0438 \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 (\u043d\u0443, \u043f\u043e\u0447\u0442\u0438) \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 <code>@Component<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0438 \u0438 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435.<\/p>\n<p>\u041d\u043e \u044f \u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u0437\u0430\u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c <code>Environment<\/code> \u043c\u043e\u0436\u043d\u043e. \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u0430, \u043c\u043e\u0436\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"java\">class ProgrammaticBeanRegistrationApplicationTest {  @Test void testDynamicBeansRegistration_propertiesInBeanFactoryPostProcessor() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( BeanDefinitionRegistryPostProcessorConfiguration.class);  BeanDefinition beanDefinition = applicationContext.getBeanDefinition(\"withCallback\");  assertThat(beanDefinition.getScope()).isEqualTo(\"prototype\"); assertThat(beanDefinition.isPrimary()).isTrue(); assertThat(beanDefinition.isLazyInit()).isFalse(); }  @Configuration @PropertySource(\"application.properties\") @Import(ProgrammaticBeanRegistryEnvironmentAware.class) static class BeanDefinitionRegistryPostProcessorConfiguration { }  @Component static class ProgrammaticBeanRegistryEnvironmentAware implements BeanDefinitionRegistryPostProcessor, EnvironmentAware {  private Environment environment;  @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { if (environment.matchesProfiles(\"prod\")) { registry.registerBeanDefinition(\"withCallback\", BeanDefinitionBuilder.genericBeanDefinition(WithCallback.class).setPrimary(true).setLazyInit(false) .setScope(\"prototype\").getBeanDefinition()); } }  @Override public void setEnvironment(Environment environment) { this.environment = environment; } } }<\/code><\/pre>\n<p>\u0418 \u0442\u0443\u0442 \u0435\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u043d\u044e\u0430\u043d\u0441. <strong>\u0418 \u044d\u0442\u043e\u0442 \u043d\u044e\u0430\u043d\u0441 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d \u043a\u0430\u043a \u0434\u043b\u044f BeanRegistrar API, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f <\/strong><code><strong>BeanDefinitionRegistryPostProcessor<\/strong><\/code><strong>.<\/strong><\/p>\n<p>\u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b &#8212; \u0434\u0430, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c <code>Environment<\/code>. \u041d\u043e \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0442\u043e\u0442 Environment, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u043e\u043f\u044f\u0442\u044c \u0436\u0435, \u0432 \u0441\u0438\u043b\u0443 \u0442\u043e\u0433\u043e, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 <code>BeanFactoryPostProcessor<\/code>-\u044b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u043f\u043e\u043b\u043d\u044b\u043c. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u043e\u0434\u0443\u043b\u044c Spring \u0438\u043b\u0438 \u0432\u0430\u0448 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 <code>MutablePropertySource<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 lifecycle \u0431\u0438\u043d\u0430, \u0434\u0430\u0436\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0442\u043e \u044d\u0442\u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432, \u0443\u0432\u044b, \u0435\u0449\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u043a\u0438 <code>BeanDefinitionRegistryPostProcessor<\/code>.<\/p>\n<h3>Kotlin DSL. \u041c\u0435\u043b\u043e\u0447\u044c, \u0430 \u041f\u0440\u0438\u044f\u0442\u043d\u043e.<\/h3>\n<p>\u041c\u044b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Spring \u0410\u0439\u041e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u0443\u0436\u0435 \u043a\u0430\u043a-\u0442\u043e \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u043b\u0438 \u043f\u043e\u0441\u0442 \u043e \u0442\u043e\u043c, <a href=\"https:\/\/habr.com\/ru\/companies\/spring_aio\/articles\/912006\/\" rel=\"noopener noreferrer nofollow\">\u0447\u0442\u043e Spring Framework \u0438 JetBrains \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0430\u0440\u0442\u043d\u0451\u0440\u0441\u0442\u0432\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044f\u0437\u044b\u043a\u0430 Kotlin<\/a>. \u042d\u0442\u043e, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 Spring Framework \u0431\u044b\u043b\u0438 \u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043d\u043e\u0432\u044b\u0435 Kotlin DSL \u0434\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 API. \u042d\u0442\u043e \u043a\u043e\u0441\u043d\u0443\u043b\u043e\u0441\u044c \u0438 BeanRegistrar API. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043f\u0438\u0448\u0435\u0442 \u043d\u0430 Kotlin, \u0434\u043b\u044f \u043d\u043e\u0432\u043e\u0433\u043e BeanRegistrar API <a href=\"https:\/\/github.com\/spring-projects\/spring-framework\/blob\/main\/spring-beans\/src\/main\/kotlin\/org\/springframework\/beans\/factory\/BeanRegistrarDsl.kt\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u0432\u0435\u0437\u043b\u0438 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 BeanRegistrarDsl<\/a>.<\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e, \u043a\u0430\u043a \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c Kotlin DSL \u0432 Spring Framework \u0432\u043e\u043e\u0431\u0449\u0435, \u043b\u0438\u0448\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u043f\u043e\u0432\u0435\u0440\u0445 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e API<\/strong>. \u041e\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u043d\u043e\u0441\u0438\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 BeanRegistrar \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Kotlin \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u044f\u0442\u043d\u043e\u0439.<\/p>\n<h3>Spring AOT. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0412\u0430\u0436\u043d\u043e.<\/h3>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043d\u044e\u0430\u043d\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0432\u0430\u0436\u043d\u044b\u0439. \u041e \u043d\u0451\u043c \u044f \u0443\u0437\u043d\u0430\u043b \u043f\u043e\u0441\u043b\u0435 \u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0441 Juergen Hoeller-\u043e\u043c \u043d\u0430 <a href=\"https:\/\/2025.springio.net\/\" rel=\"noopener noreferrer nofollow\">Spring I\/O 2025 Barcelona<\/a>. \u042d\u043a\u0441\u043a\u043b\u044e\u0437\u0438\u0432 \u0434\u043b\u044f \u0412\u0430\u0441, \u0442\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u0442\u044c.<\/p>\n<p><strong>\u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u043e\u0432\u044b\u0439 API \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0436\u0438\u0437\u043d\u044c \u043f\u0440\u043e\u0435\u043a\u0442\u0443 Spring AOT<\/strong>. \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0432 \u043a\u0443\u0440\u0441\u0435 &#8212; Spring Framework \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0438 ramp up-\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 Spring \u0438 \u0442.\u043f. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0438 \u0446\u0435\u043b\u0438 \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u0443\u0435\u0442 Spring AOT. \u042d\u0442\u043e \u043d\u0435 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c Spring-\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0430 \u043e\u0431\u0449\u0435\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u043b\u044f AOT \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Spring Framework.<\/p>\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u0443\u044e Spring AOT \u043f\u0435\u0440\u0435\u0434 \u0441\u043e\u0431\u043e\u0439 \u0441\u0442\u0430\u0432\u0438\u0442, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0447\u0451\u0442\u043a\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u0442\u0435 \u0431\u0438\u043d\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0412\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. <strong>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, Spring AOT \u0431\u0443\u0434\u0435\u0442 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c classpath \u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u044b Bean Defnition-\u044b<\/strong>. \u041f\u043e \u0441\u0443\u0442\u0438, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f.\u00a0<\/p>\n<p>\u0418\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435. <strong>\u041e\u0434\u043d\u043e \u0438\u0437 \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0439 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e classpath, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c\u0441\u044f, \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439<\/strong>. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 Spring AOT, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 classpath-\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0431\u0438\u043b\u0434\u0430 \u0438 \u0443\u0436\u0435 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435.\u00a0<\/p>\n<p>\u0412\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a <code>BeanRegistrar<\/code> \u0438 \u043a \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 Spring AOT. \u0412\u0438\u0434\u0438\u0442\u0435 \u043b\u0438, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>BeanDefinition<\/code>-\u044b \u0447\u0435\u0440\u0435\u0437 <code><strong>BeanDefinitionRegistryPostProcessor<\/strong><\/code>, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e. \u041d\u0438\u043a\u0442\u043e \u043d\u0435 \u0441\u043f\u043e\u0440\u0438\u0442. \u041e\u0434\u043d\u0430\u043a\u043e, \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e <code><strong>BeanDefinitionRegistryPostProcessor<\/strong><\/code> \u2013 \u044d\u0442\u043e \u043e\u0431\u0449\u0438\u0439 API \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430 <code>BeanDefinitionRegistry<\/code>. <strong>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <\/strong><code><strong>BeanDefinitionRegistryPostProcessor<\/strong><\/code><strong> \u0435\u0449\u0435 \u043d\u0438 \u043e \u0447\u0451\u043c \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u0442. \u042d\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/strong>.\u00a0<\/p>\n<p>Spring AOT \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435, \u043f\u0443\u0442\u0451\u043c Annotation Processing-\u0430, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e APT \u0432\u0438\u0434\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code><strong>BeanDefinitionRegistryPostProcessor<\/strong><\/code>. \u041a\u0430\u043a\u043e\u0439 \u043e\u043d \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434? \u0414\u0430 \u043d\u0438\u043a\u0430\u043a\u043e\u0439, \u0438 APT \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0412\u0430\u0448\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0430 \u0447\u0442\u043e \u0436\u0435 \u0412\u044b \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0442\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u0442\u0435. \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434.<\/p>\n<p>\u0410 \u0441 <code>BeanRegistrar<\/code> \u0432\u0441\u0451 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435! \u042d\u0442\u043e \u0436\u0435 \u043f\u043e \u0441\u0443\u0442\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438 \u043c\u044b \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u043b\u044e\u0431\u044b\u0435 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c\u0441\u044f <strong>\u0442\u043e\u043b\u044c\u043a\u043e<\/strong> \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438: <strong>\u0435\u0441\u0442\u044c \u0447\u0451\u0442\u043a\u0438\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f<\/strong>. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0434\u043b\u044f APT \u0442\u0443\u043b\u0430 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442\u0441\u044f. \u0415\u043c\u0443 \u043b\u0438\u0448\u044c \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443 \u0432\u0441\u0435\u0445 <code>BeanRegistrar<\/code> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>register()<\/code> \u0438 \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e, \u043a\u043b\u0430\u0434\u0451\u0442 \u043d\u043e\u0432\u044b\u0435 \u0431\u0438\u043d\u044b \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442.\u00a0<\/p>\n<h4>\u0412\u044b\u0432\u043e\u0434\u044b<\/h4>\n<p>\u041a\u0430\u043a \u0438\u0442\u043e\u0433, \u043d\u043e\u0432\u044b\u0439 BeanRegistrar API \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0435\u0434\u0448\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u0438\u043a\u043e\u0432 \u0442\u0435\u043c, \u0447\u0442\u043e<\/p>\n<ol>\n<li>\n<p>\u041e\u043d \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>BeanFactoryPostProcessor<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0435\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 Kotlin DSL<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441\u043e Spring AOT. <\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u043e \u043c\u043d\u043e\u0433\u043e\u043c, \u0438\u0437-\u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430, BeanRegistrar \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0435\u0449\u0451 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c, \u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0434\u043b\u044f Spring Framework \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0439 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432 \u0446\u0435\u043b\u043e\u043c. \u0414\u043b\u044f \u0442\u0435\u0445 \u0436\u0435, \u043a\u0442\u043e \u043d\u0435 \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f Spring AOT, \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 API \u0434\u043b\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u0441 &#171;\u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u043c \u043b\u0438\u0446\u043e\u043c&#187; &#8212; \u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u0445\u043d\u0435\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u0438 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0439 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Kotlin.<\/p>\n<p>\u041a\u043e\u0434, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435, <a href=\"https:\/\/github.com\/spring-aio\/programmatic-bean-registration\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d \u043d\u0430 GitHub<\/a> \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 spring-aio.<\/p>\n<hr\/>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/502\/eb1\/321\/502eb1321e971ac8a8cb0c35db368176.png\" width=\"1560\" height=\"334\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/502\/eb1\/321\/502eb1321e971ac8a8cb0c35db368176.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/502\/eb1\/321\/502eb1321e971ac8a8cb0c35db368176.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043a \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u043d\u0430 Spring Boot \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c \u2014<a href=\"https:\/\/t.me\/+oBwACbkvJ19iODAy\" rel=\"noopener noreferrer nofollow\"> Spring \u0410\u0439\u041e<\/a>, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c \u0432 \u043a\u0443\u0440\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439 \u0438\u0437 \u043c\u0438\u0440\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Spring Boot \u0438 \u0432\u0441\u0435\u0433\u043e, \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043e.<\/p>\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\/915512\/\"> https:\/\/habr.com\/ru\/articles\/915512\/<\/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>\u0412 Spring Framework 7 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 API \u2014 BeanRegistry, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e Spring Data. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 <a href=\"https:\/\/t.me\/+QmrKn0wA8CdkNjAy\" rel=\"noopener noreferrer nofollow\">Spring \u0410\u0439\u041e<\/a>, <a href=\"https:\/\/t.me\/mipo256\" rel=\"noopener noreferrer nofollow\">\u041c\u0438\u0445\u0430\u0438\u043b\u0430 \u041f\u043e\u043b\u0438\u0432\u0430\u0445\u0438<\/a>, \u0432\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u043a Spring Data \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u0441 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u0440\u0430\u043d\u044c\u0448\u0435;<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0434\u043e BeanRegistrar, \u043a\u0430\u043a \u043e\u043d\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438;<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u043d\u043e\u0432\u044b\u0439 API \u0441\u0432\u044f\u0437\u0430\u043d \u0441\u043e Spring AOT.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 Spring Framework \u0438\u043d\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c Bean-\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438. \u0418 \u0432\u043e\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 Spring Framework 7 \u0437\u0430\u0432\u043e\u0437\u044f\u0442 \u043d\u043e\u0432\u044b\u0439 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u0440\u0430\u0437 \u044d\u0442\u043e \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u043d\u043e\u0432\u044b\u0439 \u0437\u0432\u0435\u0440\u044c, \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043c\u044b \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 Spring Data, \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443.<\/p>\n<p><strong>NOTE<\/strong>: Spring Framework 7 \u0435\u0449\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 GA \u0440\u0435\u043b\u0438\u0437\u0430, \u0438\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043e\u043d \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u0448\u0435\u043b. \u0412\u0441\u0435, \u0447\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f <strong>\u043d\u043e\u0432\u043e\u0433\u043e<\/strong> API \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a 7-\u043e\u043c\u0443 Milestone \u0440\u0435\u043b\u0438\u0437\u0443 Spring Framework. \u0412\u0440\u044f\u0434 \u043b\u0438 API \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043d\u043e \u0438\u043c\u0435\u0439\u0442\u0435 \u044d\u0442\u043e \u0432 \u0432\u0438\u0434\u0443.<\/p>\n<h3>Spring Data. \u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432<\/h3>\n<p>\u0427\u0442\u043e \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 Spring Data:<\/p>\n<ol>\n<li>\n<p>\u041e\u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041b\u044e\u0431\u043e\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043e\u0431\u044f\u0437\u0430\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043b\u0438\u0431\u043e<a href=\"http:\/\/org.springframework.data\" rel=\"noopener noreferrer nofollow\"> org.springframework.data<\/a>.repository.Repository, \u043b\u0438\u0431\u043e \u0435\u0433\u043e \u043f\u043e\u0442\u043e\u043c\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0443 \u0438 \u0434\u0430\u043b\u0435\u0435 Spring Data \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c classpath \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0448\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0438\u043d\u044b.<\/p>\n<\/li>\n<\/ol>\n<p><strong>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 &#8212; Spring Data \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0438\u043d\u043e\u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043e\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0432\u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435<\/strong>. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0448\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u044d\u0442\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u043d\u044b. \u041f\u043e\u0434 &#171;\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439&#187; \u0437\u0434\u0435\u0441\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0443 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432 &#171;\u043d\u0430 \u043b\u0435\u0442\u0443&#187;, \u0442\u043e \u0435\u0441\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043a\u0430\u043a\u043e\u0439-\u0442\u043e API Spring-\u0430, \u0430 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0435 \u043d\u0430\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 <code>@Component<\/code> \u0438 \u0435\u0451 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435.<\/p>\n<p>\u041d\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435, Spring Framework 7 \u0435\u0449\u0435 \u043d\u0435 \u0432\u044b\u0448\u0435\u043b, \u0432\u0441\u0435 \u0447\u0442\u043e \u0443 \u043d\u0430c \u0435\u0441\u0442\u044c, \u044d\u0442\u043e Milestone \u0440\u0435\u043b\u0438\u0437, \u043d\u043e<a href=\"https:\/\/github.com\/spring-projects\/spring-data-jpa\/tree\/1.3.5.RELEASE\" rel=\"noopener noreferrer nofollow\"> Spring Data JPA, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0443\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 10 \u043b\u0435\u0442<\/a>. \u041a\u0430\u043a \u0434\u043e \u044d\u0442\u043e\u0433\u043e Spring Data \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0431\u0438\u043d\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u0441\u0430\u043c\u0430 \u043f\u043e \u0441\u0435\u0431\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0431\u0438\u043d\u043e\u0432 \u0435\u0449\u0435 \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u044b\u0448\u043b\u0430?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h3>\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0411\u0438\u043d\u043e\u0432. \u0418\u0441\u0442\u043e\u043a\u0438<\/h3>\n<p>\u0412 \u0447\u0435\u043c \u0436\u0435 \u0434\u0435\u043b\u043e. <strong>\u0410 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0443\u0436\u0435 \u0431\u044b\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f (\u043e \u0442\u043e\u043c, \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0436\u0435 \u043d\u0430\u043c \u043d\u043e\u0432\u044b\u0439 API, \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435)<\/strong>.<\/p>\n<p>\u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0443\u0436\u0435 \u0434\u043e\u043b\u0433\u0438\u0435 \u0433\u043e\u0434\u044b \u0432 Spring Framework \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>SingletonBeanRegistry<\/code>. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u043e\u0432:<\/p>\n<pre><code class=\"java\">class MyFirst {  private final MySecond mySecond;  MyFirst(MySecond mySecond) { this.mySecond = mySecond; } }  class MySecond { }  class ProgrammaticBeanRegistrationApplicationTest {  @Test void testRegisterSingletonMethod() { GenericApplicationContext applicationContext = new GenericApplicationContext(); MySecond second = new MySecond();  applicationContext.getBeanFactory().registerSingleton(\"mySecond\", second); applicationContext.getBeanFactory().registerSingleton(\"myFirst\", new MyFirst(second));  applicationContext.refresh();  assertThat(applicationContext.containsBean(\"myFirst\")).isTrue(); assertThat(applicationContext.containsBean(\"mySecond\")).isTrue(); } }<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b &#8212; \u0447\u0435\u0433\u043e \u043c\u0443\u0434\u0440\u0438\u0442\u044c, \u0432\u043e\u0442 \u043e\u043d\u043e, \u0440\u0435\u0448\u0435\u043d\u0438\u0435. <strong>\u041d\u043e \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438<\/strong>. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0434\u0430\u043d\u043d\u044b\u0439 API \u043d\u0435 \u0434\u0430\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>BeanDefinition<\/code>. \u0414\u043b\u044f \u044f\u0441\u043d\u043e\u0441\u0442\u0438: <code>BeanDefinition<\/code> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0438\u043d\u0430, \u043d\u0430\u0431\u043e\u0440 \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<ol>\n<li>\n<p>Scope \u0431\u0438\u043d\u0430. \u0427\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 <em>Singleton<\/em>, \u043d\u043e \u0438 <em>Session<\/em> \u0438\u043d\u043e\u0433\u0434\u0430 \u0431\u044b\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u0435\u043d.<\/p>\n<\/li>\n<li>\n<p>Init \u043c\u0435\u0442\u043e\u0434\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0447\u044c \u043f\u0440\u043e <code>@PostConstruct<\/code> \u0438\u043b\u0438 \u043c\u0435\u0442\u043e\u0434 <code>afterPropertiesSet()<\/code>, \u0445\u043e\u0442\u044f \u0438 \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430.<\/p>\n<\/li>\n<li>\n<p><code>Primary<\/code>\/<code>Fallback<\/code> \u0444\u043b\u0430\u0433\u0438. \u0418\u0445, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 <code>@Primary<\/code> \u0438 <code>@Fallback<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e<\/p>\n<\/li>\n<\/ol>\n<p>\u0438 \u0442.\u0434.<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>SingletonBeanRegistry<\/code> \u0435\u0449\u0435 \u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e. \u041e\u043d\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0435 <code>@PostConstruct<\/code>\/<code>@PreDestroy<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u0438. <strong>\u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0431\u0438\u043d \u0443\u0436\u0435 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d<\/strong>. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 Singleton, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u0438\u0435 \u0432 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 <code>ApplicationContext<\/code>:<\/p>\n<pre><code class=\"java\">class WithCallback implements InitializingBean {  private boolean callbackCalled;  @Override public void afterPropertiesSet() throws Exception { System.out.println(\"Hey from the callback\"); callbackCalled = true; }  public boolean isCallbackCalled() { return callbackCalled; } }  class ProgrammaticBeanRegistrationApplicationTest {  @Test void testRegisterSingletonMethod_noCallbacksInvoked() { GenericApplicationContext applicationContext = new GenericApplicationContext();  applicationContext.getBeanFactory().registerSingleton(\"mySecond\", new WithCallback()); applicationContext.refresh();  assertThat(applicationContext.containsBean(\"mySecond\")).isTrue(); \/\/ \u0411\u0438\u043d-\u0442\u043e \u0435\u0441\u0442\u044c assertThat(applicationContext.getBean(\"mySecond\", WithCallback.class).isCallbackCalled()).isFalse(); \/\/ \u0410 \u043a\u043e\u043b\u043b\u0431\u0435\u043a \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d } }<\/code><\/pre>\n<p>\u041f\u043e \u0441\u0443\u0442\u0438, \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0434\u043b\u044f \u043d\u0430\u0441 \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0432\u0437\u044f\u0442\u044c \u0431\u0438\u043d \u0438\u0437 <code>BeanFactory<\/code>\/<code>ApplicationContext<\/code>-\u0430 \u0447\u0435\u0440\u0435\u0437 <code>getBean()<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<h3>\u041c\u044b \u041c\u043e\u0436\u0435\u043c \u041b\u0443\u0447\u0448\u0435! BeanDefinitionRegistry<\/h3>\n<p>\u041d\u0443 \u0445\u043e\u0440\u043e\u0448\u043e. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044f\u0441\u043d\u0430 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0430. \u0418 \u0442\u0443\u0442 \u0432 \u0434\u0432\u0435\u0440\u044c \u0441 \u043d\u043e\u0433\u0438 \u0432\u043b\u0430\u043c\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>BeanDefinitionRegistry<\/code>!<\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>BeanDefinitionRegistry<\/code> \u0442\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 Spring Framework \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u0430\u0432\u043d\u043e. <strong>\u0418 \u0434\u0430, \u0435\u0441\u043b\u0438 \u0412\u0430\u043c-\u0442\u0430\u043a\u0438 \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u0436\u0435 Spring Data \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0441\u0432\u043e\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438, \u043e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442 \u2013 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <\/strong><code><strong>BeanDefinitionRegistry<\/strong><\/code><strong>.<\/strong> \u0412\u043e\u0442<a href=\"https:\/\/github.com\/spring-projects\/spring-data-commons\/blob\/main\/src\/main\/java\/org\/springframework\/data\/repository\/config\/RepositoryConfigurationDelegate.java#L138\" rel=\"noopener noreferrer nofollow\"> \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432 Spring Data Commons<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 <code>BeanDefinition<\/code>-\u043e\u0432. \u0421\u0430\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u043a\u0441\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 <code>RepositoryFactorySupport<\/code>, \u043d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0437\u0430 \u0440\u0430\u043c\u043a\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0436\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 API <code>BeanDefinitionRegistry<\/code>:<\/p>\n<pre><code class=\"java\">class ProgrammaticBeanRegistrationApplicationTest {  @Test void testDynamicBeansRegistration_beanDefinitionRegistry() { GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext(ProgrammaticBeanRegistry.class);  WithCallback firstBean = applicationContext.getBean(\"withCallback\", WithCallback.class); WithCallback secondBean = applicationContext.getBean(\"withCallback\", WithCallback.class);  assertThat(firstBean.isCallbackCalled()).isTrue(); \/\/ \u041a\u043e\u043b\u043b\u0431\u0435\u043a\u0438 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438! assertThat(secondBean.isCallbackCalled()).isTrue();  assertThat(firstBean).isNotSameAs(secondBean); \/\/ \u0418 \u0431\u0438\u043d \u043d\u0430\u043c \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u043d\u0435 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435, prototype! }  @Component static class ProgrammaticBeanRegistry implements BeanDefinitionRegistryPostProcessor {  @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException { registry.registerBeanDefinition(\"withCallback\", BeanDefinitionBuilder.genericBeanDefinition(WithCallback.class).setPrimary(true).setLazyInit(false) .setScope(\"prototype\").getBeanDefinition()); } } }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0437\u0434\u0435\u0441\u044c \u0443\u0436\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0442\u043e\u043d\u043a\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 <code>BeanDefinition<\/code>-a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e \u043e\u0442\u043b\u0438\u0447\u043d\u043e. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e, \u0432 \u0442\u0435\u043e\u0440\u0438\u0438, \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>BeanDefinitionRegistry<\/code> \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u043e \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e <code>BeanDefinitionRegistryPostProcessor<\/code>.<a href=\"https:\/\/spring.io\/blog\/2017\/03\/01\/spring-tips-programmatic-bean-registration-in-spring-framework-5\" rel=\"noopener noreferrer nofollow\"> \u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0438\u0434\u0435\u043e \u043e\u0442 Josh-a Long-a<\/a>, Spring Framework Developer Advocate-\u0430, \u0433\u0434\u0435 \u043e\u043d \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0439 API \u0447\u0435\u0440\u0435\u0437 <code>BeanDefinitionRegistryPostProcessor<\/code>.<\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e init \u043c\u0435\u0442\u043e\u0434\u044b, scope-\u044b, primary, lazy-init \u2013 \u044d\u0442\u043e \u0432\u0441\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442<\/strong>. \u041f\u043e\u0447\u0435\u043c\u0443? \u0427\u0438\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u043a\u0446\u0438\u044e \u043d\u0438\u0436\u0435. \u0418 Spring Data \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u043e\u0442 API \u043f\u043e \u0441\u0435\u0439 \u0434\u0435\u043d\u044c. <strong>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442<\/strong> <strong>\u0432\u043e\u043f\u0440\u043e\u0441: \u201c\u0427\u0435\u043c \u043e\u043d \u043d\u0430\u043c \u043d\u0435 \u0443\u0433\u043e\u0434\u0438\u043b?\u201d<\/strong><\/p>\n<h3>\u041d\u043e\u0432\u044b\u0439 API. BeanRegistry<\/h3>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 Spring Framework 7, \u0443 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u0439 BeanRegistry API. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u043e\u0447\u0432\u0443 \u0434\u043b\u044f \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0440\u0430\u0437\u0443 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>BeanRegistry<\/code> \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438:<\/p>\n<pre><code class=\"java\">class ProgrammaticBeanRegistrationApplicationTest {  @Test void testDynamicBeansRegistration_beanRegistry() { AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( BeanRegistryConfiguration.class);  BeanDefinition beanDefinition = applicationContext.getBeanDefinition(\"prodBean\");  assertThat(beanDefinition.getScope()).isEqualTo(\"prototype\"); assertThat(beanDefinition.isPrimary()).isTrue(); assertThat(beanDefinition.isLazyInit()).isTrue(); }  \/**  * application.properties \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:  * &lt;p&gt;  * &lt;pre class=\"code\"&gt;  *   spring.profiles.active=prod  * &lt;\/pre&gt;  *\/ @Configuration @PropertySource(\"application.properties\") @Import(MyBeanRegistry.class) static class BeanRegistryConfiguration { }  @Component static class MyBeanRegistry implements BeanRegistrar {  @Override public void register(BeanRegistry registry, Environment env) { if (env.matchesProfiles(\"dev|qa\")) { registry.registerBean(\"testBean\", WithCallback.class, spec -&gt; spec.fallback().lazyInit().order(Ordered.HIGHEST_PRECEDENCE)); } else if (env.matchesProfiles(\"prod\")) { registry.registerBean(\"prodBean\", WithCallback.class, spec -&gt; spec.primary().prototype().lazyInit()); } } } }<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e, \u0442\u043e, \u0447\u0442\u043e \u0434\u043b\u044f \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043b\u0438\u0448\u044c API \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0445 \u043d\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0418\u043d\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0430\u043c \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 <code>BeanDefinitionRegistryPostProcessor<\/code> \u0438\u043b\u0438 \u0442.\u043f. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0443 \u043d\u0430\u0441 \u0437\u0434\u0435\u0441\u044c \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 <code>Environment<\/code> \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <code>@Value<\/code>. \u041a\u0441\u0442\u0430\u0442\u0438, \u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 <code>BeanDefinitionRegistryPostProcessor<\/code>?<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0434\u0430\u0434\u0438\u043c\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c <code>Environment<\/code> \u0432 <code>BeanDefinitionRegistryPostProcessor<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0436\u0435 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044e \u0431\u0438\u043d\u043e\u0432 \u0441 \u0443\u043f\u043e\u0440\u043e\u043c \u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437<a href=\"http:\/\/application.properties\" rel=\"noopener noreferrer nofollow\"> application.properties<\/a>? <strong>\u0414\u0430, \u043c\u043e\u0436\u043d\u043e, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u044e\u0430\u043d\u0441.<\/strong><\/p>\n<p>\u041e\u043d \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c <code>@Autowired Environment env;<\/code>. \u041f\u043e\u0447\u0435\u043c\u0443? \u0414\u0430 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e <code>BeanDefinitionRegistryPostProcessor<\/code> \u2013 \u044d\u0442\u043e <code>BeanFactoryPostProcessor<\/code>. \u0417\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u0435, <code><\/code><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-462439","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/462439","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=462439"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/462439\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=462439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=462439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=462439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}