Java 映射异常:无法';在实现AbstractElasticsearchConfiguration时找不到持久性
我想为我的对象following和answer实现自定义转换器,但是当我运行该项目时,我收到MappingException:找不到类型类TransactionElistic的PersistentEntity 这是我的配置Java 映射异常:无法';在实现AbstractElasticsearchConfiguration时找不到持久性,java,spring-boot,
spring-data-elasticsearch,Java,Spring Boot,
spring Data Elasticsearch,我想为我的对象following和answer实现自定义转换器,但是当我运行该项目时,我收到MappingException:找不到类型类TransactionElistic的PersistentEntity 这是我的配置 @Configuration public class ElasticConfig extends AbstractElasticsearchConfiguration { @Value("$elasticUrl") private S
@Configuration
public class ElasticConfig extends AbstractElasticsearchConfiguration {
@Value("$elasticUrl")
private String elasticUrl;
@Override
public RestHighLevelClient elasticsearchClient() {
return RestClients.create(ClientConfiguration.create(elasticUrl)).rest();
}
@Bean
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(), new DefaultConversionService());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
@Bean
@Override
public ElasticsearchCustomConversions elasticsearchCustomConversions() {
return new ElasticsearchCustomConversions(Arrays.asList(new TransactionToMapConverter(), new MapToTransactionConverter()));
}
}
@WritingConverter
public class TransactionToMapConverter implements Converter<TransactionElastic, Map<String, Object>> {
@Override
public Map<String, Object> convert(TransactionElastic tradeTransaction) {
Map<String, Object> target = new HashMap<>();
target.put("id", tradeTransaction.getId());
target.put("portfolio_name", tradeTransaction.getPortfolioName());
target.put("settl_date", tradeTransaction.getSettlDate());
return target;
}
}
@ReadingConverter
public class MapToTransactionConverter implements Converter<Map<String, Object>, TransactionElastic> {
@Override
public TransactionElastic convert(Map<String, Object> map) {
TransactionElastic t = new TransactionElastic();
t.setPortfolioName(map.get("portfolio_name").toString());
t.setId((Long) map.get("id"));
return t;
}
}
@Document(indexName = "transactions")
public class TransactionElastic {
@Id
private Long id;
@Field(name = "portfolio_name", type = FieldType.Text)
private String portfolioName;
@Field(name = "settl_date", type = FieldType.Date)
private Date settlDate;
@Field(name = "trscn_status", type = FieldType.Text)
private String trscnStatus;
// getters and setters here
}
注册转换器日志
o.s.data.convert.CustomConversions - Registering converter from class com.portal.domain.TransactionElastic to interface java.util.Map as writing converter although it doesn't convert to a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.data.convert.CustomConversions - Registering converter from interface java.util.Map to class com.portal.domain.TransactionElastic as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.data.convert.CustomConversions - Registering converter from class org.springframework.data.geo.Point to interface java.util.Map as writing converter although it doesn't convert to a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.data.convert.CustomConversions - Registering converter from interface java.util.Map to class org.springframework.data.geo.Point as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.data.convert.CustomConversions - Registering converter from class org.springframework.data.elasticsearch.core.geo.GeoPoint to interface java.util.Map as writing converter although it doesn't convert to a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.data.convert.CustomConversions - Registering converter from interface java.util.Map to class org.springframework.data.elasticsearch.core.geo.GeoPoint as reading converter although it doesn't convert from a store-supported type! You might wanna check you annotation setup at the converter implementation.
o.s.b.a.o.j.JpaBaseConfiguration$JpaWebConfiguration - spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
Spring启动版本2.2.1
弹簧数据弹性搜索3.2.1
Elasticsearch版本6.4.0
什么可能导致问题?我遗漏了什么吗?我认为它无法找到实体。请在
AbstractElasticsearchConfiguration
中扩展以下方法:
@Override
protected Collection<String> getMappingBasePackages() {
//Provide list of your packages where you have entities.
}
@覆盖
受保护的集合getMappingBasePackages(){
//提供您拥有实体的软件包列表。
}
你能发布stacktrace吗?嗨@SimonMartinelli,我已经更新了问题,添加了StackTrace您的包结构是什么样子的?com.portal.domain-for@Document objects com.portal.search-elasticsearch repositories com.portal.service-for service interfaces and implementation com.portal.config-with configs com.portal.converter-with convertersAnd,其中包是SpringBootApplication?将我的配置更新为遵循@Override protected Collection getMappingBasePackages(){return Collections.singletonList(“com.meritkapital.portal.domain”);}但仍然有相同的例外我还建议尝试创建一个简单的配置bean,而不是扩展AbstractElasticsearchConfiguration,因为它正在禁用一些自动配置。与其扩展它,不如创建一个配置bean,并根据需要创建方法级bean。谢谢您的建议。试图在配置中只保留Elasticsearch CustomConversions方法bean,但没有帮助。
@Override
protected Collection<String> getMappingBasePackages() {
//Provide list of your packages where you have entities.
}