我有以下Spring数据弹性搜索的实体定义
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.util.List;
@Document(indexName = "ExcpetionStack", type="stack")
public class StateObject {
@Id
private String id;
@Field(type=FieldType.String)
private String exceptionName;
@Field(type=FieldType.String)
private String time;
@Field(type=FieldType.String)
private String exceptionMessage;
@Field(type= FieldType.Object)
private List<MethodStack> stackList;
public StateObject(){
}
public StateObject(String id, String exceptionName, String time, String exceptionMessage, List<MethodStack> stackList) {
this.id = id;
this.exceptionName = exceptionName;
this.time = time;
this.exceptionMessage = exceptionMessage;
this.stackList = stackList;
}
public String getExceptionName() {
return exceptionName;
}
public void setExceptionName(String exceptionName) {
this.exceptionName = exceptionName;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getExceptionMessage() {
return exceptionMessage;
}
public void setExceptionMessage(String exceptionMessage) {
this.exceptionMessage = exceptionMessage;
}
public List<MethodStack> getStackList() {
return stackList;
}
public void setStackList(List<MethodStack> stackList) {
this.stackList = stackList;
}
}
我有以下存储库
import com.fico.ficoops.models.StateObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface StateObjectRepository extends ElasticsearchCrudRepository<StateObject,String>{
// Page<StateObject> findStateObjectById(String id, Pageable pageable);
}
当我运行此应用程序时,我得到以下异常
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stateObjectRepository': Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
我哪里错了?我在我的文档中有嵌套对象是它的原因,我尝试从模型中删除该成员变量,但这也没有帮助......
编辑1:添加配置文件
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.NodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.custom.repositories")
@ComponentScan(basePackages = "com.custom.services")
public class Config {
private static Logger logger = LoggerFactory.getLogger(Config.class);
@Bean
public NodeBuilder nodeBuilder(){
return new NodeBuilder();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() throws IOException {
final Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data");
logger.debug(tmpDir.toAbsolutePath().toString());
Settings.Builder elasticsearchSettings =
Settings.settingsBuilder()
.put("http.enabled", "false")
.put("path.data", tmpDir)
.put("path.home", "/usr/share/elasticsearch");
return new ElasticsearchTemplate(nodeBuilder().local(true).settings(elasticsearchSettings).node().client());
}
}