├── .gitignore
├── LICENSE
├── README.md
├── preparing-for-the-cloud
├── README.md
└── section_1
│ └── section_1_1
│ ├── config-client
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── ConfigClientApplication.java
│ │ │ │ └── SimpleController.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── ConfigClientApplicationTests.java
│ ├── config-server
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ └── ConfigServerApplication.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── ConfigServerApplicationTests.java
│ ├── docker
│ └── docker-compose.yml
│ ├── pom.xml
│ └── properties
│ └── section_1_1
│ ├── default
│ └── application.properties
│ ├── development
│ └── application.properties
│ └── production
│ └── application.properties
└── spring-boot-fundamentals
├── section_1
├── section_1_1
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── Dockerfile
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── wkennedy
│ │ │ │ └── github
│ │ │ │ └── com
│ │ │ │ └── Section11Application.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── wkennedy
│ │ └── github
│ │ └── com
│ │ └── Section11ApplicationTests.java
├── section_1_2
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── groovy
│ │ │ └── RestApp.groovy
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ └── Section12Application.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── Section12ApplicationTests.java
└── section_1_3
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ └── Section13Application.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ └── Section13ApplicationTests.java
├── section_2
├── section_2_1
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section21Application.java
│ │ │ │ ├── SimpleConfig.java
│ │ │ │ ├── SimpleController.java
│ │ │ │ ├── SimpleInterceptor.java
│ │ │ │ └── SimpleProperties.java
│ │ └── resources
│ │ │ ├── application-development.yml
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── Section21ApplicationTests.java
├── section_2_2
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── Dockerfile
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ ├── src
│ │ ├── main
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── github
│ │ │ │ │ └── wkennedy
│ │ │ │ │ ├── Section22Application.java
│ │ │ │ │ ├── SimpleController.java
│ │ │ │ │ └── service
│ │ │ │ │ └── SimpleService.java
│ │ │ └── resources
│ │ │ │ ├── application.properties
│ │ │ │ └── templates
│ │ │ │ ├── index.html
│ │ │ │ └── other.html
│ │ └── test
│ │ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ └── Section21ApplicationTests.java
│ └── trigger
│ │ └── trigger.txt
├── section_2_3
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── Dockerfile
│ ├── docker
│ │ ├── configs
│ │ │ └── telegraf.conf
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section23Application.java
│ │ │ │ ├── SimpleConfig.java
│ │ │ │ ├── SimpleController.java
│ │ │ │ ├── SimpleEndpoint.java
│ │ │ │ └── service
│ │ │ │ └── SimpleService.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ ├── logback-spring.xml
│ │ │ └── templates
│ │ │ └── index.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── Section21ApplicationTests.java
└── section_2_4
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── Section24Application.java
│ │ │ ├── SimpleController.java
│ │ │ └── service
│ │ │ └── SimpleService.java
│ └── resources
│ │ ├── application.properties
│ │ ├── logback-spring.xml
│ │ └── templates
│ │ └── index.html
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ └── Section21ApplicationTests.java
├── section_3
├── section_3_1
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section31Application.java
│ │ │ │ ├── controllers
│ │ │ │ └── SimpleController.java
│ │ │ │ ├── dto
│ │ │ │ ├── Customer.java
│ │ │ │ └── Order.java
│ │ │ │ └── serializers
│ │ │ │ └── SimpleSerializers.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── html
│ │ │ ├── error
│ │ │ ├── 404.html
│ │ │ └── 500.html
│ │ │ └── index.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── Section31ApplicationTests.java
│ │ └── controllers
│ │ └── SimpleControllerTest.java
├── section_3_2
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── docs
│ │ ├── asciidoc
│ │ │ └── generated
│ │ │ │ ├── definitions.adoc
│ │ │ │ ├── overview.adoc
│ │ │ │ └── paths.adoc
│ │ └── markdown
│ │ │ └── generated
│ │ │ ├── definitions.md
│ │ │ ├── overview.md
│ │ │ └── paths.md
│ │ ├── main
│ │ ├── asciidoc
│ │ │ └── index.adoc
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section32Application.java
│ │ │ │ ├── SwaggerConfig.java
│ │ │ │ └── controllers
│ │ │ │ └── SimpleController.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── Section32ApplicationTests.java
│ │ ├── SpringRestDocumentation.java
│ │ └── SwaggerGenerationTest.java
├── section_3_3
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section33Application.java
│ │ │ │ ├── controllers
│ │ │ │ └── SimpleController.java
│ │ │ │ ├── dto
│ │ │ │ └── Person.java
│ │ │ │ └── services
│ │ │ │ └── PersonService.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── templates
│ │ │ ├── index.html
│ │ │ ├── layout.html
│ │ │ └── personList.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── Section33ApplicationTests.java
├── section_3_4
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section34Application.java
│ │ │ │ ├── ThymeleafConfig.java
│ │ │ │ ├── controllers
│ │ │ │ ├── SimpleReactiveController.java
│ │ │ │ └── ThymeleafReactiveController.java
│ │ │ │ ├── dto
│ │ │ │ └── Person.java
│ │ │ │ ├── handlers
│ │ │ │ └── PersonHandler.java
│ │ │ │ ├── routers
│ │ │ │ └── SimpleReactiveRouter.java
│ │ │ │ └── services
│ │ │ │ └── SimpleService.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── templates
│ │ │ └── thymeleaf
│ │ │ └── persons.html
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── Section34ApplicationTests.java
│ │ ├── controllers
│ │ └── SimpleReactiveControllerTest.java
│ │ └── routers
│ │ └── SimpleReactiveRouterTest.java
├── section_3_5
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── Dockerfile
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── nginx
│ │ ├── Dockerfile
│ │ └── nginx.conf
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section35Application.java
│ │ │ │ ├── SimpleConfig.java
│ │ │ │ ├── SimpleFilter.java
│ │ │ │ ├── SimpleServletContainerCustomizer.java
│ │ │ │ └── controllers
│ │ │ │ ├── RedirectController.java
│ │ │ │ └── SimpleController.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── Section35ApplicationTests.java
└── section_3_6
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── README.md
│ ├── docker
│ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── avro
│ │ └── person.avsc
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ ├── Section36Application.java
│ │ │ ├── avro
│ │ │ └── Person.java
│ │ │ ├── controller
│ │ │ ├── SimpleAvroController.java
│ │ │ └── SimpleProtoController.java
│ │ │ ├── proto
│ │ │ └── Person.java
│ │ │ └── service
│ │ │ └── PersonService.java
│ ├── proto
│ │ └── person.proto
│ ├── resources
│ │ └── application.properties
│ └── thrift
│ │ └── person.thrift
│ └── test
│ └── java
│ └── com
│ └── github
│ ├── Section36ApplicationTests.java
│ └── controller
│ ├── SimpleAvroControllerTest.java
│ └── SimpleProtoControllerTest.java
├── section_4
├── section_4_1
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── DataSourceConfig.java
│ │ │ │ ├── JooqConfig.java
│ │ │ │ ├── Section41Application.java
│ │ │ │ ├── entity
│ │ │ │ ├── AddressEntity.java
│ │ │ │ └── PersonEntity.java
│ │ │ │ └── repository
│ │ │ │ ├── AddressRepository.java
│ │ │ │ └── PersonRepository.java
│ │ └── resources
│ │ │ ├── application.properties
│ │ │ └── db
│ │ │ └── migration
│ │ │ ├── V1.1__person_add_address.sql
│ │ │ └── V1__initial_build.sql
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── JooqIT.java
│ │ │ ├── JpaIT.java
│ │ │ └── JpaTest.java
│ │ └── resources
│ │ └── application.properties
├── section_4_2
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── asciidoc
│ │ │ └── index.adoc
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section42Application.java
│ │ │ │ ├── entity
│ │ │ │ ├── AddressEntity.java
│ │ │ │ └── PersonEntity.java
│ │ │ │ └── repository
│ │ │ │ ├── AddressRepository.java
│ │ │ │ ├── InlineAddress.java
│ │ │ │ └── PersonRepository.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── ApiDocumentation.java
│ │ ├── JpaIT.java
│ │ └── Section42ApplicationTests.java
├── section_4_3
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── CassandraConfig.java
│ │ │ │ ├── Section43Application.java
│ │ │ │ ├── entities
│ │ │ │ └── Person.java
│ │ │ │ └── repositories
│ │ │ │ ├── PersonCassandraRepository.java
│ │ │ │ └── PersonMongoRepository.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ └── repositories
│ │ │ ├── PersonCassandraRepositoryIT.java
│ │ │ └── PersonMongoRepositoryIT.java
│ │ └── resources
│ │ └── init.cql
├── section_4_4
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── docker
│ │ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── Section44Application.java
│ │ │ │ ├── controllers
│ │ │ │ └── SimpleReactiveController.java
│ │ │ │ ├── entities
│ │ │ │ └── Person.java
│ │ │ │ └── repositories
│ │ │ │ ├── PersonReactiveCassandraRepository.java
│ │ │ │ └── PersonReactiveMongoRepository.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── controllers
│ │ └── SimpleReactiveControllerTest.java
│ │ └── repositories
│ │ ├── PersonReactiveCassandraRepositoryIT.java
│ │ └── PersonReactiveMongoRepositoryTest.java
└── section_4_5
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── docker
│ └── docker-compose.yml
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── CacheConfig.java
│ │ │ ├── Section45Application.java
│ │ │ ├── entities
│ │ │ └── Person.java
│ │ │ ├── repositories
│ │ │ └── PersonMongoRepository.java
│ │ │ └── service
│ │ │ └── SimpleService.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ ├── Section45ApplicationTests.java
│ ├── repositories
│ └── PersonMongoRepositoryTest.java
│ └── service
│ └── SimpleServiceTest.java
└── section_5
├── section_5_1
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── authorization_server
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── README.md
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── AuthorizationServerApplication.java
│ │ │ │ ├── AuthorizationServerOAuthConfig.java
│ │ │ │ └── SecurityConfiguration.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ └── AuthorizationServerApplicationTests.java
├── mvnw
├── mvnw.cmd
├── pom.xml
├── resource_server
│ ├── .gitignore
│ ├── .mvn
│ │ └── wrapper
│ │ │ ├── maven-wrapper.jar
│ │ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── github
│ │ │ │ └── wkennedy
│ │ │ │ ├── ResourceServerApplication.java
│ │ │ │ ├── ResourceServerConfig.java
│ │ │ │ ├── controllers
│ │ │ │ └── ResourceController.java
│ │ │ │ └── entities
│ │ │ │ └── Person.java
│ │ └── resources
│ │ │ └── application.properties
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── ResourceServerApplicationTests.java
│ │ └── controllers
│ │ └── ResourceControllerTest.java
└── simple_service
│ ├── .gitignore
│ ├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
│ ├── mvnw
│ ├── mvnw.cmd
│ ├── pom.xml
│ └── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── SecurityConfig.java
│ │ │ ├── SimpleServiceApplication.java
│ │ │ └── controllers
│ │ │ └── SimpleController.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ └── SimpleServiceApplicationTests.java
└── section_5_2
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── authorization_server
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── AuthorizationServerApplication.java
│ │ │ ├── AuthorizationServerOAuthConfig.java
│ │ │ └── SecurityConfig.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ └── AuthorizationServerApplicationTests.java
├── mvnw
├── mvnw.cmd
├── pom.xml
├── resource_server
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── ResourceServerApplication.java
│ │ │ ├── ResourceServerConfig.java
│ │ │ ├── controllers
│ │ │ └── ResourceController.java
│ │ │ └── entities
│ │ │ └── Person.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ ├── ResourceServerApplicationTests.java
│ └── controllers
│ └── ResourceControllerTest.java
├── resource_server_2
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── wkennedy
│ │ │ ├── ResourceServer2Application.java
│ │ │ ├── ResourceServerConfig.java
│ │ │ ├── controllers
│ │ │ └── ResourceController2.java
│ │ │ └── entities
│ │ │ └── Order.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── github
│ └── wkennedy
│ └── ResourceServer2ApplicationTests.java
└── simple_service
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── github
│ │ └── wkennedy
│ │ ├── SecurityConfig.java
│ │ ├── SimpleServiceApplication.java
│ │ └── controllers
│ │ └── SimpleController.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── github
└── wkennedy
└── SimpleServiceApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### JetBrains template
3 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5 |
6 | # User-specific stuff:
7 | .idea/**/workspace.xml
8 | .idea/**/tasks.xml
9 |
10 | # Sensitive or high-churn files:
11 | .idea/**/dataSources/
12 | .idea/**/dataSources.ids
13 | .idea/**/dataSources.xml
14 | .idea/**/dataSources.local.xml
15 | .idea/**/sqlDataSources.xml
16 | .idea/**/dynamic.xml
17 | .idea/**/uiDesigner.xml
18 |
19 | # Gradle:
20 | .idea/**/gradle.xml
21 | .idea/**/libraries
22 |
23 | # Mongo Explorer plugin:
24 | .idea/**/mongoSettings.xml
25 |
26 | ## File-based project format:
27 | *.iws
28 |
29 | ## Plugin-specific files:
30 |
31 | # IntelliJ
32 | /out/
33 |
34 | # mpeltonen/sbt-idea plugin
35 | .idea_modules/
36 |
37 | # JIRA plugin
38 | atlassian-ide-plugin.xml
39 |
40 | # Crashlytics plugin (for Android Studio and IntelliJ)
41 | com_crashlytics_export_strings.xml
42 | crashlytics.properties
43 | crashlytics-build.properties
44 | fabric.properties
45 | ### macOS template
46 | *.DS_Store
47 | .AppleDouble
48 | .LSOverride
49 |
50 | # Icon must end with two \r
51 | Icon
52 |
53 |
54 | # Thumbnails
55 | ._*
56 |
57 | # Files that might appear in the root of a volume
58 | .DocumentRevisions-V100
59 | .fseventsd
60 | .Spotlight-V100
61 | .TemporaryItems
62 | .Trashes
63 | .VolumeIcon.icns
64 | .com.apple.timemachine.donotpresent
65 |
66 | # Directories potentially created on remote AFP share
67 | .AppleDB
68 | .AppleDesktop
69 | Network Trash Folder
70 | Temporary Items
71 | .apdisk
72 | ### Windows template
73 | # Windows thumbnail cache files
74 | Thumbs.db
75 | ehthumbs.db
76 | ehthumbs_vista.db
77 |
78 | # Folder config file
79 | Desktop.ini
80 |
81 | # Recycle Bin used on file shares
82 | $RECYCLE.BIN/
83 |
84 | # Windows Installer files
85 | *.cab
86 | *.msi
87 | *.msm
88 | *.msp
89 |
90 | # Windows shortcuts
91 | *.lnk
92 |
93 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Will Kennedy
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # mastering-spring-5-development
--------------------------------------------------------------------------------
/preparing-for-the-cloud/README.md:
--------------------------------------------------------------------------------
1 | Volume 2: Preparing for the Cloud
2 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/preparing-for-the-cloud/section_1/section_1_1/config-client/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/src/main/java/com/github/wkennedy/ConfigClientApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ConfigClientApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ConfigClientApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/src/main/java/com/github/wkennedy/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.cloud.context.config.annotation.RefreshScope;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RefreshScope
7 | @RestController
8 | public class SimpleController {
9 | }
10 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=section_1_1
2 | #spring.cloud.config.uri=http://localhost:8888
3 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-client/src/test/java/com/github/wkennedy/ConfigClientApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ConfigClientApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/preparing-for-the-cloud/section_1/section_1_1/config-server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/src/main/java/com/github/wkennedy/ConfigServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.cloud.config.server.EnableConfigServer;
6 |
7 | @SpringBootApplication
8 | @EnableConfigServer
9 | public class ConfigServerApplication {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(ConfigServerApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.cloud.config.server.git.uri=https://github.com/wkennedy/mastering-spring-5-development/tree/develop/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/config-server/src/test/java/com/github/wkennedy/ConfigServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class ConfigServerApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/docker/docker-compose.yml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/preparing-for-the-cloud/section_1/section_1_1/docker/docker-compose.yml
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.wkennedy
8 | section_1_1
9 | 1.0-SNAPSHOT
10 | pom
11 |
12 |
13 | config-server
14 | config-client
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1/default/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8000
2 |
3 | simple.value=foo
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1/development/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1/development/application.properties
--------------------------------------------------------------------------------
/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1/production/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/preparing-for-the-cloud/section_1/section_1_1/properties/section_1_1/production/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM fabric8/java-alpine-openjdk8-jdk
2 | VOLUME /tmp
3 | ADD /target/section-1-1.jar /deployments/app.jar
4 | ENTRYPOINT ["/deployments/run-java.sh", "-Djava.security.egd=file:/dev/./urandom", "/app.jar"]
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | services:
3 | section-1-1-service:
4 | build: ../.
5 | ports:
6 | - 8080:8080
7 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/src/main/java/wkennedy/github/com/Section11Application.java:
--------------------------------------------------------------------------------
1 | package wkennedy.github.com;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section11Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section11Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_1/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_1/src/test/java/wkennedy/github/com/Section11ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package wkennedy.github.com;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section11ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.github.wkennedy
7 | section_1_2
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | section_1_2
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.0.BUILD-SNAPSHOT
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-maven-plugin
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/src/main/groovy/RestApp.groovy:
--------------------------------------------------------------------------------
1 | @RestController
2 | class RestApp {
3 | @RequestMapping("/")
4 | String index() {
5 | "Success!"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/src/main/java/com/github/wkennedy/Section12Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section12Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section12Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_2/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_2/src/test/java/com/github/wkennedy/Section12ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section12ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/src/main/java/com/github/wkennedy/Section13Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section13Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section13Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_1/section_1_3/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_1/section_1_3/src/test/java/com/github/wkennedy/Section13ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section13ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_2/section_2_1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/java/com/github/wkennedy/Section21Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.autoconfigure.reactor.core.ReactorCoreAutoConfiguration;
6 |
7 | @SpringBootApplication(exclude = {ReactorCoreAutoConfiguration.class})
8 | public class Section21Application {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(Section21Application.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/java/com/github/wkennedy/SimpleConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
10 |
11 | import javax.annotation.PostConstruct;
12 |
13 | @Configuration
14 | @EnableConfigurationProperties(SimpleProperties.class)
15 | @EnableWebMvc
16 | public class SimpleConfig extends WebMvcConfigurerAdapter {
17 |
18 | @Value("${my.property}")
19 | private String myProperty;
20 |
21 | private SimpleProperties simpleProperties;
22 |
23 | @Autowired
24 | public SimpleConfig(SimpleProperties simpleProperties) {
25 | this.simpleProperties = simpleProperties;
26 | }
27 |
28 | @PostConstruct
29 | private void postConstruct() {
30 | System.out.println(myProperty);
31 | System.out.println(simpleProperties.getName());
32 | System.out.println(simpleProperties.isEnabled());
33 | }
34 |
35 | @Override
36 | public void addInterceptors(InterceptorRegistry registry) {
37 | registry.addInterceptor(new SimpleInterceptor()).addPathPatterns("/**");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/java/com/github/wkennedy/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class SimpleController {
8 |
9 | @RequestMapping("/")
10 | public String index() {
11 | return "Hello!";
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/java/com/github/wkennedy/SimpleInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.web.servlet.HandlerInterceptor;
4 | import org.springframework.web.servlet.ModelAndView;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | public class SimpleInterceptor implements HandlerInterceptor {
10 |
11 | @Override
12 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
13 | System.out.println("In preHandle");
14 | return true;
15 | }
16 |
17 | @Override
18 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
19 | System.out.println("In postHandle");
20 | }
21 |
22 | @Override
23 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
24 | System.out.println("In afterCompletion");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/java/com/github/wkennedy/SimpleProperties.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.hibernate.validator.constraints.NotEmpty;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.validation.annotation.Validated;
6 |
7 | @ConfigurationProperties(prefix = "simple")
8 | @Validated
9 | public class SimpleProperties {
10 | @NotEmpty
11 | private String name;
12 | private String description;
13 | private boolean enabled;
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | public void setName(String name) {
20 | this.name = name;
21 | }
22 |
23 | public String getDescription() {
24 | return description;
25 | }
26 |
27 | public void setDescription(String description) {
28 | this.description = description;
29 | }
30 |
31 | public boolean isEnabled() {
32 | return enabled;
33 | }
34 |
35 | public void setEnabled(boolean enabled) {
36 | this.enabled = enabled;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/resources/application-development.yml:
--------------------------------------------------------------------------------
1 | my:
2 | property: Mastering Spring - Development
3 |
4 | simple:
5 | name: Simple Development Properties
6 | enabled: true
7 | description: ${simple.name} is a collection of properties.
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #Equivalent to --spring.profiles.active=development
2 | spring.profiles.active=development
3 |
4 | server.port=8000
5 | spring.mvc.favicon.enabled=false
6 |
7 | my.property=Mastering Spring
8 |
9 | simple.name=Simple Properties
10 | simple.enabled=true
11 | simple.description=${simple.name} is a collection of properties.
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_1/src/test/java/com/github/wkennedy/Section21ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section21ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_2/section_2_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8
2 | WORKDIR /deployments
3 | ADD /target/section_2_2.jar /deployments/app.jar
4 | CMD java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n -jar app.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | services:
3 | section-2-2-service:
4 | build: ../.
5 | ports:
6 | - 8080:8080
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/java/com/github/wkennedy/Section22Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section22Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section22Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/java/com/github/wkennedy/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.service.SimpleService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestParam;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @Controller
11 | public class SimpleController {
12 |
13 | @Autowired
14 | private SimpleService simpleService;
15 |
16 | @RequestMapping("/")
17 | public String index() {
18 | return "index";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/java/com/github/wkennedy/service/SimpleService.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class SimpleService {
7 |
8 | public String getName() {
9 | return "SimpleService";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=section-2-2-service
2 | spring.mvc.favicon.enabled=false
3 | security.basic.enabled=false
4 |
5 | spring.devtools.restart.exclude=com/github/wkennedy/service/**
6 |
7 | spring.devtools.restart.additional-paths=trigger
8 | #spring.devtools.restart.trigger-file=trigger.txt
9 | #spring.devtools.restart.enabled=false
10 |
11 | spring.devtools.remote.secret=secret
12 |
13 | spring.thymeleaf.cache=false
14 |
15 | spring.output.ansi.enabled=ALWAYS
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mastering Spring Development
5 |
6 |
7 |
8 | Goodbye!
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/main/resources/templates/other.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mastering Spring Development
5 |
6 |
7 |
8 | Other page.
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/src/test/java/com/github/wkennedy/Section21ApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class Section21ApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_2/trigger/trigger.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_2/section_2_2/trigger/trigger.txt
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_2/section_2_3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8
2 | WORKDIR /deployments
3 | ADD /target/section_2_3.jar /deployments/app.jar
4 | CMD java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n -jar app.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/docker/configs/telegraf.conf:
--------------------------------------------------------------------------------
1 | [tags]
2 | dc = "local-1"
3 |
4 | [agent]
5 | interval = "5s"
6 |
7 | [[inputs.jolokia]]
8 | context = "/jolokia"
9 |
10 | [[inputs.jolokia.servers]]
11 | name = "jolokia-server"
12 | host = "section-2-3-service"
13 | port = "8080"
14 |
15 | [[inputs.jolokia.metrics]]
16 | name = "metrics"
17 | mbean = "org.springframework.boot:name=metricsEndpoint,type=Endpoint"
18 | attribute = "Data"
19 |
20 | [outputs]
21 | [outputs.influxdb]
22 | url = "http://influxdb:8086"
23 | database = "metrics"
24 | precision = "s"
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '2'
2 | services:
3 |
4 | section-2-3-service:
5 | build: ../.
6 | ports:
7 | - 8080:8080
8 |
9 | redis:
10 | image: redis
11 | ports:
12 | - "6379:6379"
13 |
14 | influxdb:
15 | container_name: influxdb
16 | image: influxdb:latest
17 | ports:
18 | - "8086:8086"
19 | - "8083:8083"
20 | - "8090:8090"
21 | - "8099:8099"
22 | environment:
23 | INFLUXDB_DATA_ENGINE: tsm1
24 |
25 | telegraf:
26 | container_name: telegraf
27 | image: telegraf:latest
28 | volumes:
29 | - ./configs/telegraf.conf:/etc/telegraf/telegraf.conf:ro
30 | ports:
31 | - "8125:8125"
32 | depends_on:
33 | - influxdb
34 | - grafana
35 | links:
36 | - influxdb
37 |
38 | grafana:
39 | container_name: grafana
40 | image: grafana/grafana
41 | volumes:
42 | - ./configs/:/etc/grafana/scripts
43 | ports:
44 | - "3000:3000"
45 | depends_on:
46 | - influxdb
47 | links:
48 | - influxdb
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/java/com/github/wkennedy/Section23Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section23Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section23Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/java/com/github/wkennedy/SimpleConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | public class SimpleConfig {
8 |
9 | @Bean
10 | public SimpleEndpoint simpleEndpoint() {
11 | return new SimpleEndpoint("simple", false);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/java/com/github/wkennedy/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.service.SimpleService;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Controller;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @RestController
13 | public class SimpleController {
14 |
15 | private static final Logger log = LoggerFactory.getLogger(SimpleController.class);
16 |
17 | @Autowired
18 | private SimpleService simpleService;
19 |
20 | @RequestMapping("/")
21 | public String index() {
22 | log.debug("In index method in SimpleController");
23 | return simpleService.getName();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/java/com/github/wkennedy/SimpleEndpoint.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
4 |
5 | public class SimpleEndpoint extends AbstractEndpoint {
6 |
7 | public SimpleEndpoint(String id) {
8 | super(id);
9 | }
10 |
11 | public SimpleEndpoint(String id, boolean sensitive) {
12 | super(id, sensitive);
13 | }
14 |
15 | public SimpleEndpoint(String id, boolean sensitive, boolean enabled) {
16 | super(id, sensitive, enabled);
17 | }
18 |
19 | @Override
20 | public String invoke() {
21 | return "SimpleEndpoint invoked";
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/java/com/github/wkennedy/service/SimpleService.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.service;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class SimpleService {
9 |
10 | private static final Logger log = LoggerFactory.getLogger(SimpleService.class);
11 |
12 | public String getName() {
13 | log.trace("Returning name of SimpleService");
14 | return "SimpleService";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=section-2-4-service
2 | spring.mvc.favicon.enabled=false
3 | security.basic.enabled=false
4 |
5 | #spring.devtools.restart.exclude=com/github/wkennedy/service/**
6 |
7 | #spring.devtools.restart.additional-paths=trigger
8 | #spring.devtools.restart.trigger-file=trigger.txt
9 | #spring.devtools.restart.enabled=false
10 |
11 | spring.devtools.remote.secret=secret
12 |
13 | #spring.thymeleaf.cache=false
14 |
15 | spring.output.ansi.enabled=ALWAYS
16 |
17 | #logging.file=my-log.log
18 | #logging.path=
19 |
20 | logging.level.root=info
21 | logging.level.com.github.wkennedy=debug
22 |
23 | endpoints.docs.enabled=false
24 | endpoints.health.sensitive=false
25 | endpoints.info.enabled=true
26 | endpoints.sensitive=false
27 |
28 | management.security.enabled=false
29 |
30 | #management.context-path=/actuator
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | >
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mastering Spring Development
5 |
6 |
7 |
8 | Hello!
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_3/src/test/java/com/github/wkennedy/Section21ApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class Section21ApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_2/section_2_4/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/java/com/github/wkennedy/Section24Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section24Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section24Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/java/com/github/wkennedy/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.service.SimpleService;
4 | import org.slf4j.Logger;
5 | import org.slf4j.LoggerFactory;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.stereotype.Controller;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.springframework.web.bind.annotation.RequestParam;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | @RestController
13 | public class SimpleController {
14 |
15 | private static final Logger log = LoggerFactory.getLogger(SimpleController.class);
16 |
17 | @Autowired
18 | private SimpleService simpleService;
19 |
20 | @RequestMapping("/")
21 | public String index() {
22 | log.trace("In index method in SimpleController");
23 | return simpleService.getName();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/java/com/github/wkennedy/service/SimpleService.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.service;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class SimpleService {
9 |
10 | private static final Logger log = LoggerFactory.getLogger(SimpleService.class);
11 |
12 | public String getName() {
13 | log.trace("Returning name of SimpleService");
14 | return "SimpleService";
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=section-2-4-service
2 | spring.mvc.favicon.enabled=false
3 | security.basic.enabled=false
4 |
5 | spring.profiles.active=development
6 |
7 | spring.devtools.remote.secret=secret
8 |
9 | #spring.thymeleaf.cache=false
10 |
11 | spring.output.ansi.enabled=ALWAYS
12 |
13 | debug=false
14 |
15 | logging.file=my-log.log
16 | #logging.path=
17 |
18 | logging.level.root=info
19 | logging.level.com.github.wkennedy=trace
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/resources/logback-spring.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mastering Spring Development
5 |
6 |
7 |
8 | Hello!
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_2/section_2_4/src/test/java/com/github/wkennedy/Section21ApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class Section21ApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/java/com/github/wkennedy/Section31Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section31Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section31Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.dto.Customer;
4 | import com.github.wkennedy.dto.Order;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.Date;
9 |
10 | @RestController
11 | public class SimpleController {
12 |
13 | // @RequestMapping("/")
14 | // public String index() {
15 | // return "index";
16 | // }
17 |
18 | @RequestMapping("/myError")
19 | public void getError() throws Exception {
20 | throw new Exception("Error handling example");
21 | }
22 |
23 | @RequestMapping("/orders")
24 | public Order getOrders() {
25 | return getOrder();
26 | }
27 |
28 | private Order getOrder() {
29 | Customer customer = new Customer();
30 | customer.setFirstName("John");
31 | customer.setLastName("Doe");
32 | customer.setId(3);
33 |
34 | Order order = new Order();
35 | order.setId(1);
36 | order.setCustomer(customer);
37 | order.setOrderDate(new Date());
38 | order.setProductName("Acme Portal");
39 | order.setQuantity(1);
40 |
41 | return order;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/java/com/github/wkennedy/dto/Customer.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.dto;
2 |
3 | public class Customer {
4 | private Integer id;
5 | private String firstName;
6 | private String lastName;
7 |
8 | public Integer getId() {
9 | return id;
10 | }
11 |
12 | public void setId(Integer id) {
13 | this.id = id;
14 | }
15 |
16 | public String getFirstName() {
17 | return firstName;
18 | }
19 |
20 | public void setFirstName(String firstName) {
21 | this.firstName = firstName;
22 | }
23 |
24 | public String getLastName() {
25 | return lastName;
26 | }
27 |
28 | public void setLastName(String lastName) {
29 | this.lastName = lastName;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/java/com/github/wkennedy/dto/Order.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.dto;
2 |
3 | import java.util.Date;
4 |
5 | public class Order {
6 | private Integer id;
7 | private Date orderDate;
8 | private Integer quantity;
9 | private Customer customer;
10 | private String productName;
11 |
12 | public Integer getId() {
13 | return id;
14 | }
15 |
16 | public void setId(Integer id) {
17 | this.id = id;
18 | }
19 |
20 | public Date getOrderDate() {
21 | return orderDate;
22 | }
23 |
24 | public void setOrderDate(Date orderDate) {
25 | this.orderDate = orderDate;
26 | }
27 |
28 | public Integer getQuantity() {
29 | return quantity;
30 | }
31 |
32 | public void setQuantity(Integer quantity) {
33 | this.quantity = quantity;
34 | }
35 |
36 | public Customer getCustomer() {
37 | return customer;
38 | }
39 |
40 | public void setCustomer(Customer customer) {
41 | this.customer = customer;
42 | }
43 |
44 | public String getProductName() {
45 | return productName;
46 | }
47 |
48 | public void setProductName(String productName) {
49 | this.productName = productName;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/java/com/github/wkennedy/serializers/SimpleSerializers.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.serializers;
2 |
3 | import com.fasterxml.jackson.core.JsonGenerator;
4 | import com.fasterxml.jackson.databind.SerializerProvider;
5 | import com.github.wkennedy.dto.Order;
6 | import org.springframework.boot.jackson.JsonComponent;
7 | import org.springframework.boot.jackson.JsonObjectSerializer;
8 |
9 | import java.io.IOException;
10 |
11 | @JsonComponent //automatically registers with Jackson in the ApplicationContext
12 | public class SimpleSerializers {
13 |
14 | public static class OrderSerializer extends JsonObjectSerializer {
15 |
16 | @Override
17 | protected void serializeObject(Order value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
18 | jgen.writeStringField("LastName", value.getCustomer().getLastName());
19 | jgen.writeStringField("FirstName", value.getCustomer().getFirstName());
20 | jgen.writeNumberField("amount", value.getQuantity());
21 | jgen.writeStringField("Product", value.getProductName());
22 | }
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.resources.static-locations=classpath:/html/,classpath:/static/,classpath:/resources/,classpath:/META-INF/resources,classpath:/public/
2 |
3 | spring.resources.cache-period=0
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/resources/html/error/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 404 - Not Found
6 |
7 |
8 | We're sorry, we aren't able to find anything there.
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/resources/html/error/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 500 Error
6 |
7 |
8 | We're sorry, an error occurred.
9 |
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/main/resources/html/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Mastering Spring Development
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
Mastering Spring!
13 |
This is the index page.
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/test/java/com/github/wkennedy/Section31ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section31ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_1/src/test/java/com/github/wkennedy/controllers/SimpleControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.gargoylesoftware.htmlunit.WebClient;
4 | import com.gargoylesoftware.htmlunit.html.HtmlPage;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 | import org.springframework.test.web.servlet.MockMvc;
12 |
13 | import static org.assertj.core.api.Assertions.assertThat;
14 | import static org.hamcrest.core.Is.is;
15 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
17 |
18 | @RunWith(SpringRunner.class)
19 | @WebMvcTest(SimpleController.class)
20 | public class SimpleControllerTest {
21 |
22 | @Autowired
23 | private MockMvc mvc;
24 |
25 | @Autowired
26 | private WebClient webClient;
27 |
28 | @Test
29 | public void getOrder() throws Exception {
30 | this.mvc.perform(get("/orders").accept(MediaType.APPLICATION_JSON_UTF8_VALUE))
31 | .andExpect(status().isOk())
32 | .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
33 | .andExpect(jsonPath("$.LastName", is("Doe")))
34 | .andExpect(jsonPath("$.FirstName", is("John")));
35 | }
36 |
37 | @Test
38 | public void testIndex() throws Exception {
39 | HtmlPage page = this.webClient.getPage("/index.html");
40 | assertThat(page.getBody().getTextContent()).isEqualTo("\n" +
41 | "\n" +
42 | " Mastering Spring!\n" +
43 | " This is the index page.\n" +
44 | "\n" +
45 | "\n" +
46 | "");
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/asciidoc/generated/definitions.adoc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_2/src/docs/asciidoc/generated/definitions.adoc
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/asciidoc/generated/overview.adoc:
--------------------------------------------------------------------------------
1 | = Api Documentation
2 |
3 | == Overview
4 | Api Documentation
5 |
6 | === Version information
7 | Version: 1.0
8 |
9 | === Contact information
10 |
11 | === License information
12 | License: Apache 2.0
13 | License URL: http://www.apache.org/licenses/LICENSE-2.0
14 |
15 | Terms of service: urn:tos
16 |
17 | === URI scheme
18 | Host: localhost
19 | BasePath: /
20 |
21 | === Tags
22 |
23 | * Simple Service: A basic API example
24 | * simple-controller: Simple Controller
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/asciidoc/generated/paths.adoc:
--------------------------------------------------------------------------------
1 | == Paths
2 | === welcome
3 | ----
4 | GET /simple/welcome
5 | ----
6 |
7 | ==== Responses
8 | [options="header"]
9 | |===
10 | |HTTP Code|Description|Schema
11 | |200|OK|string
12 | |500|500 message|<>
13 | |===
14 |
15 | ==== Consumes
16 |
17 | * application/json
18 |
19 | ==== Produces
20 |
21 | * */*
22 |
23 | ==== Tags
24 |
25 | * simple-controller
26 |
27 | === postSimpleValue
28 | ----
29 | POST /simple/{param}
30 | ----
31 |
32 | ==== Parameters
33 | [options="header"]
34 | |===
35 | |Type|Name|Description|Required|Schema|Default
36 | |PathParameter|param|param|true|string|
37 | |===
38 |
39 | ==== Responses
40 | [options="header"]
41 | |===
42 | |HTTP Code|Description|Schema
43 | |200|OK|string
44 | |===
45 |
46 | ==== Consumes
47 |
48 | * text/plain
49 |
50 | ==== Produces
51 |
52 | * */*
53 |
54 | ==== Tags
55 |
56 | * simple-controller
57 |
58 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/markdown/generated/definitions.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_2/src/docs/markdown/generated/definitions.md
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/markdown/generated/overview.md:
--------------------------------------------------------------------------------
1 | # Api Documentation
2 |
3 | ## Overview
4 | Api Documentation
5 |
6 | ### Version information
7 | Version: 1.0
8 |
9 | ### Contact information
10 |
11 | ### License information
12 | License: Apache 2.0
13 | License URL: http://www.apache.org/licenses/LICENSE-2.0
14 |
15 | Terms of service: urn:tos
16 |
17 | ### URI scheme
18 | Host: localhost
19 | BasePath: /
20 |
21 | ### Tags
22 |
23 | * Simple Service: A basic API example
24 | * simple-controller: Simple Controller
25 |
26 |
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/docs/markdown/generated/paths.md:
--------------------------------------------------------------------------------
1 | ## Paths
2 | ### welcome
3 | ```
4 | GET /simple/welcome
5 | ```
6 |
7 | #### Responses
8 | |HTTP Code|Description|Schema|
9 | |----|----|----|
10 | |200|OK|string|
11 | |500|500 message|Error|
12 |
13 |
14 | #### Consumes
15 |
16 | * application/json
17 |
18 | #### Produces
19 |
20 | * */*
21 |
22 | #### Tags
23 |
24 | * simple-controller
25 |
26 | ### postSimpleValue
27 | ```
28 | POST /simple/{param}
29 | ```
30 |
31 | #### Parameters
32 | |Type|Name|Description|Required|Schema|Default|
33 | |----|----|----|----|----|----|
34 | |PathParameter|param|param|true|string||
35 |
36 |
37 | #### Responses
38 | |HTTP Code|Description|Schema|
39 | |----|----|----|
40 | |200|OK|string|
41 |
42 |
43 | #### Consumes
44 |
45 | * text/plain
46 |
47 | #### Produces
48 |
49 | * */*
50 |
51 | #### Tags
52 |
53 | * simple-controller
54 |
55 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/main/asciidoc/index.adoc:
--------------------------------------------------------------------------------
1 | = Simple Service REST Doc
2 | Will Kennedy;
3 | :doctype: book
4 | :icons: font
5 | :source-highlighter: highlightjs
6 | :toc: left
7 | :toclevels: 2
8 | :sectlinks:
9 |
10 | == Simple Service
11 |
12 | This is a simple example of using Spring REST Docs to generate your API guide.
13 |
14 | === Getting the welcome message
15 |
16 | ==== Request structure
17 | include::{snippets}/simple-welcome/http-request.adoc[]
18 |
19 | ==== Response structure
20 | include::{snippets}/simple-welcome/http-response.adoc[]
21 |
22 | ==== Response body
23 | include::{snippets}/simple-welcome/response-body.adoc[]
24 |
25 | ==== Example cURL request
26 | include::{snippets}/simple-welcome/curl-request.adoc[]
27 |
28 | === Posting a simple message
29 |
30 | ==== Request structure
31 | include::{snippets}/simple-post/http-request.adoc[]
32 |
33 | ==== Response structure
34 | include::{snippets}/simple-post/http-response.adoc[]
35 |
36 | ==== Path variable
37 | include::{snippets}/simple-post/path-parameters.adoc[]
38 |
39 | ==== Response body
40 | include::{snippets}/simple-post/response-body.adoc[]
41 |
42 | ==== Example cURL request
43 | include::{snippets}/simple-post/curl-request.adoc[]
44 |
45 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/main/java/com/github/wkennedy/Section32Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section32Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section32Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import org.springframework.web.bind.annotation.PathVariable;
4 | import org.springframework.web.bind.annotation.RequestMapping;
5 | import org.springframework.web.bind.annotation.RequestMethod;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @RestController
9 | @RequestMapping("/simple")
10 | public class SimpleController {
11 |
12 | @RequestMapping(value = "/welcome", method = RequestMethod.GET)
13 | public String welcome() {
14 | return "Hello!";
15 | }
16 |
17 | @RequestMapping(path = "/{param}", method = RequestMethod.POST, consumes = "text/plain")
18 | public String postSimpleValue(@PathVariable(value = "param") String param) {
19 | return "You successfully posted: " + param;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_2/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/test/java/com/github/wkennedy/Section32ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section32ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_2/src/test/java/com/github/wkennedy/SwaggerGenerationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import io.github.robwin.markup.builder.MarkupLanguage;
4 | import org.junit.Test;
5 | import org.junit.runner.RunWith;
6 | import org.springframework.beans.factory.annotation.Autowired;
7 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
8 | import org.springframework.boot.test.context.SpringBootTest;
9 | import org.springframework.http.MediaType;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 | import org.springframework.test.web.servlet.MockMvc;
12 | import springfox.documentation.staticdocs.Swagger2MarkupResultHandler;
13 |
14 | import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16 |
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | @AutoConfigureMockMvc
21 | public class SwaggerGenerationTest {
22 |
23 | @Autowired
24 | private MockMvc mockMvc;
25 |
26 | @Test
27 | public void swaggerToAsciiDoc() throws Exception {
28 | this.mockMvc.perform(get("/v2/api-docs")
29 | .accept(MediaType.APPLICATION_JSON))
30 | .andDo(Swagger2MarkupResultHandler.outputDirectory("src/docs/asciidoc/generated").build())
31 | .andExpect(status().isOk());
32 | }
33 |
34 | @Test
35 | public void swaggerToMarkdown() throws Exception {
36 | this.mockMvc.perform(get("/v2/api-docs")
37 | .accept(MediaType.APPLICATION_JSON))
38 | .andDo(Swagger2MarkupResultHandler.outputDirectory("src/docs/markdown/generated")
39 | .withMarkupLanguage(MarkupLanguage.MARKDOWN).build())
40 | .andExpect(status().isOk());
41 | }
42 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/java/com/github/wkennedy/Section33Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section33Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section33Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.dto.Person;
4 | import com.github.wkennedy.services.PersonService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Controller;
7 | import org.springframework.web.bind.annotation.ModelAttribute;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 |
10 | import java.time.LocalDate;
11 | import java.util.List;
12 |
13 | @Controller
14 | public class SimpleController {
15 |
16 | private final PersonService personService;
17 |
18 | @Autowired
19 | public SimpleController(PersonService personService) {
20 | this.personService = personService;
21 | }
22 |
23 | @RequestMapping("/")
24 | public String index() {
25 | return "index";
26 | }
27 |
28 | @RequestMapping("/personList")
29 | public String content1() {
30 | return "personList";
31 | }
32 |
33 | @ModelAttribute("allPersons")
34 | public List populatePersons() {
35 | return personService.getPersons();
36 | }
37 |
38 | @ModelAttribute("simpleValue")
39 | public String populateSimpleValue() {
40 | return "Hello!";
41 | }
42 |
43 | @ModelAttribute("today")
44 | public LocalDate localDate() {
45 | return LocalDate.now();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/java/com/github/wkennedy/dto/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.dto;
2 |
3 | public class Person {
4 |
5 | private String firstName;
6 | private String lastName;
7 |
8 | public String getFirstName() {
9 | return firstName;
10 | }
11 |
12 | public void setFirstName(String firstName) {
13 | this.firstName = firstName;
14 | }
15 |
16 | public String getLastName() {
17 | return lastName;
18 | }
19 |
20 | public void setLastName(String lastName) {
21 | this.lastName = lastName;
22 | }
23 |
24 | @Override
25 | public String toString() {
26 | return "Person{" +
27 | "firstName='" + firstName + '\'' +
28 | ", lastName='" + lastName + '\'' +
29 | '}';
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/java/com/github/wkennedy/services/PersonService.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.services;
2 |
3 | import com.github.wkennedy.dto.Person;
4 | import org.springframework.stereotype.Service;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | @Service
10 | public class PersonService {
11 |
12 | public List getPersons() {
13 | List personList = new ArrayList<>();
14 |
15 | Person person = new Person();
16 | person.setFirstName("John");
17 | person.setLastName("Doe");
18 |
19 | Person person2 = new Person();
20 | person2.setFirstName("Jane");
21 | person2.setLastName("Doe");
22 |
23 | personList.add(person);
24 | personList.add(person2);
25 |
26 | return personList;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #spring.thymeleaf.cache=true # Enable template caching.
2 | #spring.thymeleaf.check-template=true # Check that the template exists before rendering it.
3 | #spring.thymeleaf.check-template-location=true # Check that the templates location exists.
4 | #spring.thymeleaf.content-type=text/html # Content-Type value.
5 | #spring.thymeleaf.enabled=true # Enable MVC Thymeleaf view resolution.
6 | #spring.thymeleaf.encoding=UTF-8 # Template encoding.
7 | #spring.thymeleaf.excluded-view-names= # Comma-separated list of view names that should be excluded from resolution.
8 | #spring.thymeleaf.mode=HTML5 # Template mode to be applied to templates. See also StandardTemplateModeHandlers.
9 | #spring.thymeleaf.prefix=classpath:/templates/ # Prefix that gets prepended to view names when building a URL.
10 | #spring.thymeleaf.suffix=.html # Suffix that gets appended to view names when building a URL.
11 | #spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain.
12 | #spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Title
6 |
7 |
8 |
9 |
All People as of [[${#temporals.format(today, 'dd/MMM/yyyy', locale)}]]
10 |
11 |
12 |
13 |
14 | First Name |
15 | Last Name |
16 |
17 |
18 |
19 |
20 | |
21 | |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/resources/templates/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Layout page
5 |
6 |
7 |
8 |
9 | Section 3.3 - Thymeleaf
10 |
11 |
12 | Reserved for page content
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/main/resources/templates/personList.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | Section 3.3 - Person List
7 |
8 |
9 |
10 |
11 |
12 |
All People
13 |
14 |
15 |
16 |
17 | First Name |
18 | Last Name |
19 |
20 |
21 |
22 |
23 | |
24 | |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
35 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_3/src/test/java/com/github/wkennedy/Section33ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section33ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_4/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/Section34Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.scheduling.annotation.EnableAsync;
6 | import org.springframework.web.reactive.config.EnableWebFlux;
7 |
8 | @SpringBootApplication
9 | //@EnableWebFlux
10 | public class Section34Application {
11 |
12 | public static void main(String[] args) {
13 | SpringApplication.run(Section34Application.class, args);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/controllers/SimpleReactiveController.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy.controllers;
2 | //
3 | //import com.github.wkennedy.dto.Person;
4 | //import com.github.wkennedy.services.SimpleService;
5 | //import org.springframework.beans.factory.annotation.Autowired;
6 | //import org.springframework.web.bind.annotation.GetMapping;
7 | //import org.springframework.web.bind.annotation.PathVariable;
8 | //import org.springframework.web.bind.annotation.RequestMapping;
9 | //import org.springframework.web.bind.annotation.RestController;
10 | //import reactor.core.publisher.Flux;
11 | //import reactor.core.publisher.Mono;
12 | //
13 | //import java.time.Duration;
14 | //
15 | //@RestController
16 | //@RequestMapping("/react")
17 | //public class SimpleReactiveController {
18 | //
19 | // private final SimpleService simpleService;
20 | //
21 | // @Autowired
22 | // public SimpleReactiveController(SimpleService simpleService) {
23 | // this.simpleService = simpleService;
24 | // }
25 | //
26 | // @GetMapping("/persons")
27 | // public Flux getPersons() {
28 | // return simpleService.getPersons().log();
29 | // }
30 | //
31 | // @GetMapping("/persons/delay/{delay}")
32 | // public Flux getPersons(@PathVariable Long delay) {
33 | // return simpleService.getPersons().delayElements(Duration.ofMillis(delay));
34 | // }
35 | //
36 | // @GetMapping("/person")
37 | // public Mono getPerson() {
38 | // return simpleService.getPerson();
39 | // }
40 | //}
41 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/controllers/ThymeleafReactiveController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.dto.Person;
4 | import com.github.wkennedy.services.SimpleService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Controller;
7 | import org.springframework.ui.Model;
8 | import org.springframework.web.bind.annotation.RequestMapping;
9 | import org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable;
10 | import reactor.core.publisher.Flux;
11 |
12 | import java.util.List;
13 |
14 | @Controller
15 | public class ThymeleafReactiveController {
16 |
17 | private final SimpleService simpleService;
18 |
19 | @Autowired
20 | public ThymeleafReactiveController(SimpleService simpleService) {
21 | this.simpleService = simpleService;
22 | }
23 |
24 | @RequestMapping("/personsTemplate")
25 | public String getPersons(final Model model) {
26 | final Flux personFlux = simpleService.getPersonsWithDelay(200L);
27 | model.addAttribute("dataSource", new ReactiveDataDriverContextVariable(personFlux, 1));
28 |
29 | return "thymeleaf/persons";
30 | }
31 |
32 | @RequestMapping("/personsChunkedTemplate")
33 | public String getPersonsChunked(final Model model) {
34 | final Flux playlistStream = simpleService.getPersons();
35 | final List playlistEntries = playlistStream.collectList().block();
36 |
37 | model.addAttribute("dataSource", playlistEntries);
38 |
39 | return "thymeleaf/persons";
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/dto/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.dto;
2 |
3 | public class Person {
4 |
5 | private String firstName;
6 | private String lastName;
7 |
8 | public Person() {
9 | }
10 |
11 | public Person(String firstName, String lastName) {
12 | this.firstName = firstName;
13 | this.lastName = lastName;
14 | }
15 |
16 | public String getFirstName() {
17 | return firstName;
18 | }
19 |
20 | public void setFirstName(String firstName) {
21 | this.firstName = firstName;
22 | }
23 |
24 | public String getLastName() {
25 | return lastName;
26 | }
27 |
28 | public void setLastName(String lastName) {
29 | this.lastName = lastName;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "Person{" +
35 | "firstName='" + firstName + '\'' +
36 | ", lastName='" + lastName + '\'' +
37 | '}';
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/handlers/PersonHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.handlers;
2 |
3 | import com.github.wkennedy.dto.Person;
4 | import com.github.wkennedy.services.SimpleService;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Component;
7 | import org.springframework.web.reactive.function.server.ServerRequest;
8 | import org.springframework.web.reactive.function.server.ServerResponse;
9 | import reactor.core.publisher.Flux;
10 | import reactor.core.publisher.Mono;
11 |
12 | @Component
13 | public class PersonHandler {
14 |
15 | private final SimpleService simpleService;
16 |
17 | @Autowired
18 | public PersonHandler(SimpleService simpleService) {
19 | this.simpleService = simpleService;
20 | }
21 |
22 | public Mono getPerson(ServerRequest request) {
23 | Mono persons = simpleService.getPerson();
24 | return ServerResponse.ok().body(persons, Person.class);
25 | }
26 |
27 | public Mono getPersons(ServerRequest request) {
28 | Flux persons = simpleService.getPersons().log();;
29 | return ServerResponse.ok().body(persons, Person.class);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/java/com/github/wkennedy/routers/SimpleReactiveRouter.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.routers;
2 |
3 |
4 | import com.github.wkennedy.handlers.PersonHandler;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.stereotype.Component;
7 | import org.springframework.web.reactive.function.server.RouterFunction;
8 |
9 | import static org.springframework.http.MediaType.APPLICATION_JSON;
10 | import static org.springframework.web.reactive.function.server.RequestPredicates.*;
11 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
12 | import static org.springframework.web.reactive.function.server.RouterFunctions.route;
13 |
14 | @Component
15 | public class SimpleReactiveRouter {
16 |
17 | private final PersonHandler personHandler;
18 |
19 | @Autowired
20 | public SimpleReactiveRouter(PersonHandler personHandler) {
21 | this.personHandler = personHandler;
22 | }
23 |
24 | public RouterFunction> routerFunction() {
25 |
26 | return nest(path("/react/functional/"),
27 | nest(accept(APPLICATION_JSON),
28 | route(GET("/persons"), personHandler::getPersons)
29 | ).andRoute(GET("/person"), personHandler::getPerson));
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.thymeleaf.mode=HTML
2 | spring.thymeleaf.check-template=false
3 | spring.thymeleaf.check-template-location=true
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/main/resources/templates/thymeleaf/persons.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | People Streaming
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | First Name |
16 | Last Name |
17 |
18 |
19 |
20 |
21 | ... |
22 | ... |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/test/java/com/github/wkennedy/Section34ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section34ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_4/src/test/java/com/github/wkennedy/routers/SimpleReactiveRouterTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.routers;
2 |
3 | import com.github.wkennedy.dto.Person;
4 | import org.junit.Before;
5 | import org.junit.Ignore;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.http.MediaType;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 | import org.springframework.test.web.reactive.server.WebTestClient;
14 | import reactor.core.publisher.Flux;
15 |
16 | import java.time.Duration;
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
20 | @AutoConfigureWebTestClient
21 | public class SimpleReactiveRouterTest {
22 |
23 | private WebTestClient webTestClient;
24 |
25 | @Autowired
26 | private SimpleReactiveRouter simpleReactiveRouter;
27 |
28 | @Before
29 | public void before() {
30 | this.webTestClient = WebTestClient.bindToRouterFunction(simpleReactiveRouter.routerFunction()).build();
31 | }
32 |
33 | @Test
34 | public void routerFunction() throws Exception {
35 | Flux personFlux = webTestClient.get().uri("/react/functional/persons").accept(MediaType.APPLICATION_JSON)
36 | .exchange().expectStatus().is2xxSuccessful()
37 | .returnResult(Person.class).getResponseBody();
38 |
39 | personFlux.delaySubscription(Duration.ofSeconds(0))
40 | .toStream()
41 | .forEach(s -> System.out.println(1 + ": " + s));
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_5/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8
2 | WORKDIR /deployments
3 | ADD /target/section_3_5.jar /deployments/app.jar
4 | CMD java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,suspend=n -jar app.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 |
4 | section-3-5-service:
5 | build: ../.
6 | ports:
7 | - 8080
8 | hostname: app
9 | healthcheck:
10 | test: ["CMD", "curl", "-f", "http://app:8080/hello"]
11 | interval: 10m
12 | timeout: 10s
13 | retries: 5
14 |
15 | nginx:
16 | build: ../nginx
17 | restart: always
18 | ports:
19 | - 80:80
20 | hostname: proxy
21 | depends_on:
22 | - section-3-5-service
23 | links:
24 | - section-3-5-service:app
25 | entrypoint: dockerize -wait http://app:8080/hello nginx -g 'daemon off;'
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/nginx/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM nginx:alpine
2 |
3 | RUN rm /etc/nginx/conf.d/default.conf
4 |
5 | ADD nginx.conf /etc/nginx/conf.d/
6 |
7 | RUN apk add --no-cache openssl
8 |
9 | ENV DOCKERIZE_VERSION v0.4.0
10 | RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
11 | && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
12 | && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/nginx/nginx.conf:
--------------------------------------------------------------------------------
1 | # Configuration for the server
2 | upstream backend {
3 | server app:8080 fail_timeout=0;
4 | }
5 |
6 | server {
7 | charset utf-8;
8 | listen 80;
9 | location / {
10 | proxy_pass http://app:8080;
11 | proxy_redirect off;
12 | #proxy_set_header Host $host;
13 | proxy_set_header X-Real-IP $remote_addr;
14 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15 | #proxy_set_header X-Forwarded-Host $server_name;
16 | proxy_set_header X-Forwarded-Host 127.0.0.1;
17 | proxy_set_header X-Forwarded-Port 80;
18 | proxy_set_header X-Forwarded-Proto $scheme;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/Section35Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section35Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section35Application.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/SimpleConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Value;
6 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
7 | import org.springframework.boot.web.servlet.ServletComponentScan;
8 | import org.springframework.boot.web.servlet.ServletContextInitializer;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 |
12 | import javax.servlet.ServletContext;
13 | import javax.servlet.ServletException;
14 |
15 | @Configuration
16 | @ServletComponentScan //needed for @WebFilter
17 | public class SimpleConfig {
18 |
19 | private static Logger log = LoggerFactory.getLogger(SimpleConfig.class);
20 |
21 | @Value("${simpleFilter.enabled}")
22 | public boolean simpleFilterEnabled;
23 |
24 | @Bean
25 | public ServletContextInitializer getInitializer() {
26 | return new Initializer();
27 | }
28 |
29 | public class Initializer implements ServletContextInitializer {
30 |
31 | @Override
32 | public void onStartup(ServletContext servletContext) throws ServletException {
33 | log.info("Server Info: " + servletContext.getServerInfo());
34 | }
35 | }
36 |
37 | //This is an alternative to the ServletComponentScan
38 | // @Bean
39 | // public SimpleFilter getSimpleFilter() {
40 | // return new SimpleFilter();
41 | // }
42 |
43 | // @Bean
44 | // public FilterRegistrationBean registerSimpleFilter() {
45 | // FilterRegistrationBean registration = new FilterRegistrationBean<>(new SimpleFilter());
46 | // registration.setEnabled(simpleFilterEnabled);
47 | // return registration;
48 | // }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/SimpleFilter.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import javax.servlet.*;
7 | import javax.servlet.annotation.WebFilter;
8 | import java.io.IOException;
9 |
10 | @WebFilter("/*")
11 | public class SimpleFilter implements Filter {
12 |
13 | private static Logger log = LoggerFactory.getLogger(SimpleFilter.class);
14 |
15 | private FilterConfig filterConfig = null;
16 |
17 | @Override
18 | public void init(FilterConfig filterConfig) throws ServletException {
19 | this.filterConfig = filterConfig;
20 | }
21 |
22 | @Override
23 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
24 | log.info("In SimpleFilter with server name - " + request.getServerName() + " : server info - " + request.getServletContext().getServerInfo());
25 | chain.doFilter(request, response);
26 | }
27 |
28 | @Override
29 | public void destroy() {
30 | this.filterConfig = null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/SimpleServletContainerCustomizer.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.web.server.WebServerFactoryCustomizer;
4 | import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
5 | import org.springframework.core.Ordered;
6 | import org.springframework.stereotype.Component;
7 |
8 | @Component
9 | public class SimpleServletContainerCustomizer implements WebServerFactoryCustomizer, Ordered {
10 |
11 | @Override
12 | public void customize(ConfigurableServletWebServerFactory configurableServletWebServerFactory) {
13 | configurableServletWebServerFactory.setDisplayName("Simple Service");
14 | configurableServletWebServerFactory.setPort(8080);
15 | }
16 |
17 | @Override
18 | public int getOrder() {
19 | return 0;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/controllers/RedirectController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.RequestMapping;
8 | import org.springframework.web.bind.annotation.ResponseBody;
9 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
10 |
11 | import javax.servlet.http.HttpServletRequest;
12 | import java.util.Enumeration;
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | @Controller
17 | public class RedirectController {
18 |
19 | private static final Logger log = LoggerFactory.getLogger(RedirectController.class);
20 |
21 | @RequestMapping("/redirect")
22 | public String redirect(HttpServletRequest httpServletRequest) {
23 | printHeadersInfo(httpServletRequest);
24 | return "redirect:/hello";
25 | }
26 |
27 | @GetMapping("/redirectURL")
28 | @ResponseBody
29 | public String getRedirectURL(HttpServletRequest httpRequest) {
30 | printHeadersInfo(httpRequest);
31 | return ServletUriComponentsBuilder.fromRequest(httpRequest).path("/hello").build().toUriString();
32 | }
33 |
34 | private void printHeadersInfo(HttpServletRequest request) {
35 | Map headerMap = new HashMap<>();
36 |
37 | Enumeration headerNames = request.getHeaderNames();
38 | while (headerNames.hasMoreElements()) {
39 | String key = (String) headerNames.nextElement();
40 | String value = request.getHeader(key);
41 | headerMap.put(key, value);
42 | }
43 |
44 | headerMap.forEach((key, value) -> log.info(key + " : " + value));
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @RestController
9 | public class SimpleController {
10 | private static final Logger log = LoggerFactory.getLogger(SimpleController.class);
11 |
12 | @RequestMapping("/hello")
13 | public String hello() {
14 | log.info("Successful call to /hello");
15 | return "Hello!\n";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | #Set to -1 to turn off HTTP, 0 for a random port (based on scan)
2 | #server.port=0
3 |
4 | spring.application.name=app
5 | server.use-forward-headers=true
6 |
7 | simpleFilter.enabled=false
8 |
9 | debug=false
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_5/src/test/java/com/github/wkennedy/Section35ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.boot.web.server.LocalServerPort;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 | import static org.junit.Assert.assertNotNull;
12 |
13 | @RunWith(SpringRunner.class)
14 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
15 | public class Section35ApplicationTests {
16 |
17 | private static final Logger log = LoggerFactory.getLogger(Section35ApplicationTests.class);
18 |
19 | @LocalServerPort
20 | private int port;
21 |
22 | @Test
23 | public void contextLoads() {
24 | log.info("Unit test random port: " + port);
25 | assertNotNull(port);
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_6/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/README.md:
--------------------------------------------------------------------------------
1 | First run:
2 |
3 | docker-compose up
4 |
5 | in the docker directory. This will spin up an image that has thrift installed that will generate classes
6 | from the thrift file in src/main/thrift. You can then do a Maven build.
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 | services:
3 |
4 | thrift:
5 | image: thrift:latest
6 | volumes:
7 | - ../src/main/thrift/:/data
8 | - ../src/main/java/:/output
9 | entrypoint: thrift -v -out /output --gen java /data/person.thrift
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/avro/person.avsc:
--------------------------------------------------------------------------------
1 | {"namespace": "com.github.avro",
2 | "type": "record",
3 | "name": "Person",
4 | "fields": [
5 | {"name": "id", "type": ["int", "null"]},
6 | {"name": "firstName", "type": "string"},
7 | {"name": "lastName", "type": "string"}
8 | ]
9 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/java/com/github/Section36Application.java:
--------------------------------------------------------------------------------
1 | package com.github;
2 |
3 | import com.github.thrift.PersonService;
4 | import org.apache.thrift.protocol.TBinaryProtocol;
5 | import org.apache.thrift.protocol.TProtocolFactory;
6 | import org.apache.thrift.server.TServlet;
7 | import org.springframework.boot.SpringApplication;
8 | import org.springframework.boot.autoconfigure.SpringBootApplication;
9 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
10 | import org.springframework.context.annotation.Bean;
11 |
12 | @SpringBootApplication
13 | public class Section36Application {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(Section36Application.class, args);
17 | }
18 |
19 | @Bean
20 | public TProtocolFactory tProtocolFactory() {
21 | return new TBinaryProtocol.Factory();
22 | }
23 |
24 | @Bean
25 | public ServletRegistrationBean servletRegistrationBean(com.github.service.PersonService personService, TProtocolFactory protocolFactory){
26 | TServlet tServlet = new TServlet(new PersonService.Processor<>(personService), protocolFactory);
27 | return new ServletRegistrationBean<>(tServlet,"/thrift/*");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/java/com/github/controller/SimpleAvroController.java:
--------------------------------------------------------------------------------
1 | package com.github.controller;
2 |
3 | import com.github.avro.Person;
4 | import org.apache.avro.io.DatumWriter;
5 | import org.apache.avro.io.Encoder;
6 | import org.apache.avro.io.EncoderFactory;
7 | import org.apache.avro.specific.SpecificDatumWriter;
8 | import org.springframework.web.bind.annotation.GetMapping;
9 | import org.springframework.web.bind.annotation.RestController;
10 |
11 | import java.io.ByteArrayOutputStream;
12 | import java.io.IOException;
13 |
14 | @RestController
15 | public class SimpleAvroController {
16 |
17 | @GetMapping("/avro/person")
18 | public byte[] getPerson() throws IOException {
19 | Person person = new Person();
20 | person.setId(323984);
21 | person.setFirstName("Ted");
22 | person.setLastName("Hardy");
23 |
24 | DatumWriter userDatumWriter = new SpecificDatumWriter<>(Person.class);
25 |
26 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
27 | Encoder encoder = EncoderFactory.get().binaryEncoder(outputStream, null);
28 | userDatumWriter.write(person, encoder);
29 | encoder.flush();
30 | return outputStream.toByteArray();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/java/com/github/controller/SimpleProtoController.java:
--------------------------------------------------------------------------------
1 | package com.github.controller;
2 |
3 | import com.github.proto.Person;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | @RestController
8 | public class SimpleProtoController {
9 |
10 | @GetMapping("/proto/person")
11 | public byte[] getPerson() {
12 | Person.PersonProto person = Person.PersonProto
13 | .newBuilder()
14 | .setFirstName("Ted")
15 | .setLastName("Hardy")
16 | .setId(23284)
17 | .build();
18 |
19 | return person.toByteArray();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/java/com/github/service/PersonService.java:
--------------------------------------------------------------------------------
1 | package com.github.service;
2 |
3 | import com.github.thrift.Person;
4 | import org.apache.thrift.TException;
5 | import org.springframework.stereotype.Service;
6 |
7 | @Service
8 | public class PersonService implements com.github.thrift.PersonService.Iface {
9 |
10 | @Override
11 | public Person getPerson() throws TException {
12 | Person person = new Person();
13 | person.setId(3252);
14 | person.setFirstName("John");
15 | person.setLastName("Doh");
16 |
17 | return person;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/proto/person.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package proto;
4 |
5 | option java_package = "com.github.proto";
6 |
7 | message PersonProto {
8 | int32 id = 1;
9 | string firstName = 2;
10 | string lastName = 3;
11 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_3/section_3_6/src/main/resources/application.properties
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/main/thrift/person.thrift:
--------------------------------------------------------------------------------
1 | namespace java com.github.thrift
2 |
3 | struct Person {
4 | 1: string firstName;
5 | 2: string lastName;
6 | 3: i32 id;
7 | }
8 |
9 | service PersonService {
10 | Person getPerson();
11 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/test/java/com/github/Section36ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github;
2 |
3 | import com.github.thrift.Person;
4 | import com.github.thrift.PersonService;
5 | import org.apache.thrift.TException;
6 | import org.apache.thrift.protocol.TProtocol;
7 | import org.apache.thrift.protocol.TProtocolFactory;
8 | import org.apache.thrift.transport.THttpClient;
9 | import org.apache.thrift.transport.TTransport;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.boot.web.server.LocalServerPort;
16 | import org.springframework.test.context.junit4.SpringRunner;
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
20 | public class Section36ApplicationTests {
21 |
22 | @Autowired
23 | private TProtocolFactory protocolFactory;
24 |
25 | @LocalServerPort
26 | private int port;
27 |
28 | private PersonService.Client personClient;
29 |
30 | @Before
31 | public void setUp() throws Exception {
32 | TTransport transport = new THttpClient("http://localhost:" + port + "/thrift");
33 | TProtocol protocol = protocolFactory.getProtocol(transport);
34 | personClient = new PersonService.Client(protocol);
35 | }
36 |
37 | @Test
38 | public void contextLoads() {
39 | }
40 |
41 | @Test
42 | public void getPerson() throws TException {
43 | Person person = personClient.getPerson();
44 | System.out.println(person.getId());
45 | System.out.println(person.getFirstName());
46 | System.out.println(person.getLastName());
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/test/java/com/github/controller/SimpleAvroControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.github.controller;
2 |
3 | import com.github.avro.Person;
4 | import com.github.service.PersonService;
5 | import org.apache.avro.io.Decoder;
6 | import org.apache.avro.io.DecoderFactory;
7 | import org.apache.avro.specific.SpecificDatumReader;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
12 | import org.springframework.boot.test.mock.mockito.MockBean;
13 | import org.springframework.http.MediaType;
14 | import org.springframework.test.context.junit4.SpringRunner;
15 | import org.springframework.test.web.servlet.MockMvc;
16 |
17 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
19 |
20 | @RunWith(SpringRunner.class)
21 | @WebMvcTest(SimpleAvroController.class)
22 | public class SimpleAvroControllerTest {
23 |
24 | @MockBean
25 | PersonService personService;
26 |
27 | @Autowired
28 | private MockMvc mvc;
29 |
30 | @Test
31 | public void getPerson() throws Exception {
32 | byte[] result = this.mvc.perform(get("/avro/person").accept(MediaType.APPLICATION_OCTET_STREAM))
33 | .andExpect(status().isOk()).andReturn().getResponse().getContentAsByteArray();
34 |
35 | SpecificDatumReader reader = new SpecificDatumReader<>(Person.getClassSchema());
36 | Decoder decoder = DecoderFactory.get().binaryDecoder(result, null);
37 | Person person = reader.read(null, decoder);
38 | System.out.println(person.getSchema().toString(true));
39 | System.out.println(person.getId());
40 | System.out.println(person.getFirstName());
41 | System.out.println(person.getLastName());
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_3/section_3_6/src/test/java/com/github/controller/SimpleProtoControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.github.controller;
2 |
3 | import com.github.proto.Person;
4 | import com.github.service.PersonService;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
9 | import org.springframework.boot.test.mock.mockito.MockBean;
10 | import org.springframework.http.MediaType;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import org.springframework.test.web.servlet.MockMvc;
13 |
14 | import static org.junit.Assert.*;
15 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
16 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
17 |
18 | @RunWith(SpringRunner.class)
19 | @WebMvcTest(SimpleProtoController.class)
20 | public class SimpleProtoControllerTest {
21 |
22 | @MockBean
23 | PersonService personService;
24 |
25 | @Autowired
26 | private MockMvc mvc;
27 |
28 | @Test
29 | public void getPerson() throws Exception {
30 | byte[] result = this.mvc.perform(get("/proto/person").accept(MediaType.APPLICATION_OCTET_STREAM))
31 | .andExpect(status().isOk()).andReturn().getResponse().getContentAsByteArray();
32 |
33 | Person.PersonProto person = Person.PersonProto.parseFrom(result);
34 | System.out.println("Serialized size: " + person.getSerializedSize());
35 | System.out.println(person.getId());
36 | System.out.println(person.getFirstName());
37 | System.out.println(person.getLastName());
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | db:
6 | image: mysql:5.7
7 | ports:
8 | - 3306:3306
9 | restart: always
10 | environment:
11 | MYSQL_ROOT_PASSWORD: spring
12 | MYSQL_DATABASE: section4
13 | MYSQL_USER: user
14 | MYSQL_PASSWORD: pass
15 |
16 | db2:
17 | image: mysql:5.7
18 | ports:
19 | - 3307:3306
20 | restart: always
21 | environment:
22 | MYSQL_ROOT_PASSWORD: spring
23 | MYSQL_DATABASE: section4_2
24 | MYSQL_USER: user
25 | MYSQL_PASSWORD: pass
26 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/java/com/github/wkennedy/DataSourceConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.zaxxer.hikari.HikariDataSource;
4 | import org.springframework.boot.autoconfigure.flyway.FlywayDataSource;
5 | import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
6 | import org.springframework.boot.context.properties.ConfigurationProperties;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 | import org.springframework.context.annotation.Primary;
10 |
11 | import javax.sql.DataSource;
12 |
13 | @Configuration
14 | public class DataSourceConfig {
15 |
16 | @Bean
17 | @Primary
18 | @ConfigurationProperties(prefix="section4.datasource")
19 | public DataSource dataSource() {
20 | return DataSourceBuilder.create().build();
21 | }
22 |
23 | @Bean("dataSource2")
24 | @ConfigurationProperties("section4.datasource2")
25 | @FlywayDataSource
26 | public HikariDataSource dataSource2() {
27 | return (HikariDataSource) DataSourceBuilder.create().type(HikariDataSource.class).build();
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/java/com/github/wkennedy/JooqConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.jooq.SQLDialect;
4 | import org.jooq.impl.DataSourceConnectionProvider;
5 | import org.jooq.impl.DefaultConfiguration;
6 | import org.jooq.impl.DefaultDSLContext;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Qualifier;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
12 |
13 | import javax.sql.DataSource;
14 |
15 | @Configuration
16 | public class JooqConfig {
17 |
18 | private final DataSource dataSource2;
19 |
20 | @Autowired
21 | public JooqConfig(@Qualifier("dataSource2") DataSource dataSource2) {
22 | this.dataSource2 = dataSource2;
23 | }
24 |
25 | @Bean
26 | public DataSourceConnectionProvider connectionProvider() {
27 | return new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource2));
28 | }
29 |
30 | @Bean
31 | public DefaultDSLContext dslContext() {
32 | DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
33 | jooqConfiguration.set(connectionProvider());
34 | jooqConfiguration.setSQLDialect(SQLDialect.MYSQL);
35 |
36 | return new DefaultDSLContext(jooqConfiguration);
37 | }
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/java/com/github/wkennedy/Section41Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section41Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section41Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/java/com/github/wkennedy/repository/AddressRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repository;
2 |
3 | import com.github.wkennedy.entity.AddressEntity;
4 | import org.springframework.data.repository.CrudRepository;
5 |
6 | public interface AddressRepository extends CrudRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/java/com/github/wkennedy/repository/PersonRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repository;
2 |
3 | import com.github.wkennedy.entity.PersonEntity;
4 | import org.springframework.data.repository.CrudRepository;
5 |
6 | public interface PersonRepository extends CrudRepository {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/section4?useSSL=false
2 | spring.datasource.username=user
3 | spring.datasource.password=pass
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5 |
6 | section4.datasource.jdbc-url=jdbc:mysql://localhost:3306/section4?useSSL=false
7 | section4.datasource.username=user
8 | section4.datasource.password=pass
9 | section4.datasource.driver-class-name=com.mysql.jdbc.Driver
10 |
11 | section4.datasource2.jdbc-url=jdbc:mysql://localhost:3307/section4_2?useSSL=false
12 | section4.datasource2.username=root
13 | section4.datasource2.password=spring
14 | section4.datasource2.driver-class-name=com.mysql.jdbc.Driver
15 |
16 | spring.jpa.hibernate.ddl-auto=create
17 |
18 | flyway.enabled=true
19 | #flyway.baseline-version=1
20 | #flyway.baseline-on-migrate=true
21 |
22 | #spring.jooq.sql-dialect=mysql
23 |
24 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/resources/db/migration/V1.1__person_add_address.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE section4_2.address
2 | (
3 | id INT PRIMARY KEY AUTO_INCREMENT,
4 | address1 VARCHAR(36) NOT NULL,
5 | address2 VARCHAR(36),
6 | city VARCHAR(36) NOT NULL,
7 | state VARCHAR(36),
8 | zip INT
9 | );
10 |
11 | ALTER TABLE section4_2.person ADD address INT NULL;
12 | ALTER TABLE section4_2.person
13 | ADD CONSTRAINT person_address_id_fk
14 | FOREIGN KEY (address) REFERENCES address (id);
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/main/resources/db/migration/V1__initial_build.sql:
--------------------------------------------------------------------------------
1 | CREATE TABLE section4_2.person
2 | (
3 | id INT PRIMARY KEY AUTO_INCREMENT,
4 | last_name VARCHAR(36) NOT NULL,
5 | first_name VARCHAR(36) NOT NULL
6 | );
7 | CREATE INDEX person_last_name_index ON section4_2.person (last_name);
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/test/java/com/github/wkennedy/JooqIT.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.jooq.DSLContext;
4 | import org.jooq.Result;
5 | import org.jooq.util.maven.example.tables.records.PersonRecord;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.beans.factory.annotation.Qualifier;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 | import org.springframework.transaction.annotation.Transactional;
14 |
15 | import static org.jooq.util.maven.example.tables.Person.PERSON;
16 |
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest
19 | @Transactional("transactionManager")
20 | public class JooqIT {
21 |
22 | @Autowired
23 | @Qualifier("dslContext")
24 | private DSLContext dslContext;
25 |
26 | @Before
27 | public void setup() {
28 | dslContext.deleteFrom(PERSON).where(PERSON.ID.equal(3235)).execute();
29 | }
30 |
31 | @Test
32 | public void testJooq() {
33 | dslContext.insertInto(PERSON).set(PERSON.ID, 3235).set(PERSON.FIRST_NAME, "John").set(PERSON.LAST_NAME, "Doe").execute();
34 | Result persons = dslContext.selectFrom(PERSON).where(PERSON.FIRST_NAME.equal("John")).fetch();
35 |
36 | System.out.println(persons.get(0).toString());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/test/java/com/github/wkennedy/JpaIT.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.entity.PersonEntity;
4 | import com.github.wkennedy.repository.PersonRepository;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.slf4j.Logger;
9 | import org.slf4j.LoggerFactory;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.boot.test.context.SpringBootTest;
12 | import org.springframework.test.context.junit4.SpringRunner;
13 |
14 | import java.util.Optional;
15 |
16 | import static org.junit.Assert.assertTrue;
17 |
18 | @RunWith(SpringRunner.class)
19 | @SpringBootTest
20 | public class JpaIT {
21 |
22 | private static final Logger log = LoggerFactory.getLogger(JpaIT.class);
23 |
24 | @Autowired
25 | private PersonRepository personRepository;
26 |
27 | @Before
28 | public void setup() {
29 | personRepository.deleteAll();
30 | }
31 |
32 | @Test
33 | public void testPerson() {
34 | PersonEntity person = new PersonEntity();
35 | person.setFirstName("John");
36 | person.setLastName("Doh");
37 | person = personRepository.save(person);
38 |
39 | Optional personFromRepo = personRepository.findById(person.getId());
40 | assertTrue(personFromRepo.isPresent());
41 | log.info(personFromRepo.get().toString());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/test/java/com/github/wkennedy/JpaTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.entity.PersonEntity;
4 | import com.github.wkennedy.repository.PersonRepository;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 | import org.springframework.transaction.annotation.Propagation;
12 | import org.springframework.transaction.annotation.Transactional;
13 |
14 | import java.util.Optional;
15 |
16 | import static org.junit.Assert.assertTrue;
17 |
18 | @RunWith(SpringRunner.class)
19 | @DataJpaTest
20 | @Transactional(propagation = Propagation.NOT_SUPPORTED)
21 | public class JpaTest {
22 |
23 | @Autowired
24 | private PersonRepository personRepository;
25 |
26 | @Before
27 | public void setup () {
28 | personRepository.deleteAll();
29 | }
30 |
31 | @Test
32 | public void testPerson() {
33 | PersonEntity person = generatePerson();
34 | person = personRepository.save(person);
35 | Optional personFromRepo = personRepository.findById(person.getId());
36 | assertTrue(personFromRepo.isPresent());
37 | System.out.println(personFromRepo.get().toString());
38 | }
39 |
40 | private PersonEntity generatePerson() {
41 | PersonEntity person = new PersonEntity();
42 | person.setFirstName("John");
43 | person.setLastName("Doh");
44 | return person;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_1/src/test/resources/application.properties:
--------------------------------------------------------------------------------
1 | flyway.enabled=false
2 |
3 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | db:
6 | image: mysql:5.7
7 | ports:
8 | - 3306:3306
9 | restart: always
10 | environment:
11 | MYSQL_ROOT_PASSWORD: spring
12 | MYSQL_DATABASE: section4
13 | MYSQL_USER: user
14 | MYSQL_PASSWORD: pass
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/asciidoc/index.adoc:
--------------------------------------------------------------------------------
1 | = Spring Data REST Doc
2 | Will Kennedy;
3 | :doctype: book
4 | :icons: font
5 | :source-highlighter: highlightjs
6 | :toc: left
7 | :toclevels: 2
8 | :sectlinks:
9 |
10 | == Spring Data Rest Docs
11 |
12 | This is a simple example of using Spring REST Docs to generate your Spring Data Rest API guide.
13 |
14 | === Index Example
15 |
16 | ==== Request structure
17 | include::{snippets}/index-example/http-request.adoc[]
18 |
19 | ==== Response structure
20 | include::{snippets}/index-example/http-response.adoc[]
21 |
22 | ==== Response body
23 | include::{snippets}/index-example/response-body.adoc[]
24 |
25 | ==== Example cURL request
26 | include::{snippets}/index-example/curl-request.adoc[]
27 |
28 | ==== Links
29 | include::{snippets}/index-example/links.adoc[]
30 |
31 | === Person Example
32 |
33 | ==== Request structure
34 | include::{snippets}/person-list-example/http-request.adoc[]
35 |
36 | ==== Response structure
37 | include::{snippets}/person-list-example/http-response.adoc[]
38 |
39 | ==== Response body
40 | include::{snippets}/person-list-example/response-body.adoc[]
41 |
42 | ==== Example cURL request
43 | include::{snippets}/person-list-example/curl-request.adoc[]
44 |
45 | ==== Links
46 | include::{snippets}/person-list-example/links.adoc[]
47 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/java/com/github/wkennedy/Section42Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.Import;
6 |
7 | @SpringBootApplication
8 | public class Section42Application {
9 |
10 | public static void main(String[] args) {
11 | SpringApplication.run(Section42Application.class, args);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/java/com/github/wkennedy/repository/AddressRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repository;
2 |
3 | import com.github.wkennedy.entity.AddressEntity;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6 |
7 | @RepositoryRestResource(collectionResourceRel = "address", path = "address")
8 | public interface AddressRepository extends CrudRepository {
9 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/java/com/github/wkennedy/repository/InlineAddress.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repository;
2 |
3 | import com.github.wkennedy.entity.AddressEntity;
4 | import com.github.wkennedy.entity.PersonEntity;
5 | import org.springframework.data.rest.core.config.Projection;
6 |
7 | @Projection(name = "inlineAddress", types = { PersonEntity.class })
8 | interface InlineAddress {
9 |
10 | String getFirstName();
11 |
12 | String getLastName();
13 |
14 | AddressEntity getAddress();
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/java/com/github/wkennedy/repository/PersonRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repository;
2 |
3 | import com.github.wkennedy.entity.PersonEntity;
4 | import org.springframework.data.repository.CrudRepository;
5 | import org.springframework.data.rest.core.annotation.RepositoryRestResource;
6 |
7 | @RepositoryRestResource(collectionResourceRel = "person", path = "person")
8 | public interface PersonRepository extends CrudRepository {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/section4?useSSL=false
2 | spring.datasource.username=user
3 | spring.datasource.password=pass
4 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver
5 |
6 | spring.jpa.hibernate.ddl-auto=create-drop
7 |
8 | endpoints.hypermedia.enabled=true
9 | management.security.enabled=false
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/test/java/com/github/wkennedy/JpaIT.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import com.github.wkennedy.entity.PersonEntity;
4 | import com.github.wkennedy.repository.PersonRepository;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | import java.util.Optional;
14 |
15 | import static org.junit.Assert.assertTrue;
16 |
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest
19 | public class JpaIT {
20 |
21 | private static final Logger log = LoggerFactory.getLogger(JpaIT.class);
22 |
23 | @Autowired
24 | private PersonRepository personRepository;
25 |
26 | @Test
27 | public void testPerson() {
28 | PersonEntity person = new PersonEntity();
29 | person.setFirstName("John");
30 | person.setLastName("Doh");
31 | person = personRepository.save(person);
32 |
33 | Optional personFromRepo = personRepository.findById(person.getId());
34 | assertTrue(personFromRepo.isPresent());
35 | log.info(personFromRepo.get().toString());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_2/src/test/java/com/github/wkennedy/Section42ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section42ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_3/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | cassandra0:
6 | image: cassandra:3.2
7 | ports:
8 | - 7000:7000
9 | - 9042:9042
10 | - 9160:9160
11 |
12 | cassandra1:
13 | image: cassandra:3.2
14 | links:
15 | - cassandra0:seed
16 | environment:
17 | - CASSANDRA_SEEDS=seed
18 |
19 | mongo:
20 | image: mongo:latest
21 | ports:
22 | - 27017:27017
23 | command: -smallfiles -nojournal
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/java/com/github/wkennedy/CassandraConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
5 | import org.springframework.data.cql.core.keyspace.DropKeyspaceSpecification;
6 |
7 | import java.util.Collections;
8 | import java.util.List;
9 |
10 | @Configuration
11 | public class CassandraConfig extends AbstractCassandraConfiguration {
12 |
13 | @Override
14 | protected String getKeyspaceName() {
15 | return "section_4_3";
16 | }
17 |
18 | @Override
19 | protected List getStartupScripts() {
20 | String script = "CREATE KEYSPACE IF NOT EXISTS section_4_3 WITH REPLICATION = { 'class' : 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '1' } AND DURABLE_WRITES = true;";
21 | return Collections.singletonList(script);
22 | }
23 |
24 | @Override
25 | protected List getKeyspaceDrops() {
26 | return Collections.singletonList(DropKeyspaceSpecification.dropKeyspace("section_4_3"));
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/java/com/github/wkennedy/Section43Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
7 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
8 |
9 | @SpringBootApplication
10 | //@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
11 | public class Section43Application {
12 |
13 | public static void main(String[] args) {
14 | SpringApplication.run(Section43Application.class, args);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/java/com/github/wkennedy/entities/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.entities;
2 |
3 | import org.springframework.data.annotation.Id;
4 | import org.springframework.data.cassandra.core.mapping.PrimaryKey;
5 | import org.springframework.data.cassandra.core.mapping.Table;
6 | import org.springframework.data.mongodb.core.mapping.Document;
7 |
8 | import java.util.UUID;
9 |
10 | @Table("person")
11 | @Document
12 | public class Person {
13 |
14 | @PrimaryKey("id")
15 | @Id
16 | private UUID id;
17 |
18 | private String lastName;
19 | private String firstName;
20 |
21 | public UUID getId() {
22 | return id;
23 | }
24 |
25 | public void setId(UUID id) {
26 | this.id = id;
27 | }
28 |
29 | public String getLastName() {
30 | return lastName;
31 | }
32 |
33 | public void setLastName(String lastName) {
34 | this.lastName = lastName;
35 | }
36 |
37 | public String getFirstName() {
38 | return firstName;
39 | }
40 |
41 | public void setFirstName(String firstName) {
42 | this.firstName = firstName;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "Person{" +
48 | "id=" + id +
49 | ", lastName='" + lastName + '\'' +
50 | ", firstName='" + firstName + '\'' +
51 | '}';
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/java/com/github/wkennedy/repositories/PersonCassandraRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.data.cassandra.repository.CassandraRepository;
5 | import org.springframework.data.mongodb.repository.MongoRepository;
6 |
7 | import java.util.UUID;
8 |
9 | public interface PersonCassandraRepository extends CassandraRepository {
10 | }
11 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/java/com/github/wkennedy/repositories/PersonMongoRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.data.mongodb.repository.MongoRepository;
5 |
6 | import java.util.UUID;
7 |
8 | public interface PersonMongoRepository extends MongoRepository {
9 | }
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.data.cassandra.keyspace-name=section_4_3
2 | spring.data.cassandra.contact-points=localhost
3 | spring.data.cassandra.schema-action=RECREATE_DROP_UNUSED
4 | #spring.data.cassandra.port=9042
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/test/java/com/github/wkennedy/repositories/PersonCassandraRepositoryIT.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.datastax.driver.core.utils.UUIDs;
4 | import com.github.wkennedy.entities.Person;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | import java.util.List;
13 |
14 | import static org.junit.Assert.assertEquals;
15 |
16 | @RunWith(SpringRunner.class)
17 | @SpringBootTest
18 | public class PersonCassandraRepositoryIT {
19 |
20 | @Autowired
21 | private PersonCassandraRepository personCassandraRepository;
22 |
23 | @Before
24 | public void before() throws Exception {
25 | personCassandraRepository.deleteAll();
26 | }
27 |
28 | @Test
29 | public void testPerson() throws Exception {
30 | Person person = new Person();
31 | person.setId(UUIDs.timeBased());
32 | person.setLastName("Doe");
33 | person.setFirstName("John");
34 |
35 | personCassandraRepository.save(person);
36 |
37 | List personList = personCassandraRepository.findAll();
38 | assertEquals(1, personList.size());
39 | Person personFromList = personList.get(0);
40 | assertEquals("Doe", personFromList.getLastName());
41 | assertEquals("John", personFromList.getFirstName());
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/test/java/com/github/wkennedy/repositories/PersonMongoRepositoryIT.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 |
11 | import java.util.List;
12 | import java.util.UUID;
13 |
14 | import static org.junit.Assert.assertEquals;
15 |
16 | @RunWith(SpringRunner.class)
17 | @DataMongoTest()
18 | public class PersonMongoRepositoryIT {
19 |
20 | @Autowired
21 | private PersonMongoRepository personMongoRepository;
22 |
23 | @Before
24 | public void setup() {
25 | personMongoRepository.deleteAll();
26 | }
27 |
28 | @Test
29 | public void testMongo() {
30 | Person person = new Person();
31 | person.setId(UUID.randomUUID());
32 | person.setLastName("Doe");
33 | person.setFirstName("John");
34 |
35 | personMongoRepository.save(person);
36 |
37 | List personList = personMongoRepository.findAll();
38 | assertEquals(1, personList.size());
39 | Person personFromList = personList.get(0);
40 | assertEquals("Doe", personFromList.getLastName());
41 | assertEquals("John", personFromList.getFirstName());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_3/src/test/resources/init.cql:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_3/src/test/resources/init.cql
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_4/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | cassandra0:
6 | image: cassandra:3.2
7 | ports:
8 | - 7000:7000
9 | - 9042:9042
10 | - 9160:9160
11 |
12 | cassandra1:
13 | image: cassandra:3.2
14 | links:
15 | - cassandra0:seed
16 | environment:
17 | - CASSANDRA_SEEDS=seed
18 |
19 | mongo:
20 | image: mongo:latest
21 | ports:
22 | - 27017:27017
23 | command: -smallfiles -nojournal
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/src/main/java/com/github/wkennedy/Section44Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
7 | import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
8 | import org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration;
9 |
10 | @SpringBootApplication
11 | @EnableAutoConfiguration(exclude = {CassandraDataAutoConfiguration.class})
12 | public class Section44Application {
13 |
14 | public static void main(String[] args) {
15 | SpringApplication.run(Section44Application.class, args);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/src/main/java/com/github/wkennedy/entities/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.entities;
2 |
3 | import org.springframework.data.annotation.Id;
4 | import org.springframework.data.cassandra.core.mapping.PrimaryKey;
5 | import org.springframework.data.cassandra.core.mapping.Table;
6 | import org.springframework.data.mongodb.core.mapping.Document;
7 |
8 | import java.io.Serializable;
9 | import java.util.UUID;
10 |
11 | @Table("person")
12 | @Document
13 | public class Person implements Serializable {
14 |
15 | @PrimaryKey("id")
16 | @Id
17 | private String id;
18 |
19 | private String lastName;
20 | private String firstName;
21 |
22 | public Person() {
23 | }
24 |
25 | public Person(String lastName, String firstName) {
26 | this.id = UUID.randomUUID().toString();
27 | this.lastName = lastName;
28 | this.firstName = firstName;
29 | }
30 |
31 | public String getId() {
32 | return id;
33 | }
34 |
35 | public void setId(String id) {
36 | this.id = id;
37 | }
38 |
39 | public String getLastName() {
40 | return lastName;
41 | }
42 |
43 | public void setLastName(String lastName) {
44 | this.lastName = lastName;
45 | }
46 |
47 | public String getFirstName() {
48 | return firstName;
49 | }
50 |
51 | public void setFirstName(String firstName) {
52 | this.firstName = firstName;
53 | }
54 |
55 | @Override
56 | public String toString() {
57 | return "Person{" +
58 | "id=" + id +
59 | ", lastName='" + lastName + '\'' +
60 | ", firstName='" + firstName + '\'' +
61 | '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/src/main/java/com/github/wkennedy/repositories/PersonReactiveCassandraRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.data.cassandra.repository.ReactiveCassandraRepository;
5 |
6 | public interface PersonReactiveCassandraRepository extends ReactiveCassandraRepository{
7 | }
8 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/src/main/java/com/github/wkennedy/repositories/PersonReactiveMongoRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
5 |
6 | public interface PersonReactiveMongoRepository extends ReactiveMongoRepository {
7 | }
8 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_4/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.reactor.stacktrace-mode.enabled=false
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_4/section_4_5/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/docker/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: '3'
2 |
3 | services:
4 |
5 | redis:
6 | image: redis:latest
7 | ports:
8 | - 6380:6380
9 | - 6379:6379
10 |
11 | redisCommander:
12 | image: tenstartups/redis-commander
13 | command: '--redis-host redis'
14 | links:
15 | - redis:redis
16 | ports:
17 | - 8081:8081
18 |
19 | mongo:
20 | image: mongo:latest
21 | ports:
22 | - 27017:27017
23 | command: -smallfiles -nojournal
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/main/java/com/github/wkennedy/CacheConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.cache.annotation.EnableCaching;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableCaching
8 | public class CacheConfig {
9 | }
10 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/main/java/com/github/wkennedy/Section45Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class Section45Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(Section45Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/main/java/com/github/wkennedy/repositories/PersonMongoRepository.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.cache.annotation.CacheEvict;
5 | import org.springframework.cache.annotation.Cacheable;
6 | import org.springframework.data.mongodb.repository.MongoRepository;
7 |
8 | import java.util.Optional;
9 |
10 | public interface PersonMongoRepository extends MongoRepository {
11 |
12 | @Override
13 | @CacheEvict(value = "findById", key = "#root.args[0].id")
14 | S save(S entity);
15 |
16 | @Cacheable(value = "findById", key = "#a0")
17 | Optional findById(String id);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/main/java/com/github/wkennedy/service/SimpleService.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.service;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import com.github.wkennedy.repositories.PersonMongoRepository;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.cache.annotation.CacheEvict;
7 | import org.springframework.cache.annotation.Cacheable;
8 | import org.springframework.stereotype.Service;
9 |
10 | @Service
11 | public class SimpleService {
12 |
13 | private final PersonMongoRepository personMongoRepository;
14 |
15 | @Autowired
16 | public SimpleService(PersonMongoRepository personMongoRepository) {
17 | this.personMongoRepository = personMongoRepository;
18 | }
19 |
20 | @CacheEvict(value="findById", key = "#person?.id")
21 | public void save(Person person) {
22 | personMongoRepository.save(person);
23 | }
24 |
25 | @Cacheable(value="findById", key="#id")
26 | public Person getPersonById(String id) {
27 | artificialLatency(3000L);
28 | return personMongoRepository.findById(id).get();
29 | }
30 |
31 | private void artificialLatency(long milliseconds){
32 | try {
33 | System.out.println("Artificial latency...");
34 | Thread.sleep(milliseconds);
35 | } catch (InterruptedException e) {
36 | throw new IllegalStateException(e);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.cache.type=simple
2 |
3 | debug=false
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/test/java/com/github/wkennedy/Section45ApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class Section45ApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/test/java/com/github/wkennedy/repositories/PersonMongoRepositoryTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.repositories;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.junit.After;
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | import static org.junit.Assert.*;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest()
17 | public class PersonMongoRepositoryTest {
18 |
19 | @Autowired
20 | private PersonMongoRepository personMongoRepository;
21 |
22 | private Person person = new Person("Doh", "John");
23 |
24 | @Before
25 | public void setUp() throws Exception {
26 | personMongoRepository.save(person);
27 | }
28 |
29 | @After
30 | public void tearDown() throws Exception {
31 | personMongoRepository.deleteAll();
32 | }
33 |
34 | @Test
35 | public void basicTest() throws Exception {
36 | Person personFromId = personMongoRepository.findById(person.getId()).get();
37 | System.out.println(personFromId.toString());
38 |
39 | personFromId = personMongoRepository.findById(person.getId()).get();
40 | System.out.println(personFromId.toString());
41 |
42 | personFromId.setFirstName("Test");
43 | personMongoRepository.save(personFromId);
44 |
45 | Thread.sleep(2000);
46 |
47 | personFromId = personMongoRepository.findById(person.getId()).get();
48 | System.out.println(personFromId.toString());
49 |
50 | personFromId = personMongoRepository.findById(person.getId()).get();
51 | System.out.println(personFromId.toString());
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_4/section_4_5/src/test/java/com/github/wkennedy/service/SimpleServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.service;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import com.github.wkennedy.repositories.PersonMongoRepository;
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 |
13 | import static org.junit.Assert.*;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest()
17 | public class SimpleServiceTest {
18 |
19 | private Person person = new Person("Doh", "John");
20 |
21 | @Autowired
22 | private PersonMongoRepository personMongoRepository;
23 |
24 | @Autowired
25 | private SimpleService simpleService;
26 |
27 | @Before
28 | public void setUp() throws Exception {
29 | personMongoRepository.save(person);
30 | }
31 |
32 | @After
33 | public void tearDown() throws Exception {
34 | personMongoRepository.deleteAll();
35 | }
36 |
37 | @Test
38 | public void getPersonById() throws Exception {
39 | Person personFromId = simpleService.getPersonById(person.getId());
40 | System.out.println(personFromId.toString());
41 |
42 | personFromId = simpleService.getPersonById(person.getId());
43 | System.out.println(personFromId.toString());
44 |
45 | personFromId.setFirstName("Test");
46 | simpleService.save(personFromId);
47 |
48 | personFromId = simpleService.getPersonById(person.getId());
49 | System.out.println(personFromId.toString());
50 |
51 | personFromId = simpleService.getPersonById(person.getId());
52 | System.out.println(personFromId.toString());
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_1/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_1/authorization_server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/README.md:
--------------------------------------------------------------------------------
1 |
2 | cURL command to get a token using client_credentials grant type
3 |
4 | curl client:secret@localhost:8082/auth/oauth/token -d grant_type=client_credentials -d scope=read -d client_id=client -d client_secret=secret -d username=client -d password=secret
5 |
6 | curl -H "Authorization: Bearer 872048f3-8c15-4dd4-a20a-3b6fe5aa2a52" http://localhost:8082/auth/me
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/src/main/java/com/github/wkennedy/AuthorizationServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.security.Principal;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableResourceServer
14 | public class AuthorizationServerApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(AuthorizationServerApplication.class, args);
18 | }
19 |
20 | @GetMapping(value = {"/user", "/me"})
21 | public Principal user(Principal user) {
22 | return user;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/src/main/java/com/github/wkennedy/SecurityConfiguration.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.springframework.beans.factory.annotation.Autowired;
4 | //import org.springframework.context.annotation.Configuration;
5 | //import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
6 | //import org.springframework.security.config.annotation.web.builders.HttpSecurity;
7 | //import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
8 | //import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 | //
10 | //@Configuration
11 | //@EnableWebSecurity
12 | //public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
13 | //
14 | // @Autowired
15 | // public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
16 | // auth.inMemoryAuthentication().withUser("user1").password("pass1").roles("USER");
17 | // auth.inMemoryAuthentication().withUser("user2").password("pass2").roles("USER");
18 | // auth.inMemoryAuthentication().withUser("admin").password("root123").roles("ADMIN");
19 | // }
20 | //
21 | // @Override
22 | // protected void configure(HttpSecurity http) throws Exception {
23 | //
24 | // http.authorizeRequests()
25 | // .antMatchers("/", "/home").permitAll()
26 | // .antMatchers("/admin/**").access("hasRole('ADMIN')")
27 | // .and().formLogin()
28 | // .and().exceptionHandling().accessDeniedPage("/Access_Denied");
29 | //
30 | // }
31 | //}
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.level.org.springframework.security=DEBUG
2 | server.servlet.context-path=/auth
3 |
4 | spring.datasource.platform=h2
5 |
6 | security.user.name=my-user
7 | security.user.password=password
8 |
9 | security.oauth2.client.client-id=client
10 | security.oauth2.client.client-secret=secret
11 | security.oauth2.authorization.checkTokenAccess=isAuthenticated()
12 |
13 | server.port=8082
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/authorization_server/src/test/java/com/github/wkennedy/AuthorizationServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class AuthorizationServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_1/resource_server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/main/java/com/github/wkennedy/ResourceServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ResourceServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ResourceServerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/main/java/com/github/wkennedy/ResourceServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
9 |
10 | @Configuration
11 | @EnableResourceServer
12 | @EnableGlobalMethodSecurity(prePostEnabled = true)
13 | public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/main/java/com/github/wkennedy/controllers/ResourceController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.security.access.annotation.Secured;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.UUID;
9 |
10 | @RestController
11 | public class ResourceController {
12 |
13 | @GetMapping("/")
14 | public String index() {
15 | return "Hello!";
16 | }
17 |
18 | @GetMapping("/person")
19 | public Person getPerson() {
20 | Person person = new Person();
21 | person.setId(UUID.randomUUID().toString());
22 | person.setFirstName("John");
23 | person.setLastName("Doe");
24 |
25 | return person;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/main/java/com/github/wkennedy/entities/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.entities;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Person implements Serializable {
6 |
7 | private String id;
8 | private String lastName;
9 | private String firstName;
10 |
11 | public String getId() {
12 | return id;
13 | }
14 |
15 | public void setId(String id) {
16 | this.id = id;
17 | }
18 |
19 | public String getLastName() {
20 | return lastName;
21 | }
22 |
23 | public void setLastName(String lastName) {
24 | this.lastName = lastName;
25 | }
26 |
27 | public String getFirstName() {
28 | return firstName;
29 | }
30 |
31 | public void setFirstName(String firstName) {
32 | this.firstName = firstName;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "Person{" +
38 | "id='" + id + '\'' +
39 | ", lastName='" + lastName + '\'' +
40 | ", firstName='" + firstName + '\'' +
41 | '}';
42 | }
43 |
44 | @Override
45 | public boolean equals(Object o) {
46 | if (this == o) return true;
47 | if (o == null || getClass() != o.getClass()) return false;
48 |
49 | Person person = (Person) o;
50 |
51 | if (!id.equals(person.id)) return false;
52 | if (!lastName.equals(person.lastName)) return false;
53 | return firstName.equals(person.firstName);
54 | }
55 |
56 | @Override
57 | public int hashCode() {
58 | int result = id.hashCode();
59 | result = 31 * result + lastName.hashCode();
60 | result = 31 * result + firstName.hashCode();
61 | return result;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8083
2 | server.servlet.context-path=/resource
3 |
4 | security.oauth2.resource.user-info-uri=http://localhost:8082/auth/user
5 | #security.oauth2.resource.token-info-uri=http://localhost:8082/auth/oauth/check_token
6 | #security.oauth2.resource.prefer-token-info=false
7 | #security.oauth2.resource.jwt.key-value=
8 | #security.oauth2.resource.jwt.key-uri=
9 |
10 | logging.level.org.springframework.security=DEBUG
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/resource_server/src/test/java/com/github/wkennedy/ResourceServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ResourceServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_1/simple_service/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/src/main/java/com/github/wkennedy/SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.beans.factory.annotation.Qualifier;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.oauth2.client.OAuth2ClientContext;
7 | import org.springframework.security.oauth2.client.OAuth2RestTemplate;
8 | import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
9 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
10 |
11 | @Configuration
12 | @EnableOAuth2Client
13 | public class SecurityConfig {
14 |
15 | @Bean("oauth2RestTemplate")
16 | public OAuth2RestTemplate oauth2RestTemplate(@Qualifier("oauth2ClientContext") OAuth2ClientContext oauth2ClientContext,
17 | OAuth2ProtectedResourceDetails details) {
18 | return new OAuth2RestTemplate(details, oauth2ClientContext);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/src/main/java/com/github/wkennedy/SimpleServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SimpleServiceApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SimpleServiceApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.oauth2.client.OAuth2RestTemplate;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @RestController
10 | @RequestMapping("/api")
11 | public class SimpleController {
12 |
13 | private final OAuth2RestTemplate restTemplate;
14 |
15 | @Autowired
16 | public SimpleController(OAuth2RestTemplate restTemplate) {
17 | this.restTemplate = restTemplate;
18 | }
19 |
20 | @GetMapping("/person")
21 | public String getPerson() {
22 | return restTemplate.getForObject("http://localhost:8083/resource/person", String.class);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | security.oauth2.client.client-id=client
2 | security.oauth2.client.client-secret=secret
3 | security.oauth2.client.access-token-uri=http://localhost:8082/auth/oauth/token
4 | #security.oauth2.client.user-authorization-uri=http://localhost:8082/auth/oauth/authorize
5 | security.oauth2.client.client-authentication-scheme=header
6 | security.oauth2.client.grant-type=client_credentials
7 |
8 | security.basic.enabled=false
9 |
10 | logging.level.org.springframework.security=DEBUG
11 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_1/simple_service/src/test/java/com/github/wkennedy/SimpleServiceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SimpleServiceApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_2/authorization_server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/README.md:
--------------------------------------------------------------------------------
1 |
2 | cURL command to get a token using client_credentials grant type
3 |
4 | curl client:secret@localhost:8082/auth/oauth/token -d grant_type=client_credentials -d scope=read -d client_id=client -d client_secret=secret -d username=client -d password=secret
5 |
6 | curl -H "Authorization: Bearer 872048f3-8c15-4dd4-a20a-3b6fe5aa2a52" http://localhost:8082/auth/me
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/src/main/java/com/github/wkennedy/AuthorizationServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import java.security.Principal;
10 |
11 | @SpringBootApplication
12 | @RestController
13 | @EnableResourceServer
14 | public class AuthorizationServerApplication {
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(AuthorizationServerApplication.class, args);
18 | }
19 |
20 | @GetMapping(value = {"/user", "/me"})
21 | public Principal user(Principal user) {
22 | return user;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/src/main/java/com/github/wkennedy/SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.core.annotation.Order;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10 |
11 | @Configuration
12 | @EnableWebSecurity
13 | public class SecurityConfig extends WebSecurityConfigurerAdapter {
14 |
15 | @Override
16 | protected void configure(@Autowired AuthenticationManagerBuilder auth) throws Exception {
17 | auth.inMemoryAuthentication()
18 | .withUser("user")
19 | .password("password")
20 | .roles("USER");
21 | }
22 |
23 | @Override
24 | @Order(-20)
25 | protected void configure(HttpSecurity http) throws Exception {
26 | http.formLogin().permitAll()
27 | .and()
28 | .requestMatchers()
29 | .antMatchers("/", "/login", "/oauth/authorize", "/oauth/confirm_access")
30 | .and()
31 | .authorizeRequests()
32 | .anyRequest()
33 | .authenticated();
34 | }
35 | }
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/authorization_server/src/test/java/com/github/wkennedy/AuthorizationServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class AuthorizationServerApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_2/resource_server/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/main/java/com/github/wkennedy/ResourceServerApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ResourceServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ResourceServerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/main/java/com/github/wkennedy/ResourceServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
9 |
10 | @Configuration
11 | @EnableResourceServer
12 | @EnableGlobalMethodSecurity(prePostEnabled = true)
13 | public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/main/java/com/github/wkennedy/controllers/ResourceController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.entities.Person;
4 | import org.springframework.security.access.annotation.Secured;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.UUID;
9 |
10 | @RestController
11 | public class ResourceController {
12 |
13 | @GetMapping("/")
14 | public String index() {
15 | return "Hello!";
16 | }
17 |
18 | @GetMapping("/person")
19 | public Person getPerson() {
20 | Person person = new Person();
21 | person.setId(UUID.randomUUID().toString());
22 | person.setFirstName("John");
23 | person.setLastName("Doe");
24 |
25 | return person;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/main/java/com/github/wkennedy/entities/Person.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.entities;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Person implements Serializable {
6 |
7 | private String id;
8 | private String lastName;
9 | private String firstName;
10 |
11 | public String getId() {
12 | return id;
13 | }
14 |
15 | public void setId(String id) {
16 | this.id = id;
17 | }
18 |
19 | public String getLastName() {
20 | return lastName;
21 | }
22 |
23 | public void setLastName(String lastName) {
24 | this.lastName = lastName;
25 | }
26 |
27 | public String getFirstName() {
28 | return firstName;
29 | }
30 |
31 | public void setFirstName(String firstName) {
32 | this.firstName = firstName;
33 | }
34 |
35 | @Override
36 | public String toString() {
37 | return "Person{" +
38 | "id='" + id + '\'' +
39 | ", lastName='" + lastName + '\'' +
40 | ", firstName='" + firstName + '\'' +
41 | '}';
42 | }
43 |
44 | @Override
45 | public boolean equals(Object o) {
46 | if (this == o) return true;
47 | if (o == null || getClass() != o.getClass()) return false;
48 |
49 | Person person = (Person) o;
50 |
51 | if (!id.equals(person.id)) return false;
52 | if (!lastName.equals(person.lastName)) return false;
53 | return firstName.equals(person.firstName);
54 | }
55 |
56 | @Override
57 | public int hashCode() {
58 | int result = id.hashCode();
59 | result = 31 * result + lastName.hashCode();
60 | result = 31 * result + firstName.hashCode();
61 | return result;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8083
2 | server.servlet.context-path=/resource
3 |
4 | #security.oauth2.resource.jwt.key-uri=http://localhost:8082/auth/oauth/token_key
5 | security.oauth2.resource.jwt.key-value=-----BEGIN PUBLIC KEY----- \
6 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzRBEEDDMchv50okaINQP \
7 | tgvky1cz1Lyonzu/ny8BKjycrOgunnKkxovuunbtr1YgMZPHjVxxXvyy7bDffMXg \
8 | 6I4R0w7Q5YNYn+fvKDWAYCtNsKdoVaig/g3lZgSjUDOk8caYM7IQf1xq1E6m/qyr \
9 | jr7jyOwIko4RcZjLFgPBRmgtbwHqODFC3+UhJ52nyMbtbR5ILcNtO6Kp2IF6SA3D \
10 | iKW1wIIkjjntCVuM7UZMVSjqN9KnjeenWQWxy+B6kvOyGdhGtBBxuouxWaFmYOnr \
11 | WXeG10oMGna6oQNr2sU3FsqjmfGX6hGm7z4QetFaOF+Rg0Z8HS0jp36RBecAwdkO \
12 | ZwIDAQAB \
13 | -----END PUBLIC KEY-----
14 |
15 | logging.level.org.springframework.security=DEBUG
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server/src/test/java/com/github/wkennedy/ResourceServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class ResourceServerApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/main/java/com/github/wkennedy/ResourceServer2Application.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ResourceServer2Application {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ResourceServer2Application.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/main/java/com/github/wkennedy/ResourceServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
7 |
8 | @Configuration
9 | @EnableResourceServer
10 | @EnableGlobalMethodSecurity(prePostEnabled = true)
11 | public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/main/java/com/github/wkennedy/controllers/ResourceController2.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import com.github.wkennedy.entities.Order;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RestController;
6 |
7 | import java.util.UUID;
8 |
9 | @RestController
10 | public class ResourceController2 {
11 |
12 | @GetMapping("/")
13 | public String index() {
14 | return "Hello from Resource 2!";
15 | }
16 |
17 | @GetMapping("/order")
18 | public Order getOrder() {
19 | Order order = new Order();
20 | order.setOrderID(UUID.randomUUID().toString());
21 | order.setProduct("Acme Portal");
22 | order.setQuantity(1);
23 |
24 | return order;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/main/java/com/github/wkennedy/entities/Order.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.entities;
2 |
3 | public class Order {
4 | private String orderID;
5 | private String product;
6 | private Integer quantity;
7 |
8 | public String getOrderID() {
9 | return orderID;
10 | }
11 |
12 | public void setOrderID(String orderID) {
13 | this.orderID = orderID;
14 | }
15 |
16 | public String getProduct() {
17 | return product;
18 | }
19 |
20 | public void setProduct(String product) {
21 | this.product = product;
22 | }
23 |
24 | public Integer getQuantity() {
25 | return quantity;
26 | }
27 |
28 | public void setQuantity(Integer quantity) {
29 | this.quantity = quantity;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return "Order{" +
35 | "orderID='" + orderID + '\'' +
36 | ", product='" + product + '\'' +
37 | ", quantity=" + quantity +
38 | '}';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | server.port=8084
2 | server.servlet.context-path=/resource2
3 |
4 | #security.oauth2.resource.user-info-uri=http://localhost:8082/auth/user
5 | #security.oauth2.resource.token-info-uri=http://localhost:8082/auth/oauth/check_token
6 | #security.oauth2.resource.prefer-token-info=false
7 | #security.oauth2.resource.jwt.key-uri=http://localhost:8082/auth/oauth/token_key
8 | security.oauth2.resource.jwt.key-value=-----BEGIN PUBLIC KEY----- \
9 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzRBEEDDMchv50okaINQP \
10 | tgvky1cz1Lyonzu/ny8BKjycrOgunnKkxovuunbtr1YgMZPHjVxxXvyy7bDffMXg \
11 | 6I4R0w7Q5YNYn+fvKDWAYCtNsKdoVaig/g3lZgSjUDOk8caYM7IQf1xq1E6m/qyr \
12 | jr7jyOwIko4RcZjLFgPBRmgtbwHqODFC3+UhJ52nyMbtbR5ILcNtO6Kp2IF6SA3D \
13 | iKW1wIIkjjntCVuM7UZMVSjqN9KnjeenWQWxy+B6kvOyGdhGtBBxuouxWaFmYOnr \
14 | WXeG10oMGna6oQNr2sU3FsqjmfGX6hGm7z4QetFaOF+Rg0Z8HS0jp36RBecAwdkO \
15 | ZwIDAQAB \
16 | -----END PUBLIC KEY-----
17 |
18 | logging.level.org.springframework.security=DEBUG
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/resource_server_2/src/test/java/com/github/wkennedy/ResourceServer2ApplicationTests.java:
--------------------------------------------------------------------------------
1 | //package com.github.wkennedy;
2 | //
3 | //import org.junit.Test;
4 | //import org.junit.runner.RunWith;
5 | //import org.springframework.boot.test.context.SpringBootTest;
6 | //import org.springframework.test.context.junit4.SpringRunner;
7 | //
8 | //@RunWith(SpringRunner.class)
9 | //@SpringBootTest
10 | //public class ResourceServer2ApplicationTests {
11 | //
12 | // @Test
13 | // public void contextLoads() {
14 | // }
15 | //
16 | //}
17 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wkennedy/mastering-spring-5-development/ce7f6cc4d1d9f84a68126cc55859d847cdb50754/spring-boot-fundamentals/section_5/section_5_2/simple_service/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/src/main/java/com/github/wkennedy/SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.beans.factory.annotation.Qualifier;
4 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 | import org.springframework.security.oauth2.client.OAuth2ClientContext;
10 | import org.springframework.security.oauth2.client.OAuth2RestTemplate;
11 | import org.springframework.security.oauth2.client.resource.OAuth2ProtectedResourceDetails;
12 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
13 |
14 | @Configuration
15 | @EnableOAuth2Client
16 | //@EnableOAuth2Sso
17 | public class SecurityConfig { //extends WebSecurityConfigurerAdapter {
18 |
19 | @Bean("oauth2RestTemplate")
20 | public OAuth2RestTemplate oauth2RestTemplate(@Qualifier("oauth2ClientContext") OAuth2ClientContext oauth2ClientContext,
21 | OAuth2ProtectedResourceDetails details) {
22 | return new OAuth2RestTemplate(details, oauth2ClientContext);
23 | }
24 |
25 | // @Override
26 | // protected void configure(HttpSecurity http) throws Exception {
27 | // http.antMatcher("/**").authorizeRequests().anyRequest().authenticated();
28 | // }
29 | }
30 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/src/main/java/com/github/wkennedy/SimpleServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SimpleServiceApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SimpleServiceApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/src/main/java/com/github/wkennedy/controllers/SimpleController.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.oauth2.client.OAuth2RestTemplate;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @RestController
10 | @RequestMapping("/api")
11 | public class SimpleController {
12 |
13 | private final OAuth2RestTemplate restTemplate;
14 |
15 | @Autowired
16 | public SimpleController(OAuth2RestTemplate restTemplate) {
17 | this.restTemplate = restTemplate;
18 | }
19 |
20 | @GetMapping("/person")
21 | public String getPerson() {
22 | return restTemplate.getForObject("http://localhost:8083/resource/person", String.class);
23 | }
24 |
25 | // @GetMapping("/order")
26 | // public String getOrder() {
27 | // return restTemplate.getForObject("http://localhost:8084/resource2/order", String.class);
28 | // }
29 | //
30 | // @GetMapping("/person_order")
31 | // public String getPersonOrder() {
32 | // String person = restTemplate.getForObject("http://localhost:8083/resource/person", String.class);
33 | // String order = restTemplate.getForObject("http://localhost:8084/resource2/order", String.class);
34 | // return person + order;
35 | // }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | security.oauth2.client.client-id=client
2 | security.oauth2.client.client-secret=secret
3 | security.oauth2.client.access-token-uri=http://localhost:8082/auth/oauth/token
4 | security.oauth2.client.user-authorization-uri=http://localhost:8082/auth/oauth/authorize
5 | #security.oauth2.client.client-authentication-scheme=header
6 | security.oauth2.client.grant-type=authorization_code
7 |
8 | #security.oauth2.resource.jwt.key-uri=http://localhost:8082/auth/oauth/token_key
9 |
10 | security.basic.enabled=false
11 |
12 | logging.level.org.springframework.security=DEBUG
13 |
--------------------------------------------------------------------------------
/spring-boot-fundamentals/section_5/section_5_2/simple_service/src/test/java/com/github/wkennedy/SimpleServiceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.github.wkennedy;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SimpleServiceApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------