spring boot 集成es

目录

maven依赖

启动类

application.yml

pojo

dao


maven依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

启动类

/** @author bsl springBoot启动类 @EnableScheduling 开启定时器 */
@EnableScheduling
@SpringBootApplication
@MapperScan("com.wonders.mapper")
public class NetWorkApplication /*extends SpringBootServletInitializer*/ {
/**
 * springBoot启动类,运行此方法启动项目
 * @param args
 */
  public static void main(String[] args) {
      //        System.out.println("===========================================");
      /**
       * Springboot整合Elasticsearch 在项目启动前设置一下的属性,防止报错
       * 解决netty冲突后初始化client时还会抛出异常
       * java.lang.IllegalStateException: availableProcessors is already set to [4], rejecting [4]
       */
      System.setProperty("es.set.netty.runtime.available.processors", "false");
    SpringApplication.run(NetWorkApplication.class, args);
  }

application.yml

spring:
  application:
    name: es
  thymeleaf: # 关闭thymeleaf缓存
    cache: false
  #配置ES
  data:
    elasticsearch:
      cluster-name: docker-cluster
      cluster-nodes: ip:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode(9200端口是http查询使用的。9300集群使用。这里使用9300.)
server:
  port: 33333
#指定mybatis映射文件的地址
mybatis:
  mapper-locations: classpath:mappers/*.xml
  type-aliases-package: com.wonders.bo

pojo

@Component
@Scope("prototype")
@Data
@Document(indexName = "govbaselog", type = "loginfos")
public class GovBaseLog implements Serializable {
	@Id
	private String st_id;
	@Field(type = FieldType.text,analyzer="ik_max_word")
	private String st_opt_id;


	@Field(type = FieldType.Date ,analyzer="ik_max_word",format = DateFormat.custom,pattern ="yyyy-MM-dd HH:mm:ss")
	@JsonFormat(shape =JsonFormat.Shape.STRING,pattern ="yyyy-MM-dd HH:mm:ss",timezone ="GMT+8")
	private Date dt_time;

	

	public GovBaseLog() {}
}

dao

import com.wonders.bo.GovBaseLog;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

public interface GovBaseLogRepository extends ElasticsearchRepository<GovBaseLog,String>, PagingAndSortingRepository<GovBaseLog,String> {
}

猜你喜欢

转载自blog.csdn.net/adminBfl/article/details/104530800