Skip to content

Commit

Permalink
fifteen
Browse files Browse the repository at this point in the history
  • Loading branch information
erghjmncq6643981 committed Mar 9, 2020
1 parent 95aae38 commit cc31b58
Show file tree
Hide file tree
Showing 26 changed files with 1,121 additions and 6 deletions.
178 changes: 178 additions & 0 deletions chandler-elasticsearch-component/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chandler</groupId>
<artifactId>chandler-elasticsearch-component</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description>Demo project for spring data elasticsearch</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.3.RELEASE</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-data-elasticsearch.version>3.2.4.RELEASE</spring-data-elasticsearch.version>
<spring-data-commons.version>2.2.4.RELEASE</spring-data-commons.version>
<spring.version>5.2.3.RELEASE</spring.version>
<fastjson.version>1.2.62</fastjson.version>
<elasticsearch.version>6.8.3</elasticsearch.version>
<jackson.version>2.9.8</jackson.version>
<springfox-swagger.version>2.9.2</springfox-swagger.version>
<lombok.version>1.18.8</lombok.version>
<guava.version>28.2-jre</guava.version>
</properties>


<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>${spring-data-elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>${spring-data-commons.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- swagger,无法适配webflux,需要等待3.0版本 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
<!--<executions>-->
<!--<execution>-->
<!--<goals>-->
<!--<goal>build-info</goal>-->
<!--<goal>repackage</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* chandler-spring-component
* 2020/3/8 6:06 PM
*
* Please contact chandler
* if you need additional information or have any questions.
* Please contact chandler Corporation or visit:
* https://www.jianshu.com/u/117796446366
*
* @author 钱丁君-chandler
* @version 1.0
*/
package com.chandler.spring.elasticsearch.example.config;

import com.chandler.spring.elasticsearch.example.dao.UserMapperRepository;
import com.chandler.spring.elasticsearch.example.handler.UserHandler;
import com.chandler.spring.elasticsearch.example.service.UserService;
import com.chandler.spring.elasticsearch.example.service.impl.UserServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.PUT;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

/**
* 自动装备
*
* @author 钱丁君-chandler 2020/3/8 6:06 PM
* @version 1.0.0
* @since 1.8
*/
@Configuration
@EnableReactiveElasticsearchRepositories(basePackages = {"com.chandler.spring.elasticsearch.example.*"})
public class CustomAutoConfiguration {

@Bean
public RouterFunction<ServerResponse> route(UserHandler handler) {
return RouterFunctions
.route(GET("/users")
.and(accept(APPLICATION_STREAM_JSON)), handler::findAll)
.andRoute(PUT("/users/save")
.and(accept(APPLICATION_STREAM_JSON)), handler::save)
.andRoute(GET("/users/find")
.and(accept(APPLICATION_STREAM_JSON)), handler::findByUsename)
.andRoute(GET("/users/find/{id}")
.and(accept(APPLICATION_STREAM_JSON)), handler::findById)
.andRoute(GET("/users/exists/{id}")
.and(accept(APPLICATION_STREAM_JSON)), handler::existsById);
}

@Bean
public UserHandler handler(UserService userService) {
UserHandler handler = new UserHandler();
handler.setUserService(userService);
return handler;
}

@Bean
public UserService userService(UserMapperRepository userRepository) {
UserServiceImpl userService = new UserServiceImpl();
userService.setUserRepository(userRepository);
return userService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* chandler-elasticsearch-component
* 2020/3/8 4:42 PM
*
* Please contact chandler
* if you need additional information or have any questions.
* Please contact chandler Corporation or visit:
* https://www.jianshu.com/u/117796446366
*
* @author 钱丁君-chandler
* @version 1.0
*/
package com.chandler.spring.elasticsearch.example.dao;

import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
import org.springframework.data.repository.NoRepositoryBean;
import reactor.core.publisher.Flux;

/**
* 自定义ElasticsearchRepository
*
* @author 钱丁君-chandler 2020/3/8 4:42 PM
* @since 1.8
*/
@NoRepositoryBean
public interface CustomElasticsearchRepository<T, ID> extends ReactiveElasticsearchRepository<T, ID> {
@Query("{ \"bool\" : { \"must\" : { \"term\" : { \"useName\" : \"?0\" } } } }")
Flux<T> findByUsename(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* chandler-spring-elasticsearch
* 2020/1/19 6:27 PM
*
* Please contact chandler
* if you need additional information or have any questions.
* Please contact chandler Corporation or visit:
* https://www.jianshu.com/u/117796446366
*
* @author 钱丁君-chandler
* @version 1.0
*/
package com.chandler.spring.elasticsearch.example.dao;

import com.chandler.spring.elasticsearch.example.entity.User;

/**
* crud Repository
*
* @author 钱丁君-chandler 2020/1/19 6:27 PM
* @since 1.8
*/
public interface UserMapperRepository extends CustomElasticsearchRepository<User,String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* chandler-spring-elasticsearch
* 2020/1/19 6:52 PM
*
* Please contact chandler
* if you need additional information or have any questions.
* Please contact chandler Corporation or visit:
* https://www.jianshu.com/u/117796446366
*
* @author 钱丁君-chandler
* @version 1.0
*/
package com.chandler.spring.elasticsearch.example.domain.req;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* user请求对象
*
* @author 钱丁君-chandler 2020/1/19 6:52 PM
* @version 1.0.0
* @since 1.8
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserRequest implements Serializable {

private String id;
private String useName;
private String password;
private short age;
private String brithday;
private List<String> addresses;
private String introduction;
private Boolean memberFlag = false;
private List<String> tags;
private Long active = 0L;
private Object sessionData;
private String onlineTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Title:<br>
* Description:<br>
* Copyright: 数禾科技 Copyright(c) 2020/1/19
* Encoding: UNIX UTF-8
*
* @author 钱丁君
*/
package com.chandler.spring.elasticsearch.example.domain.req;
Loading

0 comments on commit cc31b58

Please sign in to comment.