зеркало из
				https://github.com/iharh/notes.git
				synced 2025-10-31 05:36:08 +02:00 
			
		
		
		
	m
Этот коммит содержится в:
		
							родитель
							
								
									f3da002004
								
							
						
					
					
						Коммит
						dcfa7f9b1f
					
				
							
								
								
									
										56
									
								
								pl/java/libfws/spring/features/internals/proxy.txt
									
									
									
									
									
										Обычный файл
									
								
							
							
						
						
									
										56
									
								
								pl/java/libfws/spring/features/internals/proxy.txt
									
									
									
									
									
										Обычный файл
									
								
							| @ -0,0 +1,56 @@ | |||||||
|  | 2024 | ||||||
|  | SpringDeveloper - Long - Spring Tips: Proxies of 27:17 | ||||||
|  |     https://www.youtube.com/watch?v=pvE4pwyzkpE | ||||||
|  | 
 | ||||||
|  |     static class MyBeanPostProcessor implements BeanPostProcessor { | ||||||
|  |       @Override | ||||||
|  |       public Object postProcessAfterInitialization(Object target, String beanName) throws BeansException { | ||||||
|  |         var proxyInstance = (SomeService) Proxy.newProxyInstance(...classloader, | ||||||
|  |           new Class[]{defaultCustomer.getClass.getInterfaces()}, | ||||||
|  |             @Override | ||||||
|  |             public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||||||
|  |               var result = method.invoke(defaultCustomer, args);  // call method on an impl, not on a proxy instance itself | ||||||
|  |               return result; | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |         var pf = new ProxyFactory(); | ||||||
|  |         pf.setInterfaces(target.getClass().getInterfaces()); | ||||||
|  |         pf.setTarget(target); | ||||||
|  |         pf.addAdvice(new MethodInterceptor() { | ||||||
|  |           @Override | ||||||
|  |           public Object invoke(MethodInvocation invocation) throws Throwable { | ||||||
|  |             Method method = invocation.getMethod(); | ||||||
|  |             Object[] arguments = invocation.getArguments(); | ||||||
|  |             return method.invoke(target, arguments); | ||||||
|  |           } | ||||||
|  |         }); | ||||||
|  |         return pf.getProxy(getClass().getClassLoader()); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |          | ||||||
|  |     static class ProxyBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor { | ||||||
|  |       @Override | ||||||
|  |       public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { | ||||||
|  |         return new BeanFactoryInitializationAotContribution() { | ||||||
|  |           @Override | ||||||
|  |           public void applyTo(GenerationContext generationContext, BeanFactoryInitializationCode beanFactoryInitializationCode) { | ||||||
|  |             generationContext.getRuntimeHints().proxies() | ||||||
|  |               .registerJdkProxy(CustomerService.class, | ||||||
|  |                 org.springframework.aop.SpringProxy.class, | ||||||
|  |                 org.springframework.aop.framework.Advised.class, | ||||||
|  |                 org.springframework.core.DecoratingProxy.class | ||||||
|  |               ); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     check classes: | ||||||
|  |     AdvisedSupport | ||||||
|  |     DefaultAopProxyFactory | ||||||
|  |         createAopProxy - returns either JdkDynamicAopProxy or  | ||||||
|  |         ObjenesisCglibAopProxy - the only way to proxy concrete types | ||||||
|  |     ProxyCreatorSupport, | ||||||
|  |     ClassUtils | ||||||
|  | 2023 | ||||||
|  | https://habr.com/ru/articles/750894/ | ||||||
| @ -1,2 +0,0 @@ | |||||||
| 2023 |  | ||||||
| https://habr.com/ru/articles/750894/ |  | ||||||
		Загрузка…
	
	
			
			x
			
			
		
	
		Ссылка в новой задаче
	
	Block a user
	 Ihar Hancharenka
						Ihar Hancharenka