0
我正在使用cassandra作爲其存儲庫的jhipster項目。現在我也想將elasticsearch與同一個項目集成。但是得到的錯誤似乎是cassandra試圖讀@Document作爲它的註釋。Elasticsearch與cassandra集成
Caused by: org.springframework.data.cassandra.mapping.VerifierMappingExceptions: com.shoptell.backoffice.repository.dto.IndexedMergeProductInfoDTO:
Cassandra entities must have the @Table, @Persistent or @PrimaryKeyClass Annotation
at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntityMetadataVerifier.verify(BasicCassandraPersistentEntityMetadataVerifier.java:45)
at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity.verify(BasicCassandraPersistentEntity.java:198)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:297)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:256)
at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:372)
at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.initialize(BasicCassandraMappingContext.java:79)
at org.springframework.data.mapping.context.AbstractMappingContext.afterPropertiesSet(AbstractMappingContext.java:362)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 144 more
IndexedMergeProductInfoDTO.java
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
@Document(indexName="mergeIndex",type="indexMergeProductInfo")
public class IndexedMergeProductInfoDTO {
@Id
private String id;
private String name;
private String metaCategory;
private String categoryName;
private String subCategoryName;
private String productBrand;
private String productSubBrand;
private String series;
private String model;
CassandraDataAutoConfiguration.java
import com.datastax.driver.core.Cluster;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
import org.springframework.data.cassandra.config.CassandraSessionFactoryBean;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.core.CassandraAdminOperations;
import org.springframework.data.cassandra.core.CassandraAdminTemplate;
import org.springframework.data.cassandra.mapping.BasicCassandraMappingContext;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
import javax.inject.Inject;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration} for Spring Data's Cassandra support.
* <p/>
* Registers a {@link org.springframework.data.cassandra.config.CassandraSessionFactoryBean} a {@link org.springframework.data.cassandra.core.CassandraAdminOperations} a {@link org.springframework.data.cassandra.mapping.CassandraMappingContext} and a
* {@link org.springframework.data.cassandra.convert.CassandraConverter} beans if no other beans of the same type are configured.
* <p/>
*/
@Configuration
@ConditionalOnClass({Cluster.class, CassandraAdminOperations.class})
@EnableConfigurationProperties(CassandraProperties.class)
@AutoConfigureAfter(CassandraAutoConfiguration.class)
public class CassandraDataAutoConfiguration {
@Inject
BeanFactory beanFactory;
@Inject
private CassandraProperties properties;
@Inject
private Cluster cluster;
@Bean
@ConditionalOnMissingBean
public CassandraSessionFactoryBean session() throws Exception {
CassandraSessionFactoryBean session = new CassandraSessionFactoryBean();
session.setCluster(this.cluster);
session.setConverter(cassandraConverter());
session.setKeyspaceName(properties.getKeyspaceName());
return session;
}
@Bean
@ConditionalOnMissingBean
public CassandraAdminOperations cassandraTemplate() throws Exception {
return new CassandraAdminTemplate(session().getObject(), cassandraConverter());
}
@Bean
@ConditionalOnMissingBean
public CassandraMappingContext cassandraMapping() throws ClassNotFoundException {
BasicCassandraMappingContext bean = new BasicCassandraMappingContext();
bean.setInitialEntitySet(CassandraEntityClassScanner.scan(AutoConfigurationPackages.get(beanFactory)));
bean.setBeanClassLoader(beanFactory.getClass().getClassLoader());
return bean;
}
@Bean
@ConditionalOnMissingBean
public CassandraConverter cassandraConverter() throws Exception {
return new MappingCassandraConverter(cassandraMapping());
}
}
什麼事情需要做,以獲得elasticsearch運行?
我評論以下兩行和它完美的罰款。 bean.setInitialEntitySet(CassandraEntityClassScanner.scan(AutoConfigurationPackages.get(Bean工廠))); bean.setBeanClassLoader(beanFactory.getClass()。getClassLoader()); –