Skip to content

Commit c762312

Browse files
committed
Polish chapter 1 code
1 parent 1c6afca commit c762312

File tree

9 files changed

+24
-288
lines changed

9 files changed

+24
-288
lines changed

1/part1/build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,13 @@ repositories {
3939
}
4040

4141
// tag::deps[]
42-
ext['thymeleaf-spring5.version'] = '3.0.7-SNAPSHOT'
43-
4442
dependencies {
45-
compile('org.springframework.boot:spring-boot-starter-data-jpa')
43+
compile('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
4644
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
47-
compile('org.springframework.boot:spring-boot-starter-web')
48-
compile('org.springframework:spring-messaging')
45+
compile('org.springframework.boot:spring-boot-starter-webflux')
4946

5047
compile('org.projectlombok:lombok')
51-
runtime('com.h2database:h2')
48+
compile('de.flapdoodle.embed:de.flapdoodle.embed.mongo')
5249
testCompile('org.springframework.boot:spring-boot-starter-test')
5350
}
5451
// end::deps[]

1/part1/gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 5 deletions
This file was deleted.

1/part1/gradlew

Lines changed: 0 additions & 164 deletions
This file was deleted.

1/part1/gradlew.bat

Lines changed: 0 additions & 90 deletions
This file was deleted.

1/part1/src/main/java/com/greglturnquist/learningspringboot/Chapter.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
package com.greglturnquist.learningspringboot;
22

3-
import javax.persistence.Entity;
4-
import javax.persistence.GeneratedValue;
5-
import javax.persistence.Id;
6-
73
import lombok.Data;
84

5+
import org.springframework.data.annotation.Id;
6+
import org.springframework.data.mongodb.core.mapping.Document;
7+
98
@Data
10-
@Entity
9+
@Document
1110
public class Chapter {
1211

13-
@Id @GeneratedValue
14-
private Long id;
15-
12+
@Id
13+
private String id;
1614
private String name;
1715

18-
private Chapter() {
19-
// No one but JPA uses this.
20-
}
21-
2216
public Chapter(String name) {
2317
this.name = name;
2418
}

1/part1/src/main/java/com/greglturnquist/learningspringboot/ChapterController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.greglturnquist.learningspringboot;
22

3+
import reactor.core.publisher.Flux;
4+
35
import org.springframework.web.bind.annotation.GetMapping;
46
import org.springframework.web.bind.annotation.RestController;
57

@@ -13,7 +15,7 @@ public ChapterController(ChapterRepository repository) {
1315
}
1416

1517
@GetMapping("/chapters")
16-
public Iterable<Chapter> listing() {
18+
public Flux<Chapter> listing() {
1719
return repository.findAll();
1820
}
1921
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.greglturnquist.learningspringboot;
22

3-
import org.springframework.data.repository.CrudRepository;
3+
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
44

55
public interface ChapterRepository
6-
extends CrudRepository<Chapter, Long> {
6+
extends ReactiveCrudRepository<Chapter, String> {
77

88
}

1/part1/src/main/java/com/greglturnquist/learningspringboot/LoadDatabase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.greglturnquist.learningspringboot;
22

3+
import reactor.core.publisher.Flux;
4+
35
import org.springframework.boot.CommandLineRunner;
46
import org.springframework.context.annotation.Bean;
57
import org.springframework.context.annotation.Configuration;
@@ -10,12 +12,12 @@ public class LoadDatabase {
1012
@Bean
1113
CommandLineRunner init(ChapterRepository repository) {
1214
return args -> {
13-
repository.save(
14-
new Chapter("Quick start with Java"));
15-
repository.save(
16-
new Chapter("Reactive Web with Spring Boot"));
17-
repository.save(
18-
new Chapter("...and more!"));
15+
Flux.just(
16+
new Chapter("Quick Start with Java"),
17+
new Chapter("Reactive Web with Spring Boot"),
18+
new Chapter("...and more!"))
19+
.flatMap(repository::save)
20+
.subscribe(System.out::println);
1921
};
2022
}
2123

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sun May 14 20:03:28 CDT 2017
1+
#Fri Jul 28 13:37:07 BST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-bin.zip

0 commit comments

Comments
 (0)