In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to solve the custom annotation failure of SpringBoot calling common module". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the custom annotation failure of SpringBoot calling common module".
The structure of the custom annotation failure project that invokes the common module is as follows
I have defined a custom annotation in the bi-common common module to implement AOP logging. Bi-common has been referenced by the bi-batch project. When using annotations in bi-batch, there is no error, but the aspect is invalid.
Custom comments:
@ Target (ElementType.METHOD) @ Retention (RetentionPolicy.RUNTIME) public @ interface JobLog {}
Section implementation:
/ * * log when performing a task * / @ Aspect@Component@Order (1) @ Slf4jpublic class JobLogAspect {@ Pointcut ("@ annotation (aoshu.bi.platform.common.annotation.JobLog)") public void pointcut () {} @ Before ("pointcut ()") public void logStart (JoinPoint joinPoint) {log.info ("start execution" + joinPoint.getSignature (). GetName () + "task Parameter is: "+ Arrays.toString (joinPoint.getArgs () } @ After ("pointcut ()") public void logEnd (JoinPoint joinPoint) {log.info ("" + joinPoint.getSignature () .getName () + "method runs. @ After ");}}
The annotations use:
/ * * Custom annotations are used here, but fail, but no error is reported * / @ JobLog public Job createEsJob (String jobName) {return jobBuilderFactory.get (jobName) .start (esLogJobStep.step ()) .build ();} solution
Reason:
Other projects did not scan the packages of the common module and did not scan to the location of the annotations.
Solution 1:
Add the package path of the common module to the startup class, and don't forget to add the package path of the original project
@ SpringBootApplication (scanBasePackages = {"aoshu.bi.platform.batch", "aoshu.bi.platform.common"})
Solution 2:
Import the aspect implementation in the configuration class
@ Import ({aoshu.bi.platform.common.aspect.JobLogAspect.class}) @ Configurationpublic class BatchConfigure {} SpringBoot comment is not valid, step on the pit
Annotations for sub-module projects are not valid, including @ RestController @ EnableScheduling @ Scheduled, etc.
Solution method
Right-click on the sub-project, clean install, and you will find that an error has been reported. After the problem is solved, it will be fine.
Thank you for your reading, the above is the content of "how to solve the custom annotation invalidation of SpringBoot calling public module". After the study of this article, I believe you have a deeper understanding of how to solve this problem of SpringBoot calling public module custom annotation invalidation, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.