In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail "how to solve the problem of not getting native object annotations caused by Spring proxy object". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to solve the problem of not getting native object annotations caused by Spring proxy objects" can help you solve your doubts.
Problem description
When I accept mq messages, I need to make a limit on the number of retries. If I exceed the maxNum, I will send an email alarm and will not try again.
So I need to proxy the consumer object, and then if I exceed the number of exceptions, I directly return success and send a success message, but the way I get the consumer handler method is through method.getAnnotation (XXClient.class), then I return null.
Question sample code
Target class, I will define a test method here, in which to do some simple printing.
@ Componentpublic class TestBean {@ Anno public void test () {System.out.println ("test.");}}
The main purpose of proxy logic processing is to do a @ Around method override to ensure that the logic I inserted is output before calling the target method.
@ Target ({ElementType.METHOD}) @ Retention (RetentionPolicy.RUNTIME) public @ interface Anno {String key () default;} @ Aspect@Componentpublic class AnnoAspect {@ Around ("@ annotation (anno)") public Object anno (ProceedingJoinPoint point, Anno anno) throws Throwable {System.out.println ("anno invoke!"); return point.proceed ();}}
Call point, get bean through AnnotationConfigApplicationContext. Then get all the methods through getMethods (), and finally find the Method object annotated by Anno.
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext (BeanStart.class); TestBean bean = applicationContext.getBean (TestBean.class); Class
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.