java - 弹簧自动装配中的 ContextRefresher
问题描述
我有一个 java 应用程序,其中一个类具有 ContextRefresher 自动装配:
public abstract class AbstractConfigurationPersister implements IConfigurationPersister {
@Autowired
private ContextRefresher contextRefresher;
@Override
public void forceRefresh() {
contextRefresher.refresh();
}
}
这个自动装配的 bean 给我带来了日志中的问题,它说参数 1 有一个不满足的依赖关系。
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration':
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'application':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'ktc.tanalytics.prediction.PredictionBeanConfiguration':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'configurationService' defined in ktc.tanalytics.commons.CommonsBeanConfiguration:
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'zookeeperConfigurationPersister' defined in ktc.tanalytics.commons.CommonsBeanConfiguration:
Initialization of bean failed; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'contextRefresher' defined in class path resource [org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.class]:
Unsatisfied dependency expressed through method 'contextRefresher' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'refreshScope':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor'
defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]:
Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException
现在,我在 spring 中检查了 ContextRefresher 的代码(https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-context/src/main/java/org/springframework/ cloud/context/refresh/ContextRefresher.java),它接收两个参数。
我想 Spring 负责创建这个 ContextRefresher 对象,因为它基本上是@Autowired。但是,我不知道为什么日志中缺少参数 1
解决方案
Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException
当我关注上面的嵌套异常时,可能transactionAdvisor 是一个工厂方法,它试图创建一些东西,并且在创建时,它正在对空对象执行一些操作。
只需在您的代码中检查或调试方法: transactionAdvisor 。
推荐阅读
- php - 我需要成为 abel 来过滤一张桌子,谁能告诉我怎么了
- plotly - 为 jupyter lab 安装 plotly-extension 时出错
- git - GitHub - 如何在 2 个 GitHub 存储库之间实时同步?
- generics - Star 投影集合中的特定 KClass
- php - 在 codeigniter 中向会话变量添加新值
- android - 如何使用 OpenCV 处理自定义相机拍摄的图片
- lan - 当win pc连接到局域网路由器时停止响应
- reporting-services - ssrs 上的动态图
- go - Golang获取结构字段的字符串名称
- python - 减去数据帧值后恢复索引并附加零