├── 1-reactive ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── home.html │ │ └── java │ │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── Cart.java │ │ │ ├── HomeController.java │ │ │ ├── Dish.java │ │ │ ├── ServerController.java │ │ │ └── KitchenService.java │ └── test │ │ ├── java │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ └── HackingSpringBootApplicationTests.java │ │ └── resources │ │ └── logback.xml ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties └── .gitignore ├── 4-reactive ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── home.html │ │ └── java │ │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemByExampleRepository.java │ │ │ ├── TemplateDatabaseLoader.java │ │ │ ├── CartService.java │ │ │ ├── ItemRepository.java │ │ │ ├── CartItem.java │ │ │ └── Cart.java │ └── test │ │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ ├── BlockHoundUnitTest.java │ │ ├── ItemUnitTest.java │ │ ├── MongoDbSliceTest.java │ │ └── LoadingWebSiteIntegrationTest.java ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties └── .gitignore ├── 6-reactive ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ ├── java │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── CartRepository.java │ │ │ ├── TemplateDatabaseLoader.java │ │ │ ├── CartService.java │ │ │ ├── ItemRepository.java │ │ │ ├── CartItem.java │ │ │ └── Cart.java │ │ └── asciidoc │ │ └── index.adoc ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties └── .gitignore ├── 7-reactive ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ ├── HackingSpringBootApplication.java │ ├── ItemRepository.java │ └── SpringAmqpItemService.java ├── 9-reactive-quick ├── src │ └── main │ │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ └── home.html │ │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ ├── HackingSpringBootApplication.java │ │ ├── ItemRepository.java │ │ ├── CartRepository.java │ │ ├── DatabaseLoader.java │ │ ├── CartItem.java │ │ └── Cart.java └── .mvn │ └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── 8-reactive-client ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ └── client │ ├── HackingSpringBootRSocketClientApplication.java │ └── ItemRepository.java ├── 8-reactive-server ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ └── server │ ├── HackingSpringBootRSocketServerApplication.java │ └── ItemRepository.java ├── 9-reactive-oauth ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ ├── HackingSpringBootApplication.java │ ├── CartRepository.java │ ├── ItemRepository.java │ ├── UserRepository.java │ ├── DatabaseLoader.java │ ├── CartItem.java │ └── Cart.java ├── 2-reactive ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── home.html │ │ └── java │ │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── ItemRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── TemplateDatabaseLoader.java │ │ │ ├── CartItem.java │ │ │ ├── CartService.java │ │ │ ├── Item.java │ │ │ └── Cart.java │ └── test │ │ ├── resources │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ ├── BlockingItemRepository.java │ │ ├── InventoryService.java │ │ ├── RepositoryDatabaseLoader.java │ │ ├── InventoryController.java │ │ ├── Sample1.java │ │ └── HomeController2.java └── .gitignore ├── 3-reactive ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── home.html │ │ └── java │ │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── HackingSpringBootApplicationPlainBlockHound.java │ │ │ ├── HackingSpringBootApplicationBlockHoundCustomized.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemByExampleRepository.java │ │ │ ├── TemplateDatabaseLoader.java │ │ │ ├── CartService.java │ │ │ ├── ItemRepository.java │ │ │ ├── CartItem.java │ │ │ └── Cart.java │ └── test │ │ ├── resources │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ └── LoggingReactorFlows.java └── .gitignore ├── 5-reactive ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── .gitignore ├── Dockerfile └── src │ └── main │ ├── resources │ ├── application.properties │ └── templates │ │ └── home.html │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ ├── CartRepository.java │ ├── ItemByExampleRepository.java │ ├── HttpTraceWrapperRepository.java │ ├── HttpTraceWrapper.java │ ├── TemplateDatabaseLoader.java │ ├── SpringDataHttpTraceRepository.java │ ├── CartService.java │ ├── ItemRepository.java │ ├── CartItem.java │ └── Cart.java ├── 2b-reactive ├── .mvn │ └── wrapper │ │ └── maven-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ │ └── home.html │ │ └── java │ │ │ └── com │ │ │ └── greglturnquist │ │ │ └── hackingspringboot │ │ │ └── reactive │ │ │ ├── HackingSpringBootApplication.java │ │ │ ├── CartRepository.java │ │ │ ├── ItemByExampleRepository.java │ │ │ ├── TemplateDatabaseLoader.java │ │ │ ├── CartItem.java │ │ │ ├── CartService.java │ │ │ ├── ItemRepository.java │ │ │ └── Cart.java │ └── test │ │ ├── resources │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ ├── BlockingItemRepository.java │ │ ├── RepositoryDatabaseLoader.java │ │ ├── Sample1.java │ │ ├── HomeController2.java │ │ ├── InventoryController.java │ │ └── FluentService.java └── .gitignore ├── 9-reactive-repository ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ ├── application.properties │ └── templates │ │ └── home.html │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ ├── HackingSpringBootApplication.java │ ├── ItemRepository.java │ ├── CartRepository.java │ ├── UserRepository.java │ ├── DatabaseLoader.java │ ├── CartItem.java │ ├── SecurityConfig.java │ └── Cart.java ├── 9-reactive-custom-config ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ └── main │ ├── resources │ ├── application.properties │ └── templates │ │ └── home.html │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ ├── HackingSpringBootApplication.java │ ├── CartRepository.java │ ├── ItemRepository.java │ ├── UserRepository.java │ ├── DatabaseLoader.java │ ├── CartItem.java │ └── Cart.java ├── 9-reactive-method-security ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties └── src │ ├── main │ ├── resources │ │ ├── application.properties │ │ └── templates │ │ │ └── home.html │ └── java │ │ └── com │ │ └── greglturnquist │ │ └── hackingspringboot │ │ └── reactive │ │ ├── HackingSpringBootApplication.java │ │ ├── CartRepository.java │ │ ├── ItemRepository.java │ │ ├── UserRepository.java │ │ ├── DatabaseLoader.java │ │ └── CartItem.java │ └── test │ └── java │ └── com │ └── greglturnquist │ └── hackingspringboot │ └── reactive │ └── HomeControllerTest.java ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── .gitignore └── pom.xml /1-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /4-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.webflux.hiddenmethod.filter.enabled=true -------------------------------------------------------------------------------- /6-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.hateoas.use-hal-as-default-json-media-type=false -------------------------------------------------------------------------------- /7-reactive/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/7-reactive/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-quick/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.security=DEBUG 2 | spring.webflux.hiddenmethod.filter.enabled=true -------------------------------------------------------------------------------- /8-reactive-client/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/8-reactive-client/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /8-reactive-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/8-reactive-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-oauth/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/9-reactive-oauth/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-quick/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/9-reactive-quick/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /1-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /2-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /3-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /4-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /5-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /6-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /7-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /2b-reactive/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /3-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.com.gregturnquist=DEBUG 2 | logging.level.web=DEBUG 3 | spring.webflux.hiddenmethod.filter.enabled=true -------------------------------------------------------------------------------- /9-reactive-repository/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/9-reactive-repository/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-repository/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #logging.level.org.springframework.security=DEBUG 2 | spring.webflux.hiddenmethod.filter.enabled=true 3 | -------------------------------------------------------------------------------- /8-reactive-client/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /8-reactive-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /9-reactive-custom-config/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/9-reactive-custom-config/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-oauth/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /9-reactive-quick/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /9-reactive-custom-config/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /9-reactive-method-security/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/onlybooks/spring-boot-reactive/HEAD/9-reactive-method-security/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /9-reactive-repository/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /2-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.data=TRACE 2 | # tag::hidden[] 3 | spring.webflux.hiddenmethod.filter.enabled=true 4 | # end::hidden[] -------------------------------------------------------------------------------- /9-reactive-method-security/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /2b-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.data=TRACE 2 | # tag::hidden[] 3 | spring.webflux.hiddenmethod.filter.enabled=true 4 | # end::hidden[] -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #logging.level.org.springframework.security=TRACE 2 | logging.level.com.greglturnquist=DEBUG 3 | spring.webflux.hiddenmethod.filter.enabled=true -------------------------------------------------------------------------------- /8-reactive-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #logging.level.com.greglturnquist.hackingspringboot=DEBUG 2 | #logging.level.org.springframework.data=DEBUG 3 | #logging.level.reactor=DEBUG 4 | #logging.level.io.rsocket=DEBUG -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #logging.level.org.springframework.security=TRACE 2 | logging.level.com.greglturnquist=DEBUG 3 | spring.hateoas.use-hal-as-default-json-media-type=false 4 | spring.webflux.hiddenmethod.filter.enabled=true -------------------------------------------------------------------------------- /7-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | logging.level.org.springframework.amqp=DEBUG 2 | logging.level.org.springframework.messaging=DEBUG 3 | logging.level.com.greglturnquist.hackingspringboot=DEBUG 4 | logging.level.org.springframework.data=DEBUG 5 | logging.level.reactor=DEBUG -------------------------------------------------------------------------------- /1-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | public class HackingSpringBootApplicationTests { 8 | 9 | @Test 10 | public void contextLoads() { 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # tag::oauth[] 2 | spring: 3 | security: 4 | oauth2: 5 | client: 6 | registration: 7 | google: 8 | client-id: GOOGLE_CLIENT_ID # 실제 구글에서 발급받은 client-id로 대체해야함 9 | client-secret: GOOGLE_CLIENT_SECRET # 실제 구글에서 발급받은 client-secret으로 대체해야함 10 | # end::oauth[] 11 | webflux: 12 | hiddenmethod: 13 | filter: 14 | enabled: true 15 | -------------------------------------------------------------------------------- /8-reactive-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # tag::code[] 2 | # Port for your Netty web service 3 | server.port=9000 4 | 5 | # RSocket server port 6 | spring.rsocket.server.port=7000 7 | # RSocket transport protocol 8 | spring.rsocket.server.transport=tcp 9 | # end::code[] 10 | 11 | #logging.level.com.greglturnquist.hackingspringboot=DEBUG 12 | #logging.level.org.springframework.data=DEBUG 13 | #logging.level.reactor=DEBUG 14 | #logging.level.io.rsocket=DEBUG -------------------------------------------------------------------------------- /1-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /2-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /2b-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /3-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /4-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /5-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /6-reactive/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/maven,intellij 3 | # Edit at https://www.gitignore.io/?templates=maven,intellij 4 | 5 | ### Maven ### 6 | target/ 7 | pom.xml.tag 8 | pom.xml.releaseBackup 9 | pom.xml.versionsBackup 10 | pom.xml.next 11 | release.properties 12 | dependency-reduced-pom.xml 13 | buildNumber.properties 14 | .mvn/timing.properties 15 | .mvn/wrapper/maven-wrapper.jar 16 | 17 | # End of https://www.gitignore.io/api/maven,intellij 18 | -------------------------------------------------------------------------------- /1-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 스프링 부트 실전 활용 마스터 - 시작하기 6 | 7 | 8 | 9 |

스프링 부트 실전 활용 마스터 독자분들
열렬히 환영합니다!

10 | 11 |

12 | 책 내용을 전개하면서 스프링 부트를 활용해 이커머스 시스템의 여러 부분을 만들어본다. 13 |

14 |

15 | 이 페이지 내용도 동적인 컨텐츠로 점점 바뀔 것이다. 16 |

17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /1-reactive/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d %5p %40.40c:%4L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /2-reactive/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d %5p %40.40c:%4L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /2b-reactive/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d %5p %40.40c:%4L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /3-reactive/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %d %5p %40.40c:%4L - %m%n 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | // tag::code[] 7 | @SpringBootApplication 8 | public class HackingSpringBootApplication { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(HackingSpringBootApplication.class, args); 12 | } 13 | } 14 | // end::code[] 15 | -------------------------------------------------------------------------------- /8-reactive-client/src/main/java/com/greglturnquist/hackingspringboot/reactive/client/HackingSpringBootRSocketClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive.client; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootRSocketClientApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootRSocketClientApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /8-reactive-server/src/main/java/com/greglturnquist/hackingspringboot/reactive/server/HackingSpringBootRSocketServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HackingSpringBootRSocketServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HackingSpringBootRSocketServerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /5-reactive/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM adoptopenjdk/openjdk8:latest as builder 2 | WORKDIR application 3 | ARG JAR_FILE=target/*.jar 4 | COPY ${JAR_FILE} application.jar 5 | RUN java -Djarmode=layertools -jar application.jar extract 6 | 7 | FROM adoptopenjdk/openjdk8:latest 8 | WORKDIR application 9 | COPY --from=builder application/dependencies/ ./ 10 | COPY --from=builder application/spring-boot-loader/ ./ 11 | #COPY --from=builder application/snapshot-dependencies/ ./ 12 | COPY --from=builder application/application/ ./ 13 | ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] 14 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.filter.reactive.HiddenHttpMethodFilter; 7 | 8 | @SpringBootApplication 9 | public class HackingSpringBootApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(HackingSpringBootApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplicationPlainBlockHound.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import reactor.blockhound.BlockHound; 4 | 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class HackingSpringBootApplicationPlainBlockHound { 10 | 11 | // tag::blockhound[] 12 | public static void main(String[] args) { 13 | BlockHound.install(); 14 | 15 | SpringApplication.run(HackingSpringBootApplicationPlainBlockHound.class, args); 16 | } 17 | // end::blockhound[] 18 | } 19 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import static org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType.*; 4 | 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.hateoas.config.EnableHypermediaSupport; 8 | 9 | @SpringBootApplication 10 | @EnableHypermediaSupport(type = { HAL, HAL_FORMS }) 11 | public class HackingSpringBootApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(HackingSpringBootApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /5-reactive/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # tag::health[] 2 | management.endpoint.health.show-details=always 3 | # end::health[] 4 | # tag::include-all[] 5 | management.endpoints.web.exposure.include=* 6 | # end::include-all[] 7 | # tag::include-all-explicitly[] 8 | management.endpoints.web.exposure.include=auditevents,beans,caches,conditions,configprops,env,flyway,health,heapdump,httptrace,info,logfile,loggers,metrics,mappings,shutdown,threaddump 9 | # end::include-all-explicitly[] 10 | # tag::info[] 11 | info.project.version=@project.version@ 12 | info.java.version=@java.version@ 13 | info.spring.framework.version=@spring-framework.version@ 14 | info.spring.data.version=@spring-data-bom.version@ 15 | # end::info[] 16 | spring.webflux.hiddenmethod.filter.enabled=true 17 | -------------------------------------------------------------------------------- /7-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplication.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | 8 | @SpringBootApplication 9 | public class HackingSpringBootApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(HackingSpringBootApplication.class, args); 13 | } 14 | 15 | // tag::jackson[] 16 | @Bean 17 | Jackson2JsonMessageConverter jackson2JsonMessageConverter() { 18 | return new Jackson2JsonMessageConverter(); 19 | } 20 | // end::jackson[] 21 | } 22 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | /** 20 | * @author Greg Turnquist 21 | */ 22 | public class Cart { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /7-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /8-reactive-server/src/main/java/com/greglturnquist/hackingspringboot/reactive/server/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive.server; 18 | 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | } 23 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /8-reactive-client/src/main/java/com/greglturnquist/hackingspringboot/reactive/client/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive.client; 18 | 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | // tag::code[] 19 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 20 | 21 | public interface ItemRepository extends ReactiveCrudRepository { 22 | 23 | } 24 | // end::code[] 25 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HackingSpringBootApplicationBlockHoundCustomized.java: -------------------------------------------------------------------------------- 1 | package com.greglturnquist.hackingspringboot.reactive; 2 | 3 | import org.thymeleaf.TemplateEngine; 4 | import reactor.blockhound.BlockHound; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.util.JdkIdGenerator; 10 | import org.springframework.web.filter.reactive.HiddenHttpMethodFilter; 11 | 12 | @SpringBootApplication 13 | public class HackingSpringBootApplicationBlockHoundCustomized { 14 | 15 | // tag::blockhound[] 16 | public static void main(String[] args) { 17 | BlockHound.builder() // <1> 18 | .allowBlockingCallsInside( // 19 | TemplateEngine.class.getCanonicalName(), "process") // <2> 20 | .install(); // <3> 21 | 22 | SpringApplication.run(HackingSpringBootApplicationBlockHoundCustomized.class, args); 23 | } 24 | // end::blockhound[] 25 | } 26 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | 22 | public interface ItemRepository extends ReactiveCrudRepository { 23 | 24 | Mono findByName(String name); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | public interface CartRepository extends ReactiveCrudRepository { 25 | 26 | } 27 | // end::code[] 28 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | 22 | public interface ItemRepository extends ReactiveCrudRepository { 23 | 24 | Mono findByName(String name); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | 22 | public interface ItemRepository extends ReactiveCrudRepository { 23 | 24 | Mono findByName(String name); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemByExampleRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface ItemByExampleRepository extends ReactiveQueryByExampleExecutor { 26 | 27 | } 28 | // end::code[] 29 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemByExampleRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface ItemByExampleRepository extends ReactiveQueryByExampleExecutor { 26 | 27 | } 28 | // end::code[] 29 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemByExampleRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface ItemByExampleRepository extends ReactiveQueryByExampleExecutor { 26 | 27 | } 28 | // end::code[] 29 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemByExampleRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface ItemByExampleRepository extends ReactiveQueryByExampleExecutor { 26 | 27 | } 28 | // end::code[] 29 | -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/BlockingItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.CrudRepository; 19 | 20 | import com.greglturnquist.hackingspringboot.reactive.Item; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | interface BlockingItemRepository extends CrudRepository { 27 | 28 | } 29 | // end::code[] 30 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/BlockingItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.repository.CrudRepository; 19 | 20 | import com.greglturnquist.hackingspringboot.reactive.Item; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | interface BlockingItemRepository extends CrudRepository { 27 | 28 | } 29 | // end::code[] 30 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import reactor.core.publisher.Mono; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface UserRepository extends CrudRepository { 26 | 27 | Mono findByName(String name); 28 | } 29 | // end::code[] 30 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import reactor.core.publisher.Mono; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface UserRepository extends CrudRepository { 26 | 27 | Mono findByName(String name); 28 | } 29 | // end::code[] 30 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import reactor.core.publisher.Mono; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface UserRepository extends CrudRepository { 26 | 27 | Mono findByName(String name); 28 | } 29 | // end::code[] 30 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/UserRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import reactor.core.publisher.Mono; 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author Greg Turnquist 23 | */ 24 | // tag::code[] 25 | public interface UserRepository extends CrudRepository { 26 | 27 | Mono findByName(String name); 28 | 29 | } 30 | // end::code[] 31 | -------------------------------------------------------------------------------- /6-reactive/src/main/asciidoc/index.adoc: -------------------------------------------------------------------------------- 1 | = 스프링 부트 실전 활용 마스터 2 | 3 | 웹 서비스를 출시하면 개발자들에게 사용법을 알려줘야 합니다. 4 | 5 | 스프링 레스트 독 덕분에 테스트 케이스에서 서비스의 모든 상호 작용을 추출하고 읽기 좋은 문서를 자동으로 만들 수 있으며, + 6 | IDE를 통해 아주 쉽게 작업을 수행할 수 있습니다. 7 | 8 | 9 | 다음 요청을 실행하면: 10 | 11 | include::{snippets}/findAll/curl-request.adoc[] 12 | 13 | `ApiItemController`는 다음과 같은 응답을 반환합니다. 14 | 15 | include::{snippets}/findAll/response-body.adoc[] 16 | 17 | HTTPie를 사용하시나요? 다음 명령을 실행해보세요. 18 | 19 | include::{snippets}/findAll/httpie-request.adoc[] 20 | 21 | 동일한 응답 본문이 반환됩니다. curl과 HTTPie 중 좋아하는 것을 사용하시면 됩니다. 22 | 23 | ''' 24 | == 상품 25 | 26 | === 한 건 조회 27 | 28 | ==== 요청 29 | 30 | ===== http 31 | 32 | include::{snippets}/findOne-hypermedia/http-request.adoc[] 33 | 34 | ===== curl 35 | 36 | include::{snippets}/findOne-hypermedia/curl-request.adoc[] 37 | 38 | ===== HTTPie 39 | 40 | include::{snippets}/findOne-hypermedia/httpie-request.adoc[] 41 | 42 | ==== 응답 43 | 44 | include::{snippets}/findOne-hypermedia/http-response.adoc[] 45 | 46 | ===== 응답 본문 47 | 48 | include::{snippets}/findOne-hypermedia/response-body.adoc[] 49 | 50 | ===== 링크 51 | 52 | include::{snippets}/findOne-hypermedia/links.adoc[] 53 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HomeController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // tag::code[] 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | import org.springframework.stereotype.Controller; 21 | import org.springframework.ui.Model; 22 | import org.springframework.web.bind.annotation.GetMapping; 23 | 24 | @Controller 25 | public class HomeController { 26 | 27 | @GetMapping 28 | Mono home() { 29 | return Mono.just("home"); 30 | } 31 | } 32 | // end::code[] -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/InventoryService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.stereotype.Service; 19 | import reactor.core.publisher.Flux; 20 | 21 | import com.greglturnquist.hackingspringboot.reactive.Item; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Service 28 | class InventoryService { 29 | 30 | Flux getItems() { 31 | // imagine calling a remote service! 32 | return Flux.empty(); 33 | } 34 | 35 | } 36 | // end::code[] 37 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HttpTraceWrapperRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.Repository; 20 | 21 | import java.util.stream.Stream; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | public interface HttpTraceWrapperRepository extends // 28 | Repository { 29 | 30 | Stream findAll(); // <1> 31 | 32 | void save(HttpTraceWrapper trace); // <2> 33 | } 34 | // end::code[] 35 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/HttpTraceWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.boot.actuate.trace.http.HttpTrace; 20 | import org.springframework.data.annotation.Id; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | public class HttpTraceWrapper { 27 | 28 | private @Id String id; // <1> 29 | 30 | private HttpTrace httpTrace; // <2> 31 | 32 | public HttpTraceWrapper(HttpTrace httpTrace) { // <3> 33 | this.httpTrace = httpTrace; 34 | } 35 | 36 | public HttpTrace getHttpTrace() { // <4> 37 | return httpTrace; 38 | } 39 | } 40 | // end::code[] 41 | -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/RepositoryDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.stereotype.Component; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Component // <1> 27 | public class RepositoryDatabaseLoader { 28 | 29 | @Bean // <2> 30 | CommandLineRunner initialize(BlockingItemRepository repository) { // <3> 31 | return args -> { // <4> 32 | repository.save(new Item("Alf alarm clock", 19.99)); 33 | repository.save(new Item("Smurf TV tray", 24.99)); 34 | }; 35 | } 36 | } 37 | // end::code[] 38 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/RepositoryDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.stereotype.Component; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Component // <1> 27 | public class RepositoryDatabaseLoader { 28 | 29 | @Bean // <2> 30 | CommandLineRunner initialize(BlockingItemRepository repository) { // <3> 31 | return args -> { // <4> 32 | repository.save(new Item("Alf alarm clock", "kids clock", 19.99)); 33 | repository.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 34 | }; 35 | } 36 | } 37 | // end::code[] 38 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/DatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class DatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/DatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class DatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/DatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class DatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/DatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class DatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/DatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class DatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | }; 36 | } 37 | } 38 | // end::code[] 39 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/TemplateDatabaseLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.boot.CommandLineRunner; 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.data.mongodb.core.MongoOperations; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Component 28 | public class TemplateDatabaseLoader { 29 | 30 | @Bean 31 | CommandLineRunner initialize(MongoOperations mongo) { 32 | return args -> { 33 | mongo.save(new Item("Alf alarm clock", "kids clock", 19.99)); 34 | mongo.save(new Item("Smurf TV tray", "kids TV tray", 24.99)); 35 | // mongo.save(new Item("TEST", "TEST", 99.99)); // 계층화 이미지 빌드 확인 시 주석 해제 36 | }; 37 | } 38 | } 39 | // end::code[] 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/intellij,maven 2 | # Edit at https://www.gitignore.io/?templates=intellij,maven 3 | 4 | ### Intellij ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff 9 | .idea 10 | 11 | # Gradle and Maven with auto-import 12 | # When using Gradle or Maven with auto-import, you should exclude module files, 13 | # since they will be recreated, and may cause churn. Uncomment if using 14 | # auto-import. 15 | # .idea/modules.xml 16 | # .idea/*.iml 17 | # .idea/modules 18 | *.iml 19 | # *.ipr 20 | 21 | # CMake 22 | cmake-build-*/ 23 | 24 | # Mongo Explorer plugin 25 | .idea/**/mongoSettings.xml 26 | 27 | # File-based project format 28 | *.iws 29 | 30 | # IntelliJ 31 | out/ 32 | 33 | # mpeltonen/sbt-idea plugin 34 | .idea_modules/ 35 | 36 | # JIRA plugin 37 | atlassian-ide-plugin.xml 38 | 39 | # Crashlytics plugin (for Android Studio and IntelliJ) 40 | com_crashlytics_export_strings.xml 41 | crashlytics.properties 42 | crashlytics-build.properties 43 | fabric.properties 44 | 45 | ### Maven ### 46 | target/ 47 | pom.xml.tag 48 | pom.xml.releaseBackup 49 | pom.xml.versionsBackup 50 | pom.xml.next 51 | release.properties 52 | dependency-reduced-pom.xml 53 | buildNumber.properties 54 | .mvn/timing.properties 55 | .mvn/wrapper/maven-wrapper.jar 56 | .flattened-pom.xml 57 | 58 | # End of https://www.gitignore.io/api/intellij,maven 59 | 60 | ### jenv 61 | .java-version 62 | 63 | -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/InventoryController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.web.bind.annotation.GetMapping; 19 | import org.springframework.web.bind.annotation.RequestParam; 20 | import org.springframework.web.bind.annotation.RestController; 21 | import reactor.core.publisher.Flux; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @RestController 28 | class InventoryController { 29 | 30 | private InventoryService service; 31 | 32 | InventoryController(InventoryService service) { 33 | this.service = service; 34 | } 35 | 36 | @GetMapping(value = "/items", produces = "application/stream+json") 37 | Flux findInventoryData(@RequestParam("q") String q) { 38 | return this.service.getItems() 39 | .filter(item -> item.getName().contains(q)); 40 | } 41 | } 42 | // end::code[] 43 | -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/Sample1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | /** 19 | * @author Greg Turnquist 20 | */ 21 | public class Sample1 { 22 | 23 | void demo1() { 24 | 25 | Cart cart = new Cart("My Cart"); 26 | 27 | // tag::1[] 28 | boolean found = false; 29 | 30 | for (CartItem cartItem : cart.getCartItems()) { 31 | if (cartItem.getItem().getId().equals("5")) { 32 | found = true; 33 | } 34 | } 35 | 36 | if (found) { 37 | // increment 38 | } else { 39 | // add new CartItem 40 | } 41 | // end::1[] 42 | } 43 | 44 | void demo2() { 45 | 46 | Cart cart = new Cart("My Cart"); 47 | 48 | // tag::2[] 49 | if (cart.getCartItems().stream() // 50 | .anyMatch(cartItem -> cartItem.getItem().getId().equals("5"))) { 51 | // increment 52 | } else { 53 | // add new CartItem 54 | } 55 | // end::2[] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/Sample1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | /** 19 | * @author Greg Turnquist 20 | */ 21 | public class Sample1 { 22 | 23 | void demo1() { 24 | 25 | Cart cart = new Cart("My Cart"); 26 | 27 | // tag::1[] 28 | boolean found = false; 29 | 30 | for (CartItem cartItem : cart.getCartItems()) { 31 | if (cartItem.getItem().getId().equals("5")) { 32 | found = true; 33 | } 34 | } 35 | 36 | if (found) { 37 | // increment 38 | } else { 39 | // add new CartItem 40 | } 41 | // end::1[] 42 | } 43 | 44 | void demo2() { 45 | 46 | Cart cart = new Cart("My Cart"); 47 | 48 | // tag::2[] 49 | if (cart.getCartItems().stream() // 50 | .anyMatch(cartItem -> cartItem.getItem().getId().equals("5"))) { 51 | // increment 52 | } else { 53 | // add new CartItem 54 | } 55 | // end::2[] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /2-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/HomeController2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.web.bind.annotation.PostMapping; 20 | import reactor.core.publisher.Mono; 21 | import org.springframework.stereotype.Controller; 22 | import org.springframework.web.bind.annotation.GetMapping; 23 | import org.springframework.web.bind.annotation.PathVariable; 24 | 25 | /** 26 | * @author Greg Turnquist 27 | */ 28 | @Controller 29 | public class HomeController2 { 30 | 31 | private final CartService cartService; 32 | 33 | public HomeController2(CartService cartService) { 34 | this.cartService = cartService; 35 | } 36 | 37 | // tag::4[] 38 | @PostMapping("/add/{id}") 39 | Mono addToCart(@PathVariable String id) { 40 | return this.cartService.addToCart("My Cart", id) // 41 | .thenReturn("redirect:/"); 42 | } 43 | // end::4[] 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Dish.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // tag::dish[] 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import java.util.Objects; 20 | 21 | class Dish { 22 | 23 | private String description; 24 | private boolean delivered = false; 25 | 26 | public static Dish deliver(Dish dish) { 27 | Dish deliveredDish = new Dish(dish.description); 28 | deliveredDish.delivered = true; 29 | return deliveredDish; 30 | } 31 | 32 | Dish(String description) { 33 | this.description = description; 34 | } 35 | 36 | public String getDescription() { 37 | return description; 38 | } 39 | 40 | public void setDescription(String description) { 41 | this.description = description; 42 | } 43 | 44 | public boolean isDelivered() { 45 | return delivered; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "Dish{" + // 51 | "description='" + description + '\'' + // 52 | ", delivered=" + delivered + // 53 | '}'; 54 | } 55 | } 56 | // end::dish[] 57 | -------------------------------------------------------------------------------- /2b-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
IdNameQuantity
46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ServerController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // tag::controller[] 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Flux; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.GetMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | @RestController 25 | public class ServerController { 26 | 27 | private final KitchenService kitchen; 28 | 29 | public ServerController(KitchenService kitchen) { 30 | this.kitchen = kitchen; 31 | } 32 | 33 | @GetMapping(value = "/server", produces = MediaType.TEXT_EVENT_STREAM_VALUE) 34 | Flux serveDishes() { 35 | return this.kitchen.getDishes(); 36 | } 37 | // end::controller[] 38 | 39 | // tag::deliver[] 40 | @GetMapping(value = "/served-dishes", produces = MediaType.TEXT_EVENT_STREAM_VALUE) 41 | Flux deliverDishes() { 42 | return this.kitchen.getDishes() // 43 | .map(dish -> Dish.deliver(dish)); 44 | } 45 | // end::deliver[] 46 | } 47 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/HomeController2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Controller; 20 | import org.springframework.web.bind.annotation.GetMapping; 21 | import org.springframework.web.bind.annotation.PathVariable; 22 | import org.springframework.web.bind.annotation.PostMapping; 23 | import reactor.core.publisher.Mono; 24 | 25 | import com.greglturnquist.hackingspringboot.reactive.CartService; 26 | 27 | /** 28 | * @author Greg Turnquist 29 | */ 30 | @Controller 31 | public class HomeController2 { 32 | 33 | private final CartService cartService; 34 | 35 | public HomeController2(CartService cartService) { 36 | this.cartService = cartService; 37 | } 38 | 39 | // tag::4[] 40 | @PostMapping("/add/{id}") 41 | Mono addToCart(@PathVariable String id) { 42 | return this.cartService.addToCart("My Cart", id) // 43 | .thenReturn("redirect:/"); 44 | } 45 | // end::4[] 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /1-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/KitchenService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | // tag::code[] 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Service; 20 | import reactor.core.publisher.Flux; 21 | 22 | import java.time.Duration; 23 | import java.util.Arrays; 24 | import java.util.List; 25 | import java.util.Random; 26 | 27 | @Service 28 | public class KitchenService { 29 | 30 | /** 31 | * Generates continuous stream of dishes. 32 | */ 33 | Flux getDishes() { 34 | return Flux. generate(sink -> sink.next(randomDish())) // 35 | .delayElements(Duration.ofMillis(250)); 36 | } 37 | 38 | /** 39 | * Randomly pick the next dish. 40 | */ 41 | private Dish randomDish() { 42 | return menu.get(picker.nextInt(menu.size())); 43 | } 44 | 45 | private List menu = Arrays.asList( // 46 | new Dish("Sesame chicken"), // 47 | new Dish("Lo mein noodles, plain"), // 48 | new Dish("Sweet & sour beef")); 49 | 50 | private Random picker = new Random(); 51 | } 52 | // end::code[] 53 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/InventoryController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.web.bind.annotation.GetMapping; 19 | import org.springframework.web.bind.annotation.RequestParam; 20 | import org.springframework.web.bind.annotation.RestController; 21 | import reactor.core.publisher.Flux; 22 | 23 | import com.greglturnquist.hackingspringboot.reactive.InventoryService; 24 | import com.greglturnquist.hackingspringboot.reactive.Item; 25 | 26 | /** 27 | * @author Greg Turnquist 28 | */ 29 | // tag::code[] 30 | @RestController 31 | class InventoryController { 32 | 33 | private InventoryService service; 34 | 35 | InventoryController(InventoryService service) { 36 | this.service = service; 37 | } 38 | 39 | @GetMapping(value = "/items", produces = "application/stream+json") 40 | Flux findInventoryData(@RequestParam("q") String q) { 41 | return this.service.getItems() // 42 | .filter(item -> item.getName().contains(q)); 43 | } 44 | } 45 | // end::code[] 46 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/SpringDataHttpTraceRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.boot.actuate.trace.http.HttpTrace; 20 | import org.springframework.boot.actuate.trace.http.HttpTraceRepository; 21 | 22 | import java.util.List; 23 | import java.util.stream.Collectors; 24 | 25 | /** 26 | * @author Greg Turnquist 27 | */ 28 | // tag::code[] 29 | public class SpringDataHttpTraceRepository implements HttpTraceRepository { 30 | 31 | private final HttpTraceWrapperRepository repository; 32 | 33 | public SpringDataHttpTraceRepository(HttpTraceWrapperRepository repository) { 34 | this.repository = repository; // <1> 35 | } 36 | 37 | @Override 38 | public List findAll() { 39 | return repository.findAll() // 40 | .map(HttpTraceWrapper::getHttpTrace) // <2> 41 | .collect(Collectors.toList()); 42 | } 43 | 44 | @Override 45 | public void add(HttpTrace trace) { 46 | repository.save(new HttpTraceWrapper(trace)); // <3> 47 | } 48 | } 49 | // end::code[] 50 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 50 |
IdNameQuantity
44 |
45 | 46 |
47 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 50 |
IdNameQuantity
44 |
45 | 46 |
47 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /2b-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/FluentService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.mongodb.core.ReactiveFluentMongoOperations; 20 | import org.springframework.stereotype.Service; 21 | import reactor.core.publisher.Flux; 22 | 23 | import static org.springframework.data.mongodb.core.query.Criteria.where; 24 | import static org.springframework.data.mongodb.core.query.Query.query; 25 | 26 | import com.greglturnquist.hackingspringboot.reactive.Item; 27 | 28 | /** 29 | * @author Greg Turnquist 30 | */ 31 | @Service 32 | public class FluentService { 33 | 34 | private final ReactiveFluentMongoOperations fluentMongoOperations; 35 | 36 | public FluentService(ReactiveFluentMongoOperations fluentMongoOperations) { 37 | this.fluentMongoOperations = fluentMongoOperations; 38 | } 39 | 40 | Flux searchFluently(String name, String description) { 41 | return fluentMongoOperations.query(Item.class) // 42 | .matching(query(where("name").is(name).and("description").is(description))) // 43 | .all(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /4-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/BlockHoundUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import java.time.Duration; 22 | 23 | import org.junit.jupiter.api.Test; 24 | import reactor.core.publisher.Mono; 25 | import reactor.test.StepVerifier; 26 | 27 | /** 28 | * @author Greg Turnquist 29 | */ 30 | class BlockHoundUnitTest { 31 | 32 | // tag::obvious-failure[] 33 | @Test 34 | void threadSleepIsABlockingCall() { 35 | Mono.delay(Duration.ofSeconds(1)) // <1> 36 | .flatMap(tick -> { 37 | try { 38 | Thread.sleep(10); // <2> 39 | return Mono.just(true); 40 | } catch (InterruptedException e) { 41 | return Mono.error(e); 42 | } 43 | }) // 44 | .as(StepVerifier::create) // 45 | .verifyComplete(); 46 | // .verifyErrorMatches(throwable -> { 47 | // assertThat(throwable.getMessage()) // 48 | // .contains("Blocking call! java.lang.Thread.sleep"); 49 | // return true; 50 | // }); 51 | 52 | } 53 | // end::obvious-failure[] 54 | 55 | } 56 | -------------------------------------------------------------------------------- /4-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/ItemUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | 23 | import com.greglturnquist.hackingspringboot.reactive.Item; 24 | 25 | /** 26 | * @author Greg Turnquist 27 | */ 28 | // tag::code[] 29 | class ItemUnitTest { 30 | 31 | @Test // <1> 32 | void itemBasicsShouldWork() { 33 | Item sampleItem = new Item("item1", "TV tray", "Alf TV tray", 19.99); // <2> 34 | 35 | // Test various aspects using AssertJ <3> 36 | assertThat(sampleItem.getId()).isEqualTo("item1"); 37 | assertThat(sampleItem.getName()).isEqualTo("TV tray"); 38 | assertThat(sampleItem.getDescription()).isEqualTo("Alf TV tray"); 39 | assertThat(sampleItem.getPrice()).isEqualTo(19.99); 40 | 41 | assertThat(sampleItem.toString()).isEqualTo( // 42 | "Item{id='item1', name='TV tray', description='Alf TV tray', price=19.99}"); 43 | 44 | Item sampleItem2 = new Item("item1", "TV tray", "Alf TV tray", 19.99); 45 | assertThat(sampleItem).isEqualTo(sampleItem2); 46 | } 47 | } 48 | // end::code[] 49 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/test/java/com/greglturnquist/hackingspringboot/reactive/HomeControllerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.junit.jupiter.api.Test; 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; 21 | import org.springframework.boot.test.context.SpringBootTest; 22 | import org.springframework.security.test.context.support.WithMockUser; 23 | import org.springframework.test.web.reactive.server.WebTestClient; 24 | 25 | /** 26 | * @author Greg Turnquist 27 | */ 28 | @SpringBootTest 29 | @AutoConfigureWebTestClient 30 | public class HomeControllerTest { 31 | 32 | @Autowired WebTestClient webTestClient; 33 | 34 | @Autowired ItemRepository repository; 35 | 36 | @Test 37 | void verifyLoginPageBlocksAccess() { 38 | this.webTestClient.get().uri("/") // 39 | .exchange() // 40 | .expectStatus().isUnauthorized(); 41 | } 42 | 43 | @Test 44 | @WithMockUser(username = "ada") 45 | void verifyLoginPageWorks() { 46 | this.webTestClient.get().uri("/") // 47 | .exchange() // 48 | .expectStatus().isOk(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /4-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/MongoDbSliceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import static org.assertj.core.api.Assertions.*; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import reactor.test.StepVerifier; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; 25 | 26 | /** 27 | * @author Greg Turnquist 28 | */ 29 | // tag::code[] 30 | @DataMongoTest // <1> 31 | public class MongoDbSliceTest { 32 | 33 | @Autowired ItemRepository repository; // <2> 34 | 35 | @Test // <3> 36 | void itemRepositorySavesItems() { 37 | Item sampleItem = new Item( // 38 | "name", "description", 1.99); 39 | 40 | repository.save(sampleItem) // 41 | .as(StepVerifier::create) // 42 | .expectNextMatches(item -> { 43 | assertThat(item.getId()).isNotNull(); 44 | assertThat(item.getName()).isEqualTo("name"); 45 | assertThat(item.getDescription()).isEqualTo("description"); 46 | assertThat(item.getPrice()).isEqualTo(1.99); 47 | 48 | return true; 49 | }) // 50 | .verifyComplete(); 51 | } 52 | } 53 | // end::code[] 54 | -------------------------------------------------------------------------------- /3-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 50 |
IdNameQuantity
44 |
45 | 46 |
47 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /4-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 50 |
IdNameQuantity
44 |
45 | 46 |
47 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /5-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 |
IdNamePrice
20 |
21 | 22 |
23 |
25 |
26 | 27 |
28 |
32 | 33 | 34 | 35 |

My Cart

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 48 | 49 | 50 |
IdNameQuantity
44 |
45 | 46 |
47 |
51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /2-reactive/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 |

Welcome to Hacking with Spring Boot!

9 | 10 | 11 |

Inventory Management

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 30 | 35 | 36 | 37 |
IdNamePrice
26 |
27 | 28 |
29 |
31 |
32 | 33 |
34 |
38 | 39 | 40 | 41 |

My Cart

42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
IdNameQuantity
58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
Name:
Authorities:
20 |
21 | 22 |
23 |
24 | 25 | 26 |

Welcome to Hacking with Spring Boot!

27 | 28 | 29 | 30 |

Inventory Management

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 |
IdNamePrice
40 |
41 | 42 |
43 |
46 | 47 | 48 | 49 |

My Cart

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 63 | 64 |
IdNameQuantity
59 |
60 | 61 |
62 |
65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Hacking with Spring Boot - Getting Started 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
Name:
Authorities:
20 |
21 | 22 |
23 |
24 | 25 | 26 |

Welcome to Hacking with Spring Boot!

27 | 28 | 29 | 30 |

Inventory Management

31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 |
IdNamePrice
40 |
41 | 42 |
43 |
46 | 47 | 48 | 49 |

My Cart

50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 63 | 64 |
IdNameQuantity
59 |
60 | 61 |
62 |
65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | // end::code[] 36 | 37 | public void increment() { 38 | this.quantity++; 39 | } 40 | 41 | public Item getItem() { 42 | return item; 43 | } 44 | 45 | public void setItem(Item item) { 46 | this.item = item; 47 | } 48 | 49 | public int getQuantity() { 50 | return quantity; 51 | } 52 | 53 | public void setQuantity(int quantity) { 54 | this.quantity = quantity; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) 60 | return true; 61 | if (o == null || getClass() != o.getClass()) 62 | return false; 63 | CartItem cartItem = (CartItem) o; 64 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | return Objects.hash(item, quantity); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | // end::code[] 36 | 37 | public void increment() { 38 | this.quantity++; 39 | } 40 | 41 | public Item getItem() { 42 | return item; 43 | } 44 | 45 | public void setItem(Item item) { 46 | this.item = item; 47 | } 48 | 49 | public int getQuantity() { 50 | return quantity; 51 | } 52 | 53 | public void setQuantity(int quantity) { 54 | this.quantity = quantity; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) 60 | return true; 61 | if (o == null || getClass() != o.getClass()) 62 | return false; 63 | CartItem cartItem = (CartItem) o; 64 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | return Objects.hash(item, quantity); 70 | } 71 | 72 | @Override 73 | public String toString() { 74 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.greglturnquist 7 | hacking-spring-boot-parent 8 | 1.0.0.BUILD-SNAPSHOT 9 | pom 10 | 11 | Hacking with Spring Boot 12 | 13 | 2019 14 | 15 | 16 | 17 | Apache License, Version 2.0 18 | http://www.apache.org/licenses/LICENSE-2.0 19 | 20 | Copyright 2019 the original author or authors. 21 | 22 | Licensed under the Apache License, Version 2.0 (the "License"); 23 | you may not use this file except in compliance with the License. 24 | You may obtain a copy of the License at 25 | 26 | http://www.apache.org/licenses/LICENSE-2.0 27 | 28 | Unless required by applicable law or agreed to in writing, software 29 | distributed under the License is distributed on an "AS IS" BASIS, 30 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 31 | implied. 32 | See the License for the specific language governing permissions and 33 | limitations under the License. 34 | 35 | 36 | 37 | 38 | 39 | 1-reactive 40 | 2-reactive 41 | 2b-reactive 42 | 3-reactive 43 | 4-reactive 44 | 5-reactive 45 | 6-reactive 46 | 7-reactive 47 | 8-reactive-server 48 | 8-reactive-client 49 | 9-reactive-quick 50 | 9-reactive-repository 51 | 9-reactive-custom-config 52 | 9-reactive-method-security 53 | 9-reactive-oauth 54 | 55 | 56 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Service; 20 | import reactor.core.publisher.Mono; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Service // <1> 27 | class CartService { 28 | 29 | private final ItemRepository itemRepository; 30 | private final CartRepository cartRepository; 31 | 32 | CartService(ItemRepository itemRepository, // <2> 33 | CartRepository cartRepository) { 34 | this.itemRepository = itemRepository; 35 | this.cartRepository = cartRepository; 36 | } 37 | 38 | Mono addToCart(String cartId, String id) { // <3> 39 | return this.cartRepository.findById(cartId) // 40 | .defaultIfEmpty(new Cart(cartId)) // 41 | .flatMap(cart -> cart.getCartItems().stream() // 42 | .filter(cartItem -> cartItem.getItem().getId().equals(id)) // 43 | .findAny() // 44 | .map(cartItem -> { 45 | cartItem.increment(); 46 | return Mono.just(cart); 47 | }).orElseGet(() -> { 48 | return this.itemRepository.findById(id) // 49 | .map(CartItem::new) // <4> 50 | .doOnNext(cartItem -> cart.getCartItems().add(cartItem)) // 51 | .map(cartItem -> cart); 52 | })) 53 | .flatMap(this.cartRepository::save); // <5> 54 | } 55 | } 56 | // end::code[] 57 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Service; 20 | import reactor.core.publisher.Mono; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Service // <1> 27 | class CartService { 28 | 29 | private final ItemRepository itemRepository; 30 | private final CartRepository cartRepository; 31 | 32 | CartService(ItemRepository itemRepository, // <2> 33 | CartRepository cartRepository) { 34 | this.itemRepository = itemRepository; 35 | this.cartRepository = cartRepository; 36 | } 37 | 38 | Mono addToCart(String cartId, String id) { // <3> 39 | return this.cartRepository.findById(cartId) // 40 | .defaultIfEmpty(new Cart(cartId)) // 41 | .flatMap(cart -> cart.getCartItems().stream() // 42 | .filter(cartItem -> cartItem.getItem().getId().equals(id)) // 43 | .findAny() // 44 | .map(cartItem -> { 45 | cartItem.increment(); 46 | return Mono.just(cart); 47 | }).orElseGet(() -> { 48 | return this.itemRepository.findById(id) // 49 | .map(CartItem::new) // <4> 50 | .doOnNext(cartItem -> cart.getCartItems().add(cartItem)) // 51 | .map(cartItem -> cart); 52 | })) 53 | .flatMap(this.cartRepository::save); // <5> 54 | } 55 | } 56 | // end::code[] 57 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Service; 20 | import reactor.core.publisher.Mono; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Service // <1> 27 | class CartService { 28 | 29 | private final ItemRepository itemRepository; 30 | private final CartRepository cartRepository; 31 | 32 | CartService(ItemRepository itemRepository, // <2> 33 | CartRepository cartRepository) { 34 | this.itemRepository = itemRepository; 35 | this.cartRepository = cartRepository; 36 | } 37 | 38 | Mono addToCart(String cartId, String id) { // <3> 39 | return this.cartRepository.findById(cartId) // 40 | .defaultIfEmpty(new Cart(cartId)) // 41 | .flatMap(cart -> cart.getCartItems().stream() // 42 | .filter(cartItem -> cartItem.getItem().getId().equals(id)) // 43 | .findAny() // 44 | .map(cartItem -> { 45 | cartItem.increment(); 46 | return Mono.just(cart); 47 | }).orElseGet(() -> { 48 | return this.itemRepository.findById(id) // 49 | .map(CartItem::new) // <4> 50 | .doOnNext(cartItem -> cart.getCartItems().add(cartItem)) // 51 | .map(cartItem -> cart); 52 | })) 53 | .flatMap(this.cartRepository::save); // <5> 54 | } 55 | } 56 | // end::code[] 57 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.stereotype.Service; 20 | import reactor.core.publisher.Mono; 21 | 22 | /** 23 | * @author Greg Turnquist 24 | */ 25 | // tag::code[] 26 | @Service // <1> 27 | class CartService { 28 | 29 | private final ItemRepository itemRepository; 30 | private final CartRepository cartRepository; 31 | 32 | CartService(ItemRepository itemRepository, // <2> 33 | CartRepository cartRepository) { 34 | this.itemRepository = itemRepository; 35 | this.cartRepository = cartRepository; 36 | } 37 | 38 | Mono addToCart(String cartId, String id) { // <3> 39 | return this.cartRepository.findById(cartId) // 40 | .defaultIfEmpty(new Cart(cartId)) // 41 | .flatMap(cart -> cart.getCartItems().stream() // 42 | .filter(cartItem -> cartItem.getItem().getId().equals(id)) // 43 | .findAny() // 44 | .map(cartItem -> { 45 | cartItem.increment(); 46 | return Mono.just(cart); 47 | }).orElseGet(() -> { 48 | return this.itemRepository.findById(id) // 49 | .map(CartItem::new) // <4> 50 | .doOnNext(cartItem -> cart.getCartItems().add(cartItem)) // 51 | .map(cartItem -> cart); 52 | })) 53 | .flatMap(this.cartRepository::save); // <5> 54 | } 55 | } 56 | // end::code[] 57 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | 21 | import org.springframework.stereotype.Service; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Service // <1> 28 | class CartService { 29 | 30 | private final ItemRepository itemRepository; 31 | private final CartRepository cartRepository; 32 | 33 | CartService(ItemRepository itemRepository, CartRepository cartRepository) { // <2> 34 | this.itemRepository = itemRepository; 35 | this.cartRepository = cartRepository; 36 | } 37 | 38 | Mono addToCart(String cartId, String id) { // <3> 39 | return this.cartRepository.findById(cartId) // 40 | .defaultIfEmpty(new Cart(cartId)) // 41 | .flatMap(cart -> cart.getCartItems().stream() // 42 | .filter(cartItem -> cartItem.getItem() // 43 | .getId().equals(id)) // 44 | .findAny() // 45 | .map(cartItem -> { 46 | cartItem.increment(); 47 | return Mono.just(cart); 48 | }) // 49 | .orElseGet(() -> // 50 | this.itemRepository.findById(id) // 51 | .map(CartItem::new) // <4> 52 | .doOnNext(cartItem -> // 53 | cart.getCartItems().add(cartItem)) // 54 | .map(cartItem -> cart))) 55 | .flatMap(this.cartRepository::save); // <5> 56 | } 57 | } 58 | // end::code[] 59 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.mongodb.repository.Query; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | import reactor.core.publisher.Flux; 22 | 23 | // tag::code[] 24 | public interface ItemRepository extends ReactiveCrudRepository { 25 | 26 | Flux findByNameContaining(String partialName); 27 | // end::code[] 28 | 29 | // tag::code-2[] 30 | @Query("{ 'name' : ?0, 'age' : }") 31 | Flux findItemsForCustomerMonthlyReport(); 32 | 33 | @Query(sort = "{ 'age' : -1", value = "{ 'name' : 'TV tray', 'age' : }") 34 | Flux findSortedStuffForWeeklyReport(); 35 | // end::code-2[] 36 | 37 | // tag::code-3[] 38 | // search by name 39 | Flux findByNameContainingIgnoreCase(String partialName); 40 | 41 | // search by description 42 | Flux findByDescriptionContainingIgnoreCase(String partialName); 43 | 44 | // search by name AND description 45 | Flux findByNameContainingAndDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 46 | 47 | // search by name OR description 48 | Flux findByNameContainingOrDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 49 | // end::code-3[] 50 | } 51 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.mongodb.repository.Query; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | import reactor.core.publisher.Flux; 22 | 23 | // tag::code[] 24 | public interface ItemRepository extends ReactiveCrudRepository { 25 | 26 | Flux findByNameContaining(String partialName); 27 | // end::code[] 28 | 29 | // tag::code-2[] 30 | @Query("{ 'name' : ?0, 'age' : }") 31 | Flux findItemsForCustomerMonthlyReport(); 32 | 33 | @Query(sort = "{ 'age' : -1", value = "{ 'name' : 'TV tray', 'age' : }") 34 | Flux findSortedStuffForWeeklyReport(); 35 | // end::code-2[] 36 | 37 | // tag::code-3[] 38 | // search by name 39 | Flux findByNameContainingIgnoreCase(String partialName); 40 | 41 | // search by description 42 | Flux findByDescriptionContainingIgnoreCase(String partialName); 43 | 44 | // search by name AND description 45 | Flux findByNameContainingAndDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 46 | 47 | // search by name OR description 48 | Flux findByNameContainingOrDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 49 | // end::code-3[] 50 | } 51 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.mongodb.repository.Query; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | import reactor.core.publisher.Flux; 22 | 23 | // tag::code[] 24 | public interface ItemRepository extends ReactiveCrudRepository { 25 | 26 | Flux findByNameContaining(String partialName); 27 | // end::code[] 28 | 29 | // tag::code-2[] 30 | @Query("{ 'name' : ?0, 'age' : }") 31 | Flux findItemsForCustomerMonthlyReport(); 32 | 33 | @Query(sort = "{ 'age' : -1", value = "{ 'name' : 'TV tray', 'age' : }") 34 | Flux findSortedStuffForWeeklyReport(); 35 | // end::code-2[] 36 | 37 | // tag::code-3[] 38 | // search by name 39 | Flux findByNameContainingIgnoreCase(String partialName); 40 | 41 | // search by description 42 | Flux findByDescriptionContainingIgnoreCase(String partialName); 43 | 44 | // search by name AND description 45 | Flux findByNameContainingAndDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 46 | 47 | // search by name OR description 48 | Flux findByNameContainingOrDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 49 | // end::code-3[] 50 | } 51 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import reactor.core.publisher.Mono; 20 | 21 | import org.springframework.stereotype.Service; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | // tag::code[] 27 | @Service // <1> 28 | class CartService { 29 | 30 | private final ItemRepository itemRepository; 31 | private final CartRepository cartRepository; 32 | 33 | CartService(ItemRepository itemRepository, // <2> 34 | CartRepository cartRepository) { 35 | this.itemRepository = itemRepository; 36 | this.cartRepository = cartRepository; 37 | } 38 | 39 | Mono addToCart(String cartId, String id) { // <3> 40 | return this.cartRepository.findById(cartId) // 41 | .defaultIfEmpty(new Cart(cartId)) // 42 | .flatMap(cart -> cart.getCartItems().stream() // 43 | .filter(cartItem -> cartItem.getItem().getId().equals(id)) // 44 | .findAny() // 45 | .map(cartItem -> { 46 | cartItem.increment(); 47 | return Mono.just(cart); 48 | }).orElseGet(() -> { 49 | return this.itemRepository.findById(id) // 50 | .map(CartItem::new) // <4> 51 | .doOnNext(cartItem -> cart.getCartItems().add(cartItem)) // 52 | .map(cartItem -> cart); 53 | })) 54 | .flatMap(this.cartRepository::save); // <5> 55 | } 56 | } 57 | // end::code[] 58 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.mongodb.repository.Query; 20 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 21 | import reactor.core.publisher.Flux; 22 | 23 | // tag::code[] 24 | public interface ItemRepository extends ReactiveCrudRepository { 25 | 26 | Flux findByNameContaining(String partialName); 27 | // end::code[] 28 | 29 | // tag::code-2[] 30 | @Query("{ 'name' : ?0, 'age' : }") 31 | Flux findItemsForCustomerMonthlyReport(); 32 | 33 | @Query(sort = "{ 'age' : -1", value = "{ 'name' : 'TV tray', 'age' : }") 34 | Flux findSortedStuffForWeeklyReport(); 35 | // end::code-2[] 36 | 37 | // tag::code-3[] 38 | // search by name 39 | Flux findByNameContainingIgnoreCase(String partialName); 40 | 41 | // search by description 42 | Flux findByDescriptionContainingIgnoreCase(String partialName); 43 | 44 | // search by name AND description 45 | Flux findByNameContainingAndDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 46 | 47 | // search by name OR description 48 | Flux findByNameContainingOrDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 49 | // end::code-3[] 50 | } 51 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /9-reactive-method-security/src/main/java/com/greglturnquist/hackingspringboot/reactive/CartItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.Objects; 19 | 20 | /** 21 | * @author Greg Turnquist 22 | */ 23 | // tag::code[] 24 | class CartItem { 25 | 26 | private Item item; 27 | private int quantity; 28 | 29 | private CartItem() {} 30 | 31 | CartItem(Item item) { 32 | this.item = item; 33 | this.quantity = 1; 34 | } 35 | 36 | // end::code[] 37 | 38 | public void increment() { 39 | this.quantity++; 40 | } 41 | 42 | public void decrement() { 43 | this.quantity--; 44 | } 45 | 46 | public Item getItem() { 47 | return item; 48 | } 49 | 50 | public void setItem(Item item) { 51 | this.item = item; 52 | } 53 | 54 | public int getQuantity() { 55 | return quantity; 56 | } 57 | 58 | public void setQuantity(int quantity) { 59 | this.quantity = quantity; 60 | } 61 | 62 | @Override 63 | public boolean equals(Object o) { 64 | if (this == o) 65 | return true; 66 | if (o == null || getClass() != o.getClass()) 67 | return false; 68 | CartItem cartItem = (CartItem) o; 69 | return quantity == cartItem.quantity && Objects.equals(item, cartItem.item); 70 | } 71 | 72 | @Override 73 | public int hashCode() { 74 | return Objects.hash(item, quantity); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "CartItem{" + "item=" + item + ", quantity=" + quantity + '}'; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /3-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/LoggingReactorFlows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import reactor.core.publisher.Mono; 22 | 23 | /** 24 | * @author Greg Turnquist 25 | */ 26 | class LoggingReactorFlows { 27 | 28 | private static final Logger log = LoggerFactory.getLogger(LoggingReactorFlows.class); 29 | 30 | private ItemRepository itemRepository; 31 | 32 | LoggingReactorFlows(ItemRepository itemRepository) { 33 | this.itemRepository = itemRepository; 34 | } 35 | 36 | Mono findPriceByMethodReference(String id) { 37 | // tag::method-handle[] 38 | return itemRepository.findById(id) 39 | .map(Item::getPrice); 40 | // end::method-handle[] 41 | } 42 | 43 | Mono findPriceWithLogging(String id) { 44 | // tag::injected-logger[] 45 | return itemRepository.findById(id) 46 | .map(item -> { 47 | log.debug("Found item"); 48 | return item.getPrice(); 49 | }); 50 | // end::injected-logger[] 51 | } 52 | 53 | Mono findPriceWithReactorLogging(String id) { 54 | // tag::reactor-logging[] 55 | return itemRepository.findById(id) 56 | .log("Found item") 57 | .map(Item::getPrice); 58 | // end::reactor-logging[] 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/ItemRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; 20 | import reactor.core.publisher.Flux; 21 | import org.springframework.data.mongodb.repository.Query; 22 | import org.springframework.data.repository.reactive.ReactiveCrudRepository; 23 | 24 | // tag::code[] 25 | public interface ItemRepository extends ReactiveCrudRepository, ReactiveQueryByExampleExecutor { 26 | 27 | Flux findByNameContaining(String partialName); 28 | // end::code[] 29 | 30 | // tag::code-2[] 31 | // @Query("{ 'name' : ?0, 'age' : ?1 }") 32 | // Flux findItemsForCustomerMonthlyReport(String name, int age); 33 | // 34 | // @Query(sort = "{ 'age' : -1 }") 35 | // Flux findSortedStuffForWeeklyReport(); 36 | // end::code-2[] 37 | 38 | // tag::code-3[] 39 | // search by name 40 | Flux findByNameContainingIgnoreCase(String partialName); 41 | 42 | // search by description 43 | Flux findByDescriptionContainingIgnoreCase(String partialName); 44 | 45 | // search by name AND description 46 | Flux findByNameContainingAndDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 47 | 48 | // search by name OR description 49 | Flux findByNameContainingOrDescriptionContainingAllIgnoreCase(String partialName, String partialDesc); 50 | // end::code-3[] 51 | } 52 | -------------------------------------------------------------------------------- /7-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/SpringAmqpItemService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import reactor.core.publisher.Mono; 22 | import org.springframework.amqp.rabbit.annotation.Exchange; 23 | import org.springframework.amqp.rabbit.annotation.Queue; 24 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 25 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 26 | import org.springframework.stereotype.Service; 27 | 28 | /** 29 | * @author Greg Turnquist 30 | */ 31 | // tag::code[] 32 | @Service // <1> 33 | public class SpringAmqpItemService { 34 | 35 | private static final Logger log = // 36 | LoggerFactory.getLogger(SpringAmqpItemService.class); 37 | 38 | private final ItemRepository repository; // <2> 39 | 40 | public SpringAmqpItemService(ItemRepository repository) { 41 | this.repository = repository; 42 | } 43 | // end::code[] 44 | 45 | // tag::listener[] 46 | @RabbitListener( // <1> 47 | ackMode = "MANUAL", // 48 | bindings = @QueueBinding( // <2> 49 | value = @Queue, // <3> 50 | exchange = @Exchange("hacking-spring-boot"), // <4> 51 | key = "new-items-spring-amqp")) // <5> 52 | public Mono processNewItemsViaSpringAmqp(Item item) { // <6> 53 | log.debug("Consuming => " + item); 54 | return this.repository.save(item).then(); // <7> 55 | } 56 | // end::listener[] 57 | } 58 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Item.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.Objects; 21 | 22 | // tag::code[] 23 | public class Item { 24 | 25 | private @Id String id; 26 | private String name; 27 | private double price; 28 | 29 | private Item() {} 30 | 31 | Item(String name, double price) { 32 | this.name = name; 33 | this.price = price; 34 | } 35 | // end::code[] 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public double getPrice() { 54 | return price; 55 | } 56 | 57 | public void setPrice(double price) { 58 | this.price = price; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Item item = (Item) o; 68 | return Double.compare(item.price, price) == 0 && Objects.equals(id, item.id) && Objects.equals(name, item.name); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, name, price); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Item{" + "id=" + id + ", name='" + name + '\'' + ", price=" + price + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /4-reactive/src/test/java/com/greglturnquist/hackingspringboot/reactive/LoadingWebSiteIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.greglturnquist.hackingspringboot.reactive; 18 | 19 | import org.junit.jupiter.api.Disabled; 20 | import org.junit.jupiter.api.Test; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; 23 | import org.springframework.boot.test.context.SpringBootTest; 24 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 25 | import org.springframework.http.MediaType; 26 | import org.springframework.test.web.reactive.server.WebTestClient; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | import static org.springframework.http.MediaType.*; 30 | 31 | /** 32 | * @author Greg Turnquist 33 | */ 34 | // tag::code[] 35 | @Disabled("pom.xml에서 blockhound-junit-platform 의존 관계를 제거한 후에 실행해야 성공한다.") 36 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) //<1> 37 | @AutoConfigureWebTestClient // <2> 38 | public class LoadingWebSiteIntegrationTest { 39 | 40 | @Autowired WebTestClient client; // <3> 41 | 42 | @Test // <4> 43 | void test() { 44 | client.get().uri("/").exchange() // 45 | .expectStatus().isOk() // 46 | .expectHeader().contentType(TEXT_HTML) // 47 | .expectBody(String.class) // 48 | .consumeWith(exchangeResult -> { 49 | assertThat(exchangeResult.getResponseBody()).contains(" 38 | return username -> repository.findByName(username) // <2> 39 | .map(user -> User.withDefaultPasswordEncoder() // <3> 40 | .username(user.getName()) // 41 | .password(user.getPassword()) // 42 | .authorities(user.getRoles().toArray(new String[0])) // 43 | .build()); // <4> 44 | } 45 | // end::reactive-user-details[] 46 | 47 | // tag::users[] 48 | @Bean 49 | CommandLineRunner userLoader(MongoOperations operations) { 50 | return args -> { 51 | operations.save(new com.greglturnquist.hackingspringboot.reactive.User( // 52 | "greg", "password", Arrays.asList("ROLE_USER"))); 53 | }; 54 | } 55 | // end::users[] 56 | } 57 | -------------------------------------------------------------------------------- /2-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /2b-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /3-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /4-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /5-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /6-reactive/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import org.springframework.data.annotation.Id; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /9-reactive-oauth/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import org.springframework.data.annotation.Id; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /9-reactive-quick/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import org.springframework.data.annotation.Id; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /9-reactive-repository/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import org.springframework.data.annotation.Id; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /9-reactive-custom-config/src/main/java/com/greglturnquist/hackingspringboot/reactive/Cart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.greglturnquist.hackingspringboot.reactive; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | import java.util.Objects; 21 | 22 | import org.springframework.data.annotation.Id; 23 | 24 | /** 25 | * @author Greg Turnquist 26 | */ 27 | // tag::code[] 28 | class Cart { 29 | 30 | private @Id String id; 31 | private List cartItems; 32 | 33 | private Cart() {} 34 | 35 | public Cart(String id) { 36 | this(id, new ArrayList<>()); 37 | } 38 | 39 | public Cart(String id, List cartItems) { 40 | this.id = id; 41 | this.cartItems = cartItems; 42 | } 43 | // end::code[] 44 | 45 | public String getId() { 46 | return id; 47 | } 48 | 49 | public void setId(String id) { 50 | this.id = id; 51 | } 52 | 53 | public List getCartItems() { 54 | return cartItems; 55 | } 56 | 57 | public void setCartItems(List cartItems) { 58 | this.cartItems = cartItems; 59 | } 60 | 61 | @Override 62 | public boolean equals(Object o) { 63 | if (this == o) 64 | return true; 65 | if (o == null || getClass() != o.getClass()) 66 | return false; 67 | Cart cart = (Cart) o; 68 | return Objects.equals(id, cart.id) && Objects.equals(cartItems, cart.cartItems); 69 | } 70 | 71 | @Override 72 | public int hashCode() { 73 | return Objects.hash(id, cartItems); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Cart{" + "id='" + id + '\'' + ", cartItems=" + cartItems + '}'; 79 | } 80 | } 81 | --------------------------------------------------------------------------------