集成@EnableAsync后出现问题的记录

springboot 集成@EnableAsync后报错

问题描述:

在集成@EnableAsync后项目无法启动,出现下面的异常信息,在百度一番后说是依赖循环导致的,但未使用时没有出现此问题 (项目中之前已使用@Async注解,但未使用@EnableAsync,所以之前的异步操作并未生效)



 
o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Aspect': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': 
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': Injection of resource dependencies failed; nested 
exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service':
Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception
is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name '***Service': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***Service': Injection of resource 
dependencies failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name '***Service': Bean with name '***Service' has been injected into other beans 
[***Service,***Service] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager 
type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:325)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)

解决方式: 参考链接

  1. 注释掉全部@Async后测试是否能正常运行
  2. 能够正常启动后再进行排查是由哪块代码引起,排除后即可正常运行
  3. 可以定义异步处理Service类通过回调函数执行操作

同一个类调用另一个@Async的方法无法生效

解决方式:

将方法放到另一个Service再调用或者使用异步处理Service类通过回调函数执行操作

方法中声明@Transactional和@Async注解,异步操作生效(打印当前线程信息可看),但仍需等待线程执行完毕后返回结果(其中在测试过程中加了代码段使其睡眠30s验证是否存在此问题)

问题描述:

在controller调用的service中调用了其他service中的异步方法后,异步操作生效,但仍需等待异步操作线程执行完毕后才能返回结果(此时有将查询的jpa对象传入其他service中的异步方法)

解决方式:

1.可以将查询和修改放在同一个异步方法操作
2.当前jpa环境下,仍使用原来的方式(实参为查询后的持久化对象),需要将当前查询的持久化对象移除管理.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值