Tir*_*iya 5 java spring elasticsearch spring-boot elastic-stack
我刚刚启动 springboot 并尝试使用 spring-boot 实现弹性搜索,但在运行 spring-boot 应用程序时出现此类错误
考虑在您的配置中定义一个名为“elasticsearchTemplate”的 bean。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.6.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
@Repository
public interface StudentRepository extends ElasticsearchRepository<Student, Integer>{}
Run Code Online (Sandbox Code Playgroud)
@RestController
public class Controller {
@Autowired
StudentRepository studentRepo;
@GetMapping(value="/student/all")
List<Student> getAllStudent() {
Iterator<Student> studentList = studentRepo.findAll().iterator();
List<Student> students = new ArrayList<>();
if(studentList.hasNext()) {
students.add(studentList.next());
}
return students;
}
@PostMapping(value="/student/add")
String addStudent(@RequestBody Student student) {
studentRepo.save(student);
return "Record Added Successfully";
}
@DeleteMapping(value="/student/delete/{id}")
String deleteStudent(@PathVariable int id) {
studentRepo.deleteById(id);
return "Record Deleted Successfully";
}
//@GetMapping(value="/student/findById/{id}")
}
Run Code Online (Sandbox Code Playgroud)
谁能帮我解决这个错误
考虑在您的配置中定义一个名为“elasticsearchTemplate”的 bean。
小智 5
您需要在 application.properties 文件中定义一些弹性搜索属性,例如cluster-nodes,ElasticsearchTemplate和ElasticsearchRepositorycluster-names使用这些属性连接到 Elasticsearch 引擎。
您可以参考下面提到的链接:
https://dzone.com/articles/elasticsearch-with-spring-boot-application
| 归档时间: |
|
| 查看次数: |
5543 次 |
| 最近记录: |