Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0e33d72

Browse files
authored
Merge pull request #5 from kasramp/spring-boot3-upgrade
Upgrade to Spring Boot 3 with Elasticsearch 8.7.0
2 parents 6e74226 + 9b50685 commit 0e33d72

File tree

16 files changed

+136
-104
lines changed

16 files changed

+136
-104
lines changed

‎.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github: kasramp
2+
custom: https://paypal.me/Madadipouya

‎.github/workflows/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Java CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Cache
11+
uses: actions/cache@v3
12+
with:
13+
path: ~/.m2/repository
14+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
15+
restore-keys: |
16+
${{ runner.os }}-maven-
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: zulu
21+
java-version: 17
22+
- name: Run tests
23+
run: mvn clean verify
24+
- name: Build with Maven
25+
run: mvn -B package --file pom.xml

‎README.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,51 @@
1-
# Spring Data Elasticsearch Example
1+
# Spring Data Elasticsearch Example with Spring Boot 3 and ElasticSearch 8
22

33
## Introduction
44

5-
This example demonstrates how to use Spring Data Elasticsearch to do simple CRUD operation.
5+
This example demonstrates how to use Spring Data Elasticsearch to do simple CRUD operations.
66

7-
You can find the tutorial about this example at the below link:
7+
You can find the tutorial about this example at this link:[Getting started with Spring Data Elasticsearch](https://www.geekyhacker.com/getting-started-with-spring-data-elasticsearch/)
88

9-
[https://geekyhacker.com/2019/05/01/getting-started-with-spring-data-elasticsearch/](https://geekyhacker.com/2019/05/01/getting-started-with-spring-data-elasticsearch/)
9+
For this example, we created a Book controller that allows doing the following operations with Elasticsearch:
1010

11-
For this example, a Book controller created that allows to do the following operations with Elasticsearch:
12-
13-
- Get list of all books
11+
- Get the list of all books
1412
- Create a book
1513
- Update a book by Id
1614
- Delete a book by Id
1715
- Search for a book by ISBN
1816
- Fuzzy search for books by author and title
1917

20-
2118
## How to run
2219

23-
The first thing to do is to start Elasticsearch. For that you can use the `docker-compose` file in this project
24-
and run it like this:
20+
The first thing to do is to start Elasticsearch. For that, you can use the `docker-compose` file in this project and run it like this:
2521

2622
```bash
2723
$ docker-compose -f docker-compose up -d
2824
```
2925

30-
It brings Elasticsearch up on a single node cluster with the cluser name `elasticsearch`.
26+
It brings Elasticsearch up on a single node cluster with the cluster name `elasticsearch`.
3127

3228
Then you can run the application like below:
3329

3430
```bash
3531
$ ./mvnw spring-boot:run
3632
```
3733

38-
If your Elasticsearch URI is not `localhost` and/or the cluster name is different simply override one or both of the following environment variable:
34+
If your Elasticsearch URI is not `localhost` is different simply override the following environment variable:
3935

4036
- `ES_URI`
41-
- `ES_CLUSTER_NAME`
4237

4338
Once everything is up and running open the browser and go to [http://localhost:8080](http://localhost:8080). You should see Swagger to interact with.
4439

45-
## Run testcontainers tests
46-
47-
The integration tests written relying on [testcontainers](https://www.testcontainers.org/) to spin up Elasticsearch on the spot to run tests against.
40+
## Run Testcontainers tests
4841

49-
To know more about container read this tutorial:
50-
[https://geekyhacker.com/2019/05/08/integration-test-with-testcontainers-in-java/](https://geekyhacker.com/2019/05/08/integration-test-with-testcontainers-in-java/)
42+
The integration tests are written relying on [Testcontainers](https://www.testcontainers.org/) to spin up Elasticsearch on the spot and run tests against it.
43+
To know more about container testing read this tutorial: [Integration testwith Testcontainers in Java](https://www.geekyhacker.com/integration-test-with-testcontainers-in-java/)
5144

52-
To run them just execute below command:
45+
To run the integration test (using Testcontainers) just run the below command:
5346

5447
```bash
5548
$ mvn clean verify
5649
```
5750

58-
Make sure you have your docker running.
51+
Make sure you have your docker running.

‎docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
elasticsearch:
2-
image: elasticsearch:6.4.3
2+
image: elasticsearch:8.7.0
33
container_name: elasticsearch
44
ports:
5-
- "9300:9300"
65
- "9200:9200"
76
environment:
87
- discovery.type=single-node
9-
- cluster.name=elasticsearch
8+
- cluster.name=elasticsearch
9+
# Since ES 8, SSL is on by default, disabling on local
10+
- xpack.security.enabled=false

‎pom.xml

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>2.1.4.RELEASE</version>
9-
<relativePath/> <!-- lookup parent from repository -->
8+
<version>3.1.0</version>
109
</parent>
1110
<groupId>com.madadipouya.elasticsearch.springdata.example</groupId>
1211
<artifactId>elasticsearch-springdata</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
12+
<version>0.0.2</version>
1413
<name>Elasticsearch SpringData</name>
1514
<description>Elasticsearch SpringData</description>
1615

1716
<properties>
18-
<java.version>11</java.version>
17+
<java.version>17</java.version>
18+
<mockito.version>5.3.1</mockito.version>
19+
<testcontainers.version>1.18.3</testcontainers.version>
1920
</properties>
2021

2122
<dependencies>
@@ -32,64 +33,52 @@
3233
<artifactId>spring-boot-starter-actuator</artifactId>
3334
</dependency>
3435
<dependency>
35-
<groupId>io.springfox</groupId>
36-
<artifactId>springfox-swagger2</artifactId>
37-
<version>2.9.2</version>
38-
<scope>compile</scope>
39-
</dependency>
40-
<dependency>
41-
<groupId>io.springfox</groupId>
42-
<artifactId>springfox-swagger-ui</artifactId>
43-
<version>2.9.2</version>
44-
</dependency>
45-
<dependency>
46-
<groupId>org.springframework.boot</groupId>
47-
<artifactId>spring-boot-devtools</artifactId>
48-
<scope>runtime</scope>
36+
<groupId>org.springdoc</groupId>
37+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
38+
<version>2.1.0</version>
4939
</dependency>
5040
<dependency>
5141
<groupId>org.springframework.boot</groupId>
5242
<artifactId>spring-boot-starter-test</artifactId>
5343
<scope>test</scope>
5444
</dependency>
55-
5645
<dependency>
5746
<groupId>org.junit.jupiter</groupId>
5847
<artifactId>junit-jupiter-engine</artifactId>
59-
<version>5.3.2</version>
48+
<version>5.9.3</version>
6049
<scope>test</scope>
6150
</dependency>
6251
<dependency>
6352
<groupId>org.mockito</groupId>
6453
<artifactId>mockito-core</artifactId>
65-
<version>2.23.4</version>
54+
<version>${mockito.version}</version>
6655
<scope>test</scope>
6756
</dependency>
6857
<dependency>
6958
<groupId>org.mockito</groupId>
7059
<artifactId>mockito-junit-jupiter</artifactId>
71-
<version>2.23.4</version>
60+
<version>${mockito.version}</version>
7261
<scope>test</scope>
7362
</dependency>
7463
<dependency>
7564
<groupId>org.testcontainers</groupId>
7665
<artifactId>testcontainers</artifactId>
77-
<version>1.17.3</version>
66+
<version>${testcontainers.version}</version>
67+
<scope>test</scope>
7868
</dependency>
7969
<dependency>
8070
<groupId>org.testcontainers</groupId>
8171
<artifactId>junit-jupiter</artifactId>
82-
<version>1.17.2</version>
72+
<version>${testcontainers.version}</version>
8373
<scope>test</scope>
8474
</dependency>
8575
<dependency>
8676
<groupId>org.testcontainers</groupId>
8777
<artifactId>elasticsearch</artifactId>
88-
<version>1.17.3</version>
78+
<version>${testcontainers.version}</version>
8979
<scope>test</scope>
9080
</dependency>
9181
</dependencies>
92-
9382
<build>
9483
<plugins>
9584
<plugin>
@@ -99,12 +88,12 @@
9988
<plugin>
10089
<groupId>org.apache.maven.plugins</groupId>
10190
<artifactId>maven-surefire-plugin</artifactId>
102-
<version>2.22.0</version>
91+
<version>3.1.2</version>
10392
</plugin>
10493
<plugin>
10594
<groupId>org.apache.maven.plugins</groupId>
10695
<artifactId>maven-failsafe-plugin</artifactId>
107-
<version>3.0.0-M3</version>
96+
<version>3.1.2</version>
10897
<configuration>
10998
<skipTests>false</skipTests>
11099
<rerunFailingTestsCount>3</rerunFailingTestsCount>
@@ -123,5 +112,4 @@
123112
</plugin>
124113
</plugins>
125114
</build>
126-
127-
</project>
115+
</project>

‎src/main/java/com/madadipouya/elasticsearch/springdata/example/config/SwaggerConfig.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5-
import springfox.documentation.builders.RequestHandlerSelectors;
6-
import springfox.documentation.spi.DocumentationType;
7-
import springfox.documentation.spring.web.plugins.Docket;
8-
import springfox.documentation.swagger2.annotations.EnableSwagger2;
95

10-
import static springfox.documentation.builders.PathSelectors.regex;
6+
import io.swagger.v3.oas.models.OpenAPI;
7+
import io.swagger.v3.oas.models.info.Contact;
8+
import io.swagger.v3.oas.models.info.Info;
9+
import io.swagger.v3.oas.models.info.License;
1110

1211
@Configuration
13-
@EnableSwagger2
1412
public class SwaggerConfig {
13+
1514
@Bean
16-
public Docket api() {
17-
return new Docket(DocumentationType.SWAGGER_2)
18-
.select()
19-
.apis(RequestHandlerSelectors.any())
20-
.paths(regex("/v1/.*"))
21-
.build();
15+
public OpenAPI apiInfo() {
16+
return new OpenAPI().info(new Info().title("Spring Data Elasticsearch example")
17+
.description("Spring Data Elasticsearch example with Testcontainers")
18+
.version("v0.0.2")
19+
.contact(getContactDetails())
20+
.license(getLicenseDetails()));
21+
}
22+
23+
private Contact getContactDetails() {
24+
return new Contact().name("Kasra Madadipouya")
25+
.email("kasra@madadipouya.com")
26+
.url("https://geekyhacker.com");
27+
}
28+
29+
private License getLicenseDetails() {
30+
return new License().name("GNU General Public License v3.0")
31+
.url("https://github.com/kasramp/Spring-Data-ElasticSearch-Example/blob/master/LICENSE");
2232
}
2333
}

‎src/main/java/com/madadipouya/elasticsearch/springdata/example/controller/BookController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import org.springframework.http.HttpStatus;
99
import org.springframework.web.bind.annotation.*;
1010

11-
import javax.validation.Valid;
12-
import javax.validation.constraints.NotBlank;
13-
import javax.validation.constraints.Positive;
11+
import jakarta.validation.Valid;
12+
import jakarta.validation.constraints.NotBlank;
13+
import jakarta.validation.constraints.Positive;
1414
import java.util.List;
1515

1616
@RestController

‎src/main/java/com/madadipouya/elasticsearch/springdata/example/controller/redirect.java renamed to ‎src/main/java/com/madadipouya/elasticsearch/springdata/example/controller/Redirect.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import org.springframework.web.servlet.ModelAndView;
66

77
@RestController
8-
public class redirect {
8+
public class Redirect {
99

1010
@GetMapping(value = "/")
1111
public ModelAndView redirectToDocPage() {
12-
return new ModelAndView("redirect:/swagger-ui.html");
12+
return new ModelAndView("redirect:/swagger-ui/index.html");
1313
}
1414

1515
@GetMapping(value = "/apidocs")
1616
public ModelAndView redirectToApiPage() {
17-
return new ModelAndView("redirect:/swagger-ui.html");
17+
return new ModelAndView("redirect:/swagger-ui/index.html");
1818
}
1919
}

‎src/main/java/com/madadipouya/elasticsearch/springdata/example/metadata/PublicationYear.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.madadipouya.elasticsearch.springdata.example.validator.PublicationYearValidator;
44

5-
import javax.validation.Constraint;
6-
import javax.validation.Payload;
5+
import jakarta.validation.Constraint;
6+
import jakarta.validation.Payload;
77
import java.lang.annotation.Documented;
88
import java.lang.annotation.Retention;
99
import java.lang.annotation.Target;

‎src/main/java/com/madadipouya/elasticsearch/springdata/example/model/Book.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.springframework.data.annotation.Id;
44
import org.springframework.data.elasticsearch.annotations.Document;
55

6-
@Document(indexName = "books", type = "book")
6+
@Document(indexName = "books")
77
public class Book {
88

99
@Id

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /