From dcfa7f9b1f8587cad1b913d2488c1c20ce8c7e9b Mon Sep 17 00:00:00 2001 From: Ihar Hancharenka Date: Wed, 8 Jan 2025 15:51:02 +0300 Subject: [PATCH] m --- .../{ => features}/internals/articles.txt | 0 .../internals/presentations.txt | 0 .../spring/features/internals/proxy.txt | 56 +++++++++++++++++++ pl/java/libfws/spring/features/proxy.txt | 2 - 4 files changed, 56 insertions(+), 2 deletions(-) rename pl/java/libfws/spring/{ => features}/internals/articles.txt (100%) rename pl/java/libfws/spring/{ => features}/internals/presentations.txt (100%) create mode 100644 pl/java/libfws/spring/features/internals/proxy.txt delete mode 100644 pl/java/libfws/spring/features/proxy.txt diff --git a/pl/java/libfws/spring/internals/articles.txt b/pl/java/libfws/spring/features/internals/articles.txt similarity index 100% rename from pl/java/libfws/spring/internals/articles.txt rename to pl/java/libfws/spring/features/internals/articles.txt diff --git a/pl/java/libfws/spring/internals/presentations.txt b/pl/java/libfws/spring/features/internals/presentations.txt similarity index 100% rename from pl/java/libfws/spring/internals/presentations.txt rename to pl/java/libfws/spring/features/internals/presentations.txt diff --git a/pl/java/libfws/spring/features/internals/proxy.txt b/pl/java/libfws/spring/features/internals/proxy.txt new file mode 100644 index 000000000..f30b4165c --- /dev/null +++ b/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/ diff --git a/pl/java/libfws/spring/features/proxy.txt b/pl/java/libfws/spring/features/proxy.txt deleted file mode 100644 index b40baa87a..000000000 --- a/pl/java/libfws/spring/features/proxy.txt +++ /dev/null @@ -1,2 +0,0 @@ -2023 -https://habr.com/ru/articles/750894/