小编Tir*_*iya的帖子

考虑在您的配置中定义一个名为“elasticsearchTemplate”的 bean

我刚刚启动 springboot 并尝试使用 spring-boot 实现弹性搜索,但在运行 spring-boot 应用程序时出现此类错误

考虑在您的配置中定义一个名为“elasticsearchTemplate”的 bean。

POM文件

    <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 = …
Run Code Online (Sandbox Code Playgroud)

java spring elasticsearch spring-boot elastic-stack

5
推荐指数
1
解决办法
5543
查看次数

标签 统计

elastic-stack ×1

elasticsearch ×1

java ×1

spring ×1

spring-boot ×1