当前位置:   article > 正文

SpringBoot中的静态方法如何获取bean_springboot 静态方法获取bean

springboot 静态方法获取bean

目录

SpringBoot中的静态方法获取bean的三种方案

方式一 注解@PostConstruct

方式二 启动类ApplicationContext

方式三 手动注入ApplicationContext


前言:在开发过程中,当在静态方法内调用bean的时候会遇到以下类型错误,均是使用不当造成的

ps:不看错误可以直接跳转标题“SpringBoot中的静态方法获取bean的三种方案

错误1:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDetailInfoController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDetailServiceFactory': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'WJOrderDetailService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shopInfoHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wareInfoHelper': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'wareButtonHelper' defined in URL [jar:file:xxx/WEB-INF/lib/xxx-1.0-SNAPSHOT.jar!/com/xxx/mti/order/web/service/helpers/ware/WareButtonHelper.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: @Resource annotation is not supported on static fields
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(Com

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/798435
推荐阅读
相关标签
  

闽ICP备14008679号