【发布时间】:2018-02-06 15:34:51
【问题描述】:
我正在尝试使用 Spring 表达式语言从 Spring Data ElasticSearch 动态配置注释。我尝试的解决方案(this 和 this)在我的情况下会产生以下错误:
Caused by: SpelEvaluationException: EL1007E: Property or field
'DbCreatorIndexNameConfig' cannot be found on null
有问题的注释是:
@ComponentScan(basePackageClasses = DbCreatorIndexNameConfig.class)
@Document(indexName = "#{DbCreatorIndexNameConfig.indexName()}", type = "video",
shards = 1, replicas = 0)
public class Video implements EsModel {
//...
有问题的 bean:
@Configuration("DbCreatorIndexNameConfig")
@ComponentScan(basePackageClasses = Video.class)
public class DbCreatorIndexNameConfig {
@Value("video_default")
public String indexName;
@Bean
public String indexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
}
注意事项:
我已确定,该 bean 已通过
new AnnotationConfigApplicationContext(EsSpringTemplate.class, DbCreatorIndexNameConfig.class);连接到应用程序上下文中我已确保 Spring 知道所需的 bean。他们出现在
annotationConfigApplicationContext.getBeanDefinitionNames()。- indexName 必须是一个常数。因此,似乎只能使用 SpEL
非常感谢任何想法!谢谢!
【问题讨论】:
标签: spring spring-data spring-data-elasticsearch