Java EL1057E:没有在上下文中注册bean解析器来解析对bean的访问
我一直在尝试使用多个索引编写Elasticsearch。目前我已经安装了SpringV5.2.3.RELEASE和SpringBootV2.2.4.RELEASE 我发现了几个解决方案,允许使用Spring的SPEL技术使用多个索引,但我无法使其工作 我目前拥有以下文件: ElasticDBConfig.javaJava EL1057E:没有在上下文中注册bean解析器来解析对bean的访问,java,spring,
elasticsearch,javabeans,spring-el,Java,Spring,
elasticsearch,Javabeans,Spring El,我一直在尝试使用多个索引编写Elasticsearch。目前我已经安装了SpringV5.2.3.RELEASE和SpringBootV2.2.4.RELEASE 我发现了几个解决方案,允许使用Spring的SPEL技术使用多个索引,但我无法使其工作 我目前拥有以下文件: ElasticDBConfig.java package edu.unifi.disit.datamanager.config; @Configuration @EnableTransactionManagement @Ena
package edu.unifi.disit.datamanager.config;
@Configuration
@EnableTransactionManagement
@EnableElasticsearchRepositories(basePackages = { "edu.unifi.disit.datamanager.datamodel.elasticdb"})
public class ElasticDBDbConfig {
@Value("${elasticsearch.protocol}")
private String esProtocol;
@Value("${elasticsearch.host}")
private String esHost;
@Value("${elasticsearch.port}")
private int esPort;
@Value("${elasticsearch.clustername}")
private String esClusterName;
@Bean(destroyMethod = "close")
public RestHighLevelClient elasticsearchClient() {
return new RestHighLevelClient(RestClient.builder(new HttpHost(esHost,esPort,esProtocol)));
}
@Bean
public ElasticsearchRestTemplate elasticsearchTemplate() {
ElasticsearchRestTemplate elasticsearchTemplate = new
ElasticsearchRestTemplate(elasticsearchClient());
elasticsearchTemplate.putMapping(KPIElasticValue.class);
return elasticsearchTemplate;
}
ConfigIndexBean.java
package edu.unifi.disit.datamanager.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Configuration
@Component("configIndexBean")
public class ConfigIndexBean {
@Value("${elasticsearch.dummyIndex}")
private String indexName;
public String getIndexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
}
package edu.unifi.disit.datamanager.config;
public class ConfigIndexBean {
private static String indexName = "dummy";
public static final String getIndexName() {
return indexName;
}
public static void setIndexName(String indexName) {
ConfigIndexBean.indexName = indexName;
}
}
KPIElasticValue.java
package edu.unifi.disit.datamanager.datamodel.elasticdb;
@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
@JsonSerialize(using = KPIElasticValueSerializer.class)
@JsonDeserialize(using = KPIElasticValueDeserializer.class)
@ComponentScan(basePackages = "edu.unifi.disit.datamanager.config")
@Document(type = "_doc", indexName = "#{@configIndexBean.getIndexName()}")
public class KPIElasticValue {
你知道吗
我也尝试
@Document(type = "_doc", indexName = "#{configIndexBean.getIndexName()}")
@Document(type = "_doc", indexName = "#{configIndexBean.indexName}")
例外情况是:
EL1057E:没有在上下文中注册bean解析程序来解析对bean'configIndexBean'的访问。我是这样解决的:
ConfigIndexBean.setIndexName("newindex");
ConfigIndexBean.java
package edu.unifi.disit.datamanager.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
@Configuration
@Component("configIndexBean")
public class ConfigIndexBean {
@Value("${elasticsearch.dummyIndex}")
private String indexName;
public String getIndexName() {
return indexName;
}
public void setIndexName(String indexName) {
this.indexName = indexName;
}
}
package edu.unifi.disit.datamanager.config;
public class ConfigIndexBean {
private static String indexName = "dummy";
public static final String getIndexName() {
return indexName;
}
public static void setIndexName(String indexName) {
ConfigIndexBean.indexName = indexName;
}
}
以及KPIElasticValue.java上的注释:
@Document(type = "_doc",indexName = "#
{T(edu.unifi.disit.datamanager.config.ConfigIndexBean).getIndexName()}")
在服务中,在调用存储库之前,我更改索引如下:
ConfigIndexBean.setIndexName("newindex");
你的意思是,你有索引app-logs-1、app-logs-2、app-logs-3,你想请求它们,因为它们是单个索引?不,我有一些索引依赖于通过API获得的值。基于这些值,我想通过ConfigIndexBean类的setter更改索引,并通过存储库在正确的索引上写入。实际上没有办法。我可以在更高的层次上解决这个问题,您必须通过简单的
if(dispatchToIndexA){use Document}else{DocumentB}
或通过实现自己的PostBean处理器和动态管理正确的索引来发送请求以批准索引。