关于自定义注解与注解之间存在的问题

项目场景:

springboot+mybaits+oracle
项目当中创建了自定义注解,用来对用户的功能模块进行权限配置。
代码当中使用了 ApplicationContext 来获取自定义扫描有哪些类 代码如下:applicationContext.getBeansWithAnnotation(自定义注解.class);

问题描述:

在项目进行启动时,对用户功能模块权限进行初始化,初始化需要对使用了自定义注解的方法进行扫描,问题就出现在扫描不到使用过自定义注解的方法。错误信息如下:

[2021-04-01 11:49:44] [ ERROR] com.bi.sys.utils.listener.ApplicationStartedListener [51] - null
java.lang.NullPointerException: null
	at com.bi.sys.service.impl.BiSysPermissionServiceImpl.permissionInit(BiSysPermissionServiceImpl.java:120)
	at com.bi.sys.service.impl.BiSysPermissionServiceImpl$$FastClassBySpringCGLIB$$1ba34bfa.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
	at com.bi.sys.service.impl.BiSysPermissionServiceImpl$$EnhancerBySpringCGLIB$$6f485c.permissionInit(<generated>)
	at com.bi.sys.utils.listener.ApplicationStartedListener.onApplicationEvent(ApplicationStartedListener.java:41)
	at com.bi.sys.utils.listener.ApplicationStartedListener.onApplicationEvent(ApplicationStartedListener.java:22)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
	at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:102)
	at org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java:71)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
	at com.bi.sys.BISysUserApplication.main(BISysUserApplication.java:14)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

原因分析:

对 @Transactional 进行删除,然后再重新启动项目,问题消除了。

解决方案:

删除 @Transactional,后面又遇到在使用nacos时使用注解 @RefreshScope 来实现实时刷新,发现又出现了这个问题,于是就把需要实时更新的变量提取出来单独创建一个类,来避免和自定义注解一起使用。

在使用 springboot项目中使用 @Aspect 来实现全局日志记录的时候也出现了该问题,后来替换使用过滤器来完成日志的全局记录。

**

有大佬知道原因跪求解答

**

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值