{"id":313252,"date":"2020-11-16T21:01:29","date_gmt":"2020-11-16T21:01:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=313252"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=313252","title":{"rendered":"\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Spring Bean \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/ggNr\/\"><strong>&#171;\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 Spring Framework&#187;<\/strong><\/a><strong>.<\/strong><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0a2\/f59\/3d9\/0a2f593d9f102e37c292109d3c78c28e\" width=\"780\" height=\"439\"><figcaption><\/figcaption><\/figure>\n<hr>\n<p><a href=\"https:\/\/lofidewanto.blogspot.com\/2013\/06\/creating-spring-bean-dynamically-in.html\"><u>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f<\/u><\/a> \u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u0437\u0430 \u043f\u044f\u0442\u044c \u043b\u0435\u0442 \u0441\u0442\u0430\u043b\u0430 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0432 \u043c\u043e\u0435\u043c \u0431\u043b\u043e\u0433\u0435 (\u0431\u043e\u043b\u0435\u0435 9300 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432). \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b <a href=\"http:\/\/bit.ly\/2T4H8km\"><u>\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 Github<\/u><\/a>.<\/p>\n<figure class=\"float full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3b6\/95b\/683\/3b695b6831a263d658a2f07a99f1cbf9.png\" alt=\"\u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430 Spring Bean \u043d\u0430 Github\" title=\"\u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430 Spring Bean \u043d\u0430 Github\" width=\"576\" height=\"581\"><figcaption>\u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430 Spring Bean \u043d\u0430 Github<\/figcaption><\/figure>\n<\/p>\n<\/p>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u043d\u0433\u0435 \u043c\u0435\u043d\u044f \u0441\u043f\u0440\u043e\u0441\u0438\u043b\u0438: &#171;\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c Spring Bean \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f&#187;. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0431\u0438\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 properties-\u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>      1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<pre><code class=\"java\">package your.package;  @Retention(RetentionPolicy.RUNTIME) public @interface InjectDynamicObject { }<\/code><\/pre>\n<p>      2. \u0414\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442:<\/p>\n<pre><code class=\"java\">@Service public class CustomerServiceImpl {     private Customer dynamicCustomerWithAspect;          @InjectDynamicObject     public Customer getDynamicCustomerWithAspect() {         return this.dynamicCustomerWithAspect;     } }<\/code><\/pre>\n<p>      3. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0430\u0441\u043f\u0435\u043a\u0442 \u0441 Pointcut \u0438 Advise, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 2:<\/p>\n<pre><code class=\"java\">@Component @Aspect public class DynamicObjectAspect {     \/\/ This comes from the property file     @Value(\"${dynamic.object.name}\")     private String object;     @Autowired     private ApplicationContext applicationContext;          @Pointcut(\"execution(@com.lofi.springbean.dynamic.         InjectDynamicObject * *(..))\")     public void beanAnnotatedWithInjectDynamicObject() {     }     @Around(\"beanAnnotatedWithInjectDynamicObject()\")     public Object adviceBeanAnnotatedWithInjectDynamicObject(         ProceedingJoinPoint pjp) throws Throwable {            pjp.proceed();                  \/\/ Create the bean or object depends on the property file           Object createdObject = applicationContext.getBean(object);         return createdObject;     } }<\/code><\/pre>\n<p>      4. \u041f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0438\u0437 @InjectDynamicObject. \u0418\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 properties-\u0444\u0430\u0439\u043b\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Customer: CustomerOneImpl<\/code> \u0438 <code>CustomerTwoImpl:<\/code><\/p>\n<pre><code class=\"java\">@Component(\"customerOne\") public class CustomerOneImpl implements Customer {     @Override     public String getName() {         return \"Customer One\";     } }  application.properties dynamic.object.name=customerOne<\/code><\/pre>\n<p>      5. \u041f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@RunWith(SpringRunner.class) @SpringBootTest public class CustomerServiceImplTest {     @Autowired     private CustomerServiceImpl customerService;     @Test     public void testGetDynamicCustomerWithAspect() {         \/\/ Dynamic object creation         logger.info(\"Dynamic Customer with Aspect: \" +             customerService.getDynamicCustomerWithAspect()             .getName()); }<\/code><\/pre>\n<p>\u041d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435, \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e. \u0411\u0435\u0437 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0438 AspectJ, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0442\u044b\u0439 Spring. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Map \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0422\u0430\u043a \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 eXTra Client. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <a href=\"http:\/\/bit.ly\/2AZ2qJa\"><u>PluginsLocatorManager<\/u><\/a>. Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442 Map \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0431\u0438\u043d\u0430 (String) \u0438 \u0441\u0430\u043c\u0438\u043c \u0431\u0438\u043d\u043e\u043c.<\/p>\n<blockquote>\n<p><em>&#171;\u2026 \u0414\u0430\u0436\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 Map \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 String. \u0412 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 Map \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0435 \u0431\u0438\u043d\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0430 \u0432 \u043a\u043b\u044e\u0447\u0430\u0445 \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c\u0435\u043d\u0430 \u0431\u0438\u043d\u043e\u0432&#187;.<\/em><\/p>\n<\/blockquote>\n<p><em> \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441\u043c. <\/em><a href=\"http:\/\/bit.ly\/2ODz6eu\"><em><u>\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Spring<\/u><\/em><\/a><em>.<\/em><\/p>\n<pre><code class=\"java\">@Service public class CustomerServiceImpl {          \/\/ We inject the customer implementations into a Map     @Autowired     private Map&lt;String, Customer&gt; dynamicCustomerWithMap;          \/\/ This comes from the property file as a key for the Map     @Value(\"${dynamic.object.name}\")     private String object;     public Customer getDynamicCustomerWithMap() {         return this.dynamicCustomerWithMap.get(object);     } }<\/code><\/pre>\n<hr>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435 &#171;\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 Spring Framework&#187; \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c <a href=\"https:\/\/otus.pw\/ggNr\/\"><strong>\u0437\u0434\u0435\u0441\u044c.<\/strong><\/a><\/p>\n<\/blockquote>\n<\/div>\n<p> \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\/company\/otus\/blog\/528312\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/528312\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<blockquote>\n<p>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/ggNr\/\"><strong>&#171;\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 Spring Framework&#187;<\/strong><\/a><strong>.<\/strong><\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<hr>\n<p><a href=\"https:\/\/lofidewanto.blogspot.com\/2013\/06\/creating-spring-bean-dynamically-in.html\"><u>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f<\/u><\/a> \u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u0438\u043d\u043e\u0432 \u0437\u0430 \u043f\u044f\u0442\u044c \u043b\u0435\u0442 \u0441\u0442\u0430\u043b\u0430 \u0441\u0430\u043c\u043e\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0432 \u043c\u043e\u0435\u043c \u0431\u043b\u043e\u0433\u0435 (\u0431\u043e\u043b\u0435\u0435 9300 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432). \u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b <a href=\"http:\/\/bit.ly\/2T4H8km\"><u>\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 Github<\/u><\/a>.<\/p>\n<figure class=\"float full-width\"><figcaption>\u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430 Spring Bean \u043d\u0430 Github<\/figcaption><\/figure>\n<\/p>\n<\/p>\n<p>\u041e\u0434\u043d\u0430\u0436\u0434\u044b \u043d\u0430 \u0442\u0440\u0435\u043d\u0438\u043d\u0433\u0435 \u043c\u0435\u043d\u044f \u0441\u043f\u0440\u043e\u0441\u0438\u043b\u0438: &#171;\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u044c Spring Bean \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f&#187;. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0431\u0438\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 properties-\u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>      1. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<pre><code class=\"java\">package your.package;  @Retention(RetentionPolicy.RUNTIME) public @interface InjectDynamicObject { }<\/code><\/pre>\n<p>      2. \u0414\u0430\u043b\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0435 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442:<\/p>\n<pre><code class=\"java\">@Service public class CustomerServiceImpl {     private Customer dynamicCustomerWithAspect;          @InjectDynamicObject     public Customer getDynamicCustomerWithAspect() {         return this.dynamicCustomerWithAspect;     } }<\/code><\/pre>\n<p>      3. \u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0430\u0441\u043f\u0435\u043a\u0442 \u0441 Pointcut \u0438 Advise, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043d\u0430 \u0448\u0430\u0433\u0435 2:<\/p>\n<pre><code class=\"java\">@Component @Aspect public class DynamicObjectAspect {     \/\/ This comes from the property file     @Value(\"${dynamic.object.name}\")     private String object;     @Autowired     private ApplicationContext applicationContext;          @Pointcut(\"execution(@com.lofi.springbean.dynamic.         InjectDynamicObject * *(..))\")     public void beanAnnotatedWithInjectDynamicObject() {     }     @Around(\"beanAnnotatedWithInjectDynamicObject()\")     public Object adviceBeanAnnotatedWithInjectDynamicObject(         ProceedingJoinPoint pjp) throws Throwable {            pjp.proceed();                  \/\/ Create the bean or object depends on the property file           Object createdObject = applicationContext.getBean(object);         return createdObject;     } }<\/code><\/pre>\n<p>      4. \u041f\u0438\u0448\u0435\u043c \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0438\u0437 @InjectDynamicObject. \u0418\u043c\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432 properties-\u0444\u0430\u0439\u043b\u0435. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0434\u0432\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>Customer: CustomerOneImpl<\/code> \u0438 <code>CustomerTwoImpl:<\/code><\/p>\n<pre><code class=\"java\">@Component(\"customerOne\") public class CustomerOneImpl implements Customer {     @Override     public String getName() {         return \"Customer One\";     } }  application.properties dynamic.object.name=customerOne<\/code><\/pre>\n<p>      5. \u041f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442:<\/p>\n<pre><code class=\"java\">@RunWith(SpringRunner.class) @SpringBootTest public class CustomerServiceImplTest {     @Autowired     private CustomerServiceImpl customerService;     @Test     public void testGetDynamicCustomerWithAspect() {         \/\/ Dynamic object creation         logger.info(\"Dynamic Customer with Aspect: \" +             customerService.getDynamicCustomerWithAspect()             .getName()); }<\/code><\/pre>\n<p>\u041d\u043e \u0435\u0441\u0442\u044c \u0435\u0449\u0435, \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e. \u0411\u0435\u0437 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0438 AspectJ, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0442\u044b\u0439 Spring. \u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Map \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u0437 \u043d\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0422\u0430\u043a \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 eXTra Client. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <a href=\"http:\/\/bit.ly\/2AZ2qJa\"><u>PluginsLocatorManager<\/u><\/a>. Spring \u0430\u0432\u0442\u043e\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442 Map \u0441 \u0438\u043c\u0435\u043d\u0435\u043c \u0431\u0438\u043d\u0430 (String) \u0438 \u0441\u0430\u043c\u0438\u043c \u0431\u0438\u043d\u043e\u043c.<\/p>\n<blockquote>\n<p><em>&#171;\u2026 \u0414\u0430\u0436\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 Map \u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0436\u0435\u043a\u0442\u0438\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u0442\u0438\u043f \u043a\u043b\u044e\u0447\u0430 String. \u0412 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 Map \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0435 \u0431\u0438\u043d\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0430 \u0432 \u043a\u043b\u044e\u0447\u0430\u0445 \u2014 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c\u0435\u043d\u0430 \u0431\u0438\u043d\u043e\u0432&#187;.<\/em><\/p>\n<\/blockquote>\n<p><em> \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441\u043c. <\/em><a href=\"http:\/\/bit.ly\/2ODz6eu\"><em><u>\u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Spring<\/u><\/em><\/a><em>.<\/em><\/p>\n<pre><code class=\"java\">@Service public class CustomerServiceImpl {          \/\/ We inject the customer implementations into a Map     @Autowired     private Map&lt;String, Customer&gt; dynamicCustomerWithMap;          \/\/ This comes from the property file as a key for the Map     @Value(\"${dynamic.object.name}\")     private String object;     public Customer getDynamicCustomerWithMap() {         return this.dynamicCustomerWithMap.get(object);     } }<\/code><\/pre>\n<hr>\n<blockquote>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043a\u0443\u0440\u0441\u0435 &#171;\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043d\u0430 Spring Framework&#187; \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c <a href=\"https:\/\/otus.pw\/ggNr\/\"><strong>\u0437\u0434\u0435\u0441\u044c.<\/strong><\/a><\/p>\n<\/blockquote>\n<\/div>\n<p> \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\/company\/otus\/blog\/528312\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/528312\/<\/a><br \/><\/br><\/br><\/hr>\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-313252","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313252","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=313252"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/313252\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=313252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=313252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=313252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}