SpringBoot调⽤公共模块的⾃定义注解失效
项⽬结构如下:
我在 bi-common 公共模块⾥定义了⼀个⾃定义注解,实现AOP记录⽇志,bi-batch 项⽬已引⽤了 bi-common ,当在 bi-batch 使⽤注解的时候,没有报错,但是切⾯却失效。
⾃定义注解:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface JobLog {
}
切⾯实现:
/**
* 执⾏任务时记录⽇志
*/
@Aspectspringboot结构
@Component
@Order(1)
@Slf4j
public class JobLogAspect {
@Pointcut("@annotation(aoshu.bi.platformmon.annotation.JobLog)")
public void pointcut(){
}
@Before("pointcut()")
public void logStart(JoinPoint joinPoint){
log.info("开始执⾏"+ Signature().getName()+"任务,参数为:"+ Args()));
}
@After("pointcut()")
public void logEnd(JoinPoint joinPoint){
log.info(""+Signature().getName()+"⽅法运⾏后。。。@After");
}
}
注解使⽤:
/**
*  这⾥使⽤了⾃定义注解,却失效,但是没报错
*/
@JobLog
public Job createEsJob(String jobName){
(jobName)
.start(esLogJobStep.step())
.build();
}
解决⽅法
原因:其他⼯程没有扫描公共模块的包,没有扫描到注解的位置。
解决⽅法1:
在启动类加上公共模块的包路径,注意别忘记把原项⽬的包路径也加上
@SpringBootApplication(scanBasePackages ={
"aoshu.bi.platform.batch",
"aoshu.bi.platformmon"
})
解决⽅法2:
在配置类⾥导⼊该切⾯实现
@Import({
aoshu.bi.platformmon.aspect.JobLogAspect.class
})
@Configuration
public class BatchConfigure {
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。