栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

springboot+elasticserce+kibana

springboot+elasticserce+kibana

1、安装elasticserch
windows环境地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-4-3

安装以后,修改config文件夹下的elasticsearch.yml

验证:localhost:9200

2、安装kibana
windows环境地址:https://www.elastic.co/cn/downloads/past-releases/kibana-6-4-3


修改文件config下的kibana.yml文件

验证:http://localhost:5601/app/kibana

3、springboot集成es
pom.xml

		
        	org.springframework.boot
        	spring-boot-starter-parent
        	2.1.6.RELEASE
        	 
  	    
		
            org.springframework.boot
            spring-boot-starter-data-elasticsearch
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.projectlombok
            lombok
        

        
        
            junit
            junit
        

实体

package com.example.elasticsearch.eneity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.document;


@document(indexName = "test",type = "test")
public class Test {
    @Id
    private String id;
    private String name;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Test{" +
                "id='" + id + ''' +
                ", name='" + name + ''' +
                '}';
    }
}

dao

package com.example.elasticsearch.dao;

import com.example.elasticsearch.eneity.Test;
import org.springframework.data.repository.CrudRepository;

import java.util.List;


public interface TestDao extends CrudRepository {
    List findByName(String name);
}

接口

package com.example.elasticsearch.service;

import com.example.elasticsearch.eneity.Test;
import org.springframework.data.repository.CrudRepository;

import java.util.List;


public interface TestService {

    void save(Test test);

    List findByName(String name);
}

实现

package com.example.elasticsearch.service.impl;

import com.example.elasticsearch.dao.TestDao;
import com.example.elasticsearch.eneity.Test;
import com.example.elasticsearch.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TestServiceImpl implements TestService {

    @Autowired
    TestDao testDao;

    @Override
    public void save(Test test){
       testDao.save(test);
    }

    @Override
    public List findByName(String name){
        return testDao.findByName(name);
    }
}

测试

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/344558.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号