在null上找不到Spring数据-SpelEvaluationException-属性或字段
我正在尝试使用Spring表达式语言从Spring数据ElasticSearch动态配置注释。我尝试的解决方案在我的案例中产生了以下错误:在null上找不到Spring数据-SpelEvaluationException-属性或字段,spring,spring-data,spring-data-elasticsearch,Spring,Spring Data,spring Data Elasticsearch,我正在尝试使用Spring表达式语言从Spring数据ElasticSearch动态配置注释。我尝试的解决方案在我的案例中产生了以下错误: Caused by: SpelEvaluationException: EL1007E: Property or field 'DbCreatorIndexNameConfig' cannot be found on null 有关注释为: @ComponentScan(basePackageClasses = DbCreatorIndexNameConf
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通过
newannotationConfigApplicationContext(EsSpringTemplate.class,DbCreatorIndexNameConfig.class)连接到应用程序上下文中代码>
- 我已经确保春天知道需要的豆子。它们出现在
annotationConfigApplicationContext.getBeanDefinitionNames()
- indexName必须是一个常量。因此,似乎只能使用SpEL
任何想法都将受到高度赞赏!谢谢 修改如下:-您必须使用“@”来访问spel中的bean
@Document(indexName = "#{@DbCreatorIndexNameConfig.indexName()}", type = "video",
shards = 1, replicas = 0)
如果问题没有解决,请告诉我。如果有,请将其标记为答案。谢谢,我注意到了这一点,但结果是另一个例外:
SpelEvaluationException:EL1057E:没有在上下文中注册bean解析器来解析对bean'DbCreatorIndexNameConfig'的访问。
我不知道这听起来是否荒谬,但您是否只尝试过使用@indexName?是的,在所有变体中。indexName、@indexName、indexName()、@indexName()。甚至尝试了一个构造函数:@Bean public DbCreatorIndexNameConfig DbCreatorIndexNameConfig()…
让我们来看看。