├── .gitignore ├── LICENSE ├── README.md ├── spring-boot-authorization-server-example ├── README.md ├── spring-boot-authorization-server-example │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── AuthorizationServerApplication.java │ │ │ │ ├── configuration │ │ │ │ └── SecurityConfig.java │ │ │ │ └── web │ │ │ │ └── PrincipalController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── AuthorizationServerApplicationTests.java └── spring-boot-resource-server-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── ResourceServerApplication.java │ │ │ └── web │ │ │ └── CodeCoupleController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── ResourceServerApplicationTests.java ├── spring-boot-config-example ├── README.md ├── spring-boot-config-client-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ └── config │ │ │ │ └── client │ │ │ │ ├── ConfigClientApplication.java │ │ │ │ └── ConfigClientController.java │ │ └── resources │ │ │ └── bootstrap.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── config │ │ └── client │ │ └── ConfigClientApplicationTests.java ├── spring-boot-config-properties-example │ ├── README.md │ ├── application.properties │ └── client-service.properties └── spring-boot-config-server-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ └── config │ │ │ └── server │ │ │ └── ConfigServerApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── config │ └── server │ └── ConfigServerApplicationTests.java ├── spring-boot-consumer-driven-contract-example ├── README.md ├── spring-boot-consumer-driven-contract-consumer-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── ConsumerApplication.java │ │ │ │ └── consumer │ │ │ │ └── ConsumerController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ ├── ConsumerApplicationTests.java │ │ └── consumer │ │ └── ConsumerControllerIntegrationTest.java └── spring-boot-consumer-driven-contract-producer-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── ProducerApplication.java │ │ │ └── producer │ │ │ └── UserController.java │ └── resources │ │ └── bootstrap.properties │ └── test │ ├── java │ └── pl │ │ └── codecouple │ │ └── producer │ │ └── BaseClass.java │ └── resources │ └── contracts │ └── shouldReturnUser.groovy ├── spring-boot-docker-compose-example ├── README.md ├── consumer │ ├── Dockerfile │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── DemoApplication.java │ │ │ │ └── consumer │ │ │ │ └── QueueConsumer.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── DemoApplicationTests.java ├── docker-compose.yml └── producer │ ├── Dockerfile │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── DemoApplication.java │ │ │ └── producer │ │ │ └── QueueProducer.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── DemoApplicationTests.java ├── spring-boot-dockerfile-example ├── .gitignore ├── Dockerfile ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── DockerApplication.java │ │ │ └── web │ │ │ └── CodeCoupleController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── DockerApplicationTests.java ├── spring-boot-eureka-example ├── README.md ├── spring-boot-eureka-app-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── SpringBootEurekaAppExampleApplication.java │ │ │ │ └── controller │ │ │ │ └── CodeCoupleController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── SpringBootEurekaAppExampleApplicationTests.java ├── spring-boot-eureka-client-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── SpringBootEurekaClientExampleApplication.java │ │ │ │ └── controller │ │ │ │ └── ClientController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── SpringBootEurekaClientExampleApplicationTests.java └── spring-boot-eureka-server-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ └── SpringBootEurekaServerExampleApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SpringBootEurekaServerExampleApplicationTests.java ├── spring-boot-green-mail-example ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── GreenMailApplication.java │ │ │ └── email │ │ │ └── EmailSender.java │ └── resources │ │ └── application-email.properties │ └── test │ └── java │ └── pl │ └── codecouple │ ├── GreenMailApplicationTests.java │ └── email │ └── EmailSenderTest.java ├── spring-boot-hystrix-dashboard-example ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── HystrixDashboardExampleApplication.java │ │ │ └── web │ │ │ └── RandomController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── HystrixDashboardExampleApplicationTests.java ├── spring-boot-hystrix-example ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── HystrixExampleApplication.java │ │ │ └── web │ │ │ └── RandomController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── HystrixExampleApplicationTests.java ├── spring-boot-hystrix-turbine-example ├── README.md ├── spring-boot-hystrix-turbine-app-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ └── TurbineServiceApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── TurbineServiceApplicationTests.java ├── spring-boot-hystrix-turbine-discovery-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ └── DiscoveryServiceApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── DiscoveryServiceApplicationTests.java ├── spring-boot-hystrix-turbine-first-app-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── FirstServiceApplication.java │ │ │ │ └── rest │ │ │ │ └── HystrixController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── FirstServiceApplicationTests.java └── spring-boot-hystrix-turbine-second-app-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── SecondServiceApplication.java │ │ │ └── rest │ │ │ └── HystrixSecondController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SecondServiceApplicationTests.java ├── spring-boot-properties-example ├── LICENSE ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── pl │ │ └── codecouple │ │ └── properties │ │ ├── PropertiesApplication.java │ │ └── custom │ │ └── CustomProperties.java │ └── resources │ └── application.properties ├── spring-boot-rabbitmq-example ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── DemoApplication.java │ │ │ ├── consumer │ │ │ └── QueueConsumer.java │ │ │ └── producer │ │ │ └── QueueProducer.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── DemoApplicationTests.java ├── spring-boot-resource-server-example ├── README.md ├── spring-boot-resource-server-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── ResourceServerApplication.java │ │ │ │ └── web │ │ │ │ └── CodeCoupleController.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── ResourceServerApplicationTests.java └── spring-boot-sso-example │ ├── .gitignore │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── SsoApplication.java │ │ │ ├── configuration │ │ │ └── WebSecurityConfig.java │ │ │ └── web │ │ │ └── CodeCoupleController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SsoApplicationTests.java ├── spring-boot-rest-docs-example ├── README.md ├── pom.xml └── src │ ├── main │ ├── documentation │ │ ├── asciidoc │ │ │ └── todos-manual.adoc │ │ └── html │ │ │ └── todos-manual.html │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── DocumentationApplication.java │ │ │ └── todos │ │ │ ├── Todo.java │ │ │ └── TodoController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── TodoDocumentation.java ├── spring-boot-sso-example ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── SsoApplication.java │ │ │ ├── configuration │ │ │ └── WebSecurityConfig.java │ │ │ └── web │ │ │ └── CodeCoupleController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SsoApplicationTests.java ├── spring-boot-update-example ├── LICENSE ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ └── update │ │ │ ├── UpdateExampleApplication.java │ │ │ └── todo │ │ │ ├── Todo.java │ │ │ ├── TodoController.java │ │ │ ├── TodoNotFound.java │ │ │ ├── TodoRepository.java │ │ │ └── TodoService.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── update │ ├── UpdateExampleApplicationTests.java │ └── todo │ ├── TodoControllerTest.java │ ├── TodoRepositoryTest.java │ └── TodoTest.java ├── spring-boot-zipkin-example ├── README.md ├── spring-boot-zipkin-client-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ ├── ClientController.java │ │ │ │ └── SpringBootZipkinClientExampleApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── SpringBootZipkinClientExampleApplicationTests.java ├── spring-boot-zipkin-server-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── pl │ │ │ │ └── codecouple │ │ │ │ └── TracingServerApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── pl │ │ └── codecouple │ │ └── TracingServerApplicationTests.java └── spring-boot-zipkin-service-example │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── ServiceController.java │ │ │ └── SpringBootZipkinServiceExampleApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SpringBootZipkinServiceExampleApplicationTests.java └── spring-boot-zuul-example ├── README.md ├── spring-boot-zuul-eureka-service-example ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ └── DiscoveryServiceApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── DiscoveryServiceApplicationTests.java ├── spring-boot-zuul-first-service-example ├── .gitignore ├── pom.xml └── src │ └── main │ ├── java │ └── pl │ │ └── codecouple │ │ ├── FirstServiceApplication.java │ │ └── web │ │ └── FirstController.java │ └── resources │ └── application.properties ├── spring-boot-zuul-second-service-example ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── pl │ │ │ └── codecouple │ │ │ ├── SecondServiceApplication.java │ │ │ └── web │ │ │ └── SecondController.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── pl │ └── codecouple │ └── SecondServiceApplicationTests.java └── spring-boot-zuul-service-example ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── pl │ │ └── codecouple │ │ ├── ZuulServiceApplication.java │ │ └── filters │ │ └── CustomFilter.java └── resources │ └── application.properties └── test └── java └── pl └── codecouple └── ZuulServiceApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | target/ 25 | .mvn 26 | mvnw* 27 | 28 | ### IntelliJ IDEA ### 29 | .idea 30 | *.iws 31 | *.iml 32 | *.ipr 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | # Spring Boot Examples 2 | This repository contains all my Spring Boot Examples. 3 | Feel free to modify as you needed. 4 | All examples are independent! 5 | 6 | For all examples you can found the articles on https://CodeCouple.pl 7 | 8 | ## Examples 9 | 10 | * [Spring Boot Config](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-config-example) 11 | * [Spring Boot Consumer Driven Contract](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-consumer-driven-contract-example) 12 | * [Spring Boot Docker Compose](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-docker-compose-example) 13 | * [Spring Boot Dockerfile](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-dockerfile-example) 14 | * [Spring Boot Eureka](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-eureka-example) 15 | * [Spring Boot Hystrix Dashboard](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-hystrix-dashboard-example) 16 | * [Spring Boot Hystrix](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-hystrix-example) 17 | * [Spring Boot Hystrix Turbine](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-hystrix-turbine-example) 18 | * [Spring Boot Properties](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-properties-example) 19 | * [Spring Boot RabbitMQ](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-rabbitmq-example) 20 | * [Spring Boot REST Docs](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-rest-docs-example) 21 | * [Spring Boot Update PUT - POST - PATCH](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-update-example) 22 | * [Spring Boot Zipkin](https://github.com/kchrusciel/Spring-Boot-Examples/tree/master/spring-boot-zipkin-example) 23 | 24 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Resource Server 2 | This repository contains Spring Boot Resource Server example -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/.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-authorization-server-example/spring-boot-authorization-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | authorization-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | authorization-server 12 | Authorization-Server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/src/main/java/pl/codecouple/AuthorizationServerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 7 | 8 | @SpringBootApplication 9 | @EnableAuthorizationServer 10 | @EnableResourceServer 11 | public class AuthorizationServerApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(AuthorizationServerApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/src/main/java/pl/codecouple/configuration/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.configuration; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 | import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; 6 | 7 | /** 8 | * Created by CodeCouple.pl 9 | */ 10 | @Configuration 11 | class SecurityConfig extends GlobalAuthenticationConfigurerAdapter { 12 | 13 | @Override 14 | public void init(AuthenticationManagerBuilder auth) throws Exception { 15 | auth.inMemoryAuthentication() 16 | .withUser("code").password("couple").roles("USER, ADMIN") 17 | .and() 18 | .withUser("jan").password("nowak").roles("USER"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/src/main/java/pl/codecouple/web/PrincipalController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import java.security.Principal; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @RestController 12 | class PrincipalController { 13 | 14 | @GetMapping("/user") 15 | Principal getPrinciapl(Principal principal){ 16 | return principal; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9191 2 | 3 | security.oauth2.client.client-id=my-unique-client-id 4 | security.oauth2.client.client-secret=my-unique-client-secret 5 | security.oauth2.client.authorized-grant-types=password 6 | security.oauth2.client.scope=read,write -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-authorization-server-example/src/test/java/pl/codecouple/AuthorizationServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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-authorization-server-example/spring-boot-resource-server-example/.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-authorization-server-example/spring-boot-resource-server-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Resource Server 2 | This repository contains Spring Boot Resource Server example -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-resource-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | resource-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | resource-server 12 | Resource server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-resource-server-example/src/main/java/pl/codecouple/ResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 | 7 | @SpringBootApplication 8 | @EnableResourceServer 9 | public class ResourceServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ResourceServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-resource-server-example/src/main/java/pl/codecouple/web/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * Created by CodeCouple.pl 8 | */ 9 | @RestController 10 | class CodeCoupleController { 11 | 12 | @GetMapping("/not-for-all") 13 | String showCodeCouple(){ 14 | return "Code Couple!"; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-resource-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #User info endpoint 2 | security.oauth2.resource.user-info-uri=http://localhost:9191/user 3 | #Prefer user info 4 | security.oauth2.resource.prefer-token-info=false -------------------------------------------------------------------------------- /spring-boot-authorization-server-example/spring-boot-resource-server-example/src/test/java/pl/codecouple/ResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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-config-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Config Server 2 | This repository contains Spring Boot Config Server example -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-config-client-example 2 | SpringBoot Config Client - example 3 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple.config.client 7 | config-client 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | config-client 12 | Demo project for Config Client 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Brixton.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-config-client 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-actuator 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-dependencies 54 | ${spring-cloud.version} 55 | pom 56 | import 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/src/main/java/pl/codecouple/config/client/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.config.client; 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 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/src/main/java/pl/codecouple/config/client/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.config.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * Created by Krzysztof Chruściel. 10 | */ 11 | @RestController 12 | @RefreshScope 13 | public class ConfigClientController { 14 | 15 | @Value("${info.property}") 16 | private String property; 17 | 18 | @Value("${info.encrypted.property}") 19 | private String encrypted; 20 | 21 | @GetMapping("/message") 22 | String property() { 23 | return property; 24 | } 25 | 26 | @GetMapping("/decrypted") 27 | String decrypted() { 28 | return encrypted; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | #Application name 2 | spring.application.name=client-service 3 | #Config server address by default is 8888 4 | spring.cloud.config.uri=http://localhost:8888 5 | #Disable security for actuators 6 | management.security.enabled=false 7 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-client-example/src/test/java/pl/codecouple/config/client/ConfigClientApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.config.client; 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 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-properties-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Config Server Properties 2 | This repository contains Spring Boot Config Server Properties example -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-properties-example/application.properties: -------------------------------------------------------------------------------- 1 | #INFO 2 | info.property=CodeCouple.pl roxx! -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-properties-example/client-service.properties: -------------------------------------------------------------------------------- 1 | #INFO 2 | info.property=CodeCouple.pl roxx on client-service! 3 | #ENCRYPTED INGO 4 | info.encrypted.property={cipher}9fca2fb73afa4b2cd0b769ff27068dd4feec91ea246b06ec073029ea981b8693868da94bc42d7e0d87b51d3e1aad0a14 5 | #SERVER PORT 6 | server.port=8081 7 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-config-server-example 2 | SpringBoot Config Server - example 3 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple.config.server 7 | config-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | config-server 12 | Demo project for Config Server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Brixton.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-config-server 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-dependencies 49 | ${spring-cloud.version} 50 | pom 51 | import 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/src/main/java/pl/codecouple/config/server/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.config.server; 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 | -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Applicatione name 2 | spring.application.name=config-server 3 | #Conventional port number 4 | server.port=8888 5 | #URI to GIT with all properties 6 | spring.cloud.config.server.git.uri=file://${user.home}/Desktop/GIT/spring-boot-config-properties-example 7 | #Cipher value, this value should comes from ENV variables 8 | encrypt.key=secret -------------------------------------------------------------------------------- /spring-boot-config-example/spring-boot-config-server-example/src/test/java/pl/codecouple/config/server/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.config.server; 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 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Consumer Driven Contract Example 2 | This repository contains Spring Boot Consumer Driven Contract example 3 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/.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-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-consumer-driven-contract-consumer-example 2 | spring-boot-consumer-driven-contract-consumer-example 3 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | consumer 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | consumer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-starter-contract-stub-runner 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.cloud 54 | spring-cloud-dependencies 55 | ${spring-cloud.version} 56 | pom 57 | import 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/src/main/java/pl/codecouple/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | public class ConsumerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConsumerApplication.class, args); 16 | } 17 | 18 | @Bean 19 | @LoadBalanced 20 | RestTemplate restTemplate() { 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/src/main/java/pl/codecouple/consumer/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.consumer; 2 | 3 | import org.springframework.http.*; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @RestController 12 | class ConsumerController { 13 | 14 | private final RestTemplate restTemplate; 15 | 16 | ConsumerController(RestTemplate restTemplate) { 17 | this.restTemplate = restTemplate; 18 | } 19 | 20 | @GetMapping("/") 21 | ResponseEntity showCodeCouple(){ 22 | HttpHeaders headers = new HttpHeaders(); 23 | headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); 24 | HttpEntity entity = new HttpEntity<>(headers); 25 | return restTemplate.exchange( 26 | "http://producer-service/", 27 | HttpMethod.GET, 28 | entity, 29 | String.class); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=consumer-service -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/src/test/java/pl/codecouple/ConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 ConsumerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-consumer-example/src/test/java/pl/codecouple/consumer/ConsumerControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.consumer; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | import org.springframework.test.web.servlet.MockMvc; 11 | import org.springframework.test.web.servlet.ResultActions; 12 | 13 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 16 | 17 | /** 18 | * Created by CodeCouple.pl 19 | */ 20 | @RunWith(SpringRunner.class) 21 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) 22 | @AutoConfigureMockMvc 23 | @AutoConfigureStubRunner(workOffline = true, ids = { "pl.codecouple:producer-service" }) 24 | public class ConsumerControllerIntegrationTest { 25 | 26 | @Autowired 27 | MockMvc mockMvc; 28 | 29 | @Test 30 | public void shouldReturnUser() throws Exception { 31 | // When 32 | ResultActions result = mockMvc.perform(get("/")); 33 | // Then 34 | result.andExpect(status().isOk()) 35 | .andExpect(content().json("{\"id\":1,\"name\":\"CodeCouple.pl\"}")); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/.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-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-consumer-driven-contract-producer-example 2 | spring-boot-consumer-driven-contract-producer-example 3 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | producer-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | producer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.projectlombok 39 | lombok 40 | true 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | org.springframework.cloud 50 | spring-cloud-starter-contract-verifier 51 | test 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.springframework.cloud 59 | spring-cloud-dependencies 60 | ${spring-cloud.version} 61 | pom 62 | import 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-maven-plugin 72 | 73 | 74 | org.springframework.cloud 75 | spring-cloud-contract-maven-plugin 76 | 1.1.4.RELEASE 77 | true 78 | 79 | pl.codecouple.producer.BaseClass 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/src/main/java/pl/codecouple/ProducerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class ProducerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ProducerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/src/main/java/pl/codecouple/producer/UserController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.producer; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @RestController 12 | class UserController { 13 | 14 | @GetMapping("/") 15 | UserDTO getUser(){ 16 | return UserDTO.builder() 17 | .id(1) 18 | .name("CodeCouple.pl") 19 | .build(); 20 | } 21 | 22 | } 23 | 24 | @Builder 25 | @Data 26 | class UserDTO { 27 | private long id; 28 | private String name; 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | #Application name 2 | spring.application.name=user-service -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/src/test/java/pl/codecouple/producer/BaseClass.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.producer; 2 | 3 | /** 4 | * Created by CodeCouple.pl 5 | */ 6 | 7 | import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc; 8 | import org.junit.Before; 9 | import org.junit.runner.RunWith; 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 | import pl.codecouple.ProducerApplication; 14 | 15 | @RunWith(SpringRunner.class) 16 | @SpringBootTest(classes = ProducerApplication.class) 17 | public abstract class BaseClass { 18 | 19 | @Autowired 20 | UserController userController; 21 | 22 | @Before 23 | public void setUp() throws Exception { 24 | RestAssuredMockMvc.standaloneSetup(userController); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-consumer-driven-contract-example/spring-boot-consumer-driven-contract-producer-example/src/test/resources/contracts/shouldReturnUser.groovy: -------------------------------------------------------------------------------- 1 | package contracts 2 | 3 | import org.springframework.cloud.contract.spec.Contract 4 | 5 | Contract.make { 6 | 7 | description "Should return user" 8 | 9 | request { 10 | method("GET") 11 | url("/") 12 | } 13 | 14 | response { 15 | status 200 16 | body(["id":1, "name": "CodeCouple.pl"]) 17 | headers { 18 | contentType("application/json") 19 | } 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Docker Compose Example 2 | This repository contains Spring Boot Docker Compose example 3 | 4 | To run containers: 5 | ``` 6 | docker-compose up 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | ADD target/consumer-docker.jar consumer-docker.jar 3 | EXPOSE 8082 4 | EXPOSE 8002 5 | ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002", "-jar", "consumer-docker.jar"] -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 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-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | 1.16.6 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | consumer-docker 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/src/main/java/pl/codecouple/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/src/main/java/pl/codecouple/consumer/QueueConsumer.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.consumer; 2 | 3 | import org.springframework.amqp.core.Queue; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * Created by CodeCouple.pl 11 | */ 12 | @Component 13 | class QueueConsumer { 14 | 15 | @Value("${queue.name}") 16 | private String queueName; 17 | 18 | @Bean 19 | public Queue queue() { 20 | return new Queue(queueName, true, false, false, null); 21 | } 22 | 23 | @RabbitListener(queues = "${queue.name}") 24 | private void reader(String text){ 25 | System.out.println("Consumer: " + text); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #RabbitMQ Host 2 | spring.rabbitmq.host=${RABBIT_HOST:192.168.99.100} 3 | spring.rabbitmq.port=5672 4 | spring.rabbitmq.username=guest 5 | spring.rabbitmq.password=guest 6 | #Application Port 7 | server.port=8082 8 | #Queue 9 | queue.name=code.couple.queue 10 | 11 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/consumer/src/test/java/pl/codecouple/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | rabbitmq: 4 | image: rabbitmq:3.6-management-alpine 5 | ports: 6 | - "5672:5672" 7 | - "15672:15672" 8 | producer: 9 | build: ./producer 10 | ports: 11 | - "8081:8081" 12 | - "8001:8001" 13 | links: 14 | - rabbitmq 15 | environment: 16 | RABBIT_HOST: rabbitmq 17 | consumer: 18 | build: ./consumer 19 | ports: 20 | - "8082:8082" 21 | - "8002:8002" 22 | links: 23 | - rabbitmq 24 | environment: 25 | RABBIT_HOST: rabbitmq 26 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | ADD target/producer-docker.jar producer-docker.jar 3 | EXPOSE 8081 4 | EXPOSE 8001 5 | ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8001", "-jar", "producer-docker.jar"] -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 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-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | 1.16.6 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | producer-docker 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/src/main/java/pl/codecouple/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/src/main/java/pl/codecouple/producer/QueueProducer.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.producer; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * Created by CodeCouple.pl 12 | */ 13 | @RestController("/queue") 14 | class QueueProducer { 15 | 16 | @Value("${queue.name}") 17 | private String queueName; 18 | 19 | @Autowired 20 | RabbitTemplate queueSender; 21 | 22 | @GetMapping 23 | String sendToQueue(@RequestParam(value = "message", defaultValue = "CodeCouple.pl") String message){ 24 | queueSender.convertAndSend(queueName, message); 25 | return String.format("Message %s sent! See logs...", message); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #RabbitMQ Host 2 | spring.rabbitmq.host=${RABBIT_HOST:localhost} 3 | spring.rabbitmq.port=5672 4 | spring.rabbitmq.username=guest 5 | spring.rabbitmq.password=guest 6 | #Application Port 7 | server.port=8081 8 | #Queue 9 | queue.name=code.couple.queue -------------------------------------------------------------------------------- /spring-boot-docker-compose-example/producer/src/test/java/pl/codecouple/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/.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-dockerfile-example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre-alpine 2 | ADD target/code-couple-docker.jar code-couple-docker.jar 3 | EXPOSE 8081 4 | ENTRYPOINT ["java", "-jar", "code-couple-docker.jar"] -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Dockerfile 2 | This repository contains Spring Boot Dockerfile example 3 | 4 | To build image: 5 | ``` 6 | docker build -f Dockerfile -t code-couple-docker:latest . 7 | ``` 8 | To run image: 9 | ``` 10 | docker run -p 8081:8081 code-couple-docker 11 | ``` 12 | -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | docker 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | docker 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 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 | code-couple-docker 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/src/main/java/pl/codecouple/DockerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DockerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DockerApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/src/main/java/pl/codecouple/web/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by CodeCouple.pl 9 | */ 10 | @RestController 11 | @RequestMapping("/") 12 | class CodeCoupleController { 13 | 14 | @GetMapping 15 | String getCodeCouple(){ 16 | return "CodeCouple.pl"; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /spring-boot-dockerfile-example/src/test/java/pl/codecouple/DockerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DockerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Eureka Discovery 2 | This repository contains Spring Boot Eureka Discovery example -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-eureka-app-example 2 | spring-boot-eureka-app-example 3 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | spring-boot-eureka-app-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-eureka-app-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/src/main/java/pl/codecouple/SpringBootEurekaAppExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableDiscoveryClient 12 | public class SpringBootEurekaAppExampleApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringBootEurekaAppExampleApplication.class, args); 16 | } 17 | 18 | @Bean 19 | @LoadBalanced 20 | public RestTemplate restTemplate() { 21 | return new RestTemplate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/src/main/java/pl/codecouple/controller/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | /** 8 | * Created by Krzysztof Chruściel. 9 | */ 10 | @RestController 11 | public class CodeCoupleController { 12 | 13 | private final RestTemplate restTemplate; 14 | 15 | public CodeCoupleController(RestTemplate restTemplate) { 16 | this.restTemplate = restTemplate; 17 | } 18 | 19 | @GetMapping("/show") 20 | public String showCodeCoupleRoxx(){ 21 | return restTemplate.getForObject("http://client-example/codecouple", String.class) + " Roxx!"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Server port 2 | server.port=0 3 | #Application name 4 | spring.application.name=app-example 5 | #Default zone 6 | eureka.client.serviceUrl.defaultZone=http://user:password@localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-app-example/src/test/java/pl/codecouple/SpringBootEurekaAppExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SpringBootEurekaAppExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-eureka-client-example 2 | spring-boot-eureka-client-example 3 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | spring-boot-eureka-client-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-eureka-client-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/src/main/java/pl/codecouple/SpringBootEurekaClientExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class SpringBootEurekaClientExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootEurekaClientExampleApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/src/main/java/pl/codecouple/controller/ClientController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by Krzysztof Chruściel. 9 | */ 10 | @RestController 11 | public class ClientController { 12 | 13 | @GetMapping("/codecouple") 14 | public String showCodeCouple() { 15 | return "CodeCouple"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Random server port 2 | server.port=0 3 | #Application name 4 | spring.application.name=client-example 5 | #Default zone 6 | eureka.client.serviceUrl.defaultZone=http://user:password@localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-client-example/src/test/java/pl/codecouple/SpringBootEurekaClientExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SpringBootEurekaClientExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-eureka-server-example 2 | spring-boot-eureka-server-example 3 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | spring-boot-eureka-server-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-eureka-server-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-security 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-dependencies 49 | ${spring-cloud.version} 50 | pom 51 | import 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/src/main/java/pl/codecouple/SpringBootEurekaServerExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class SpringBootEurekaServerExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootEurekaServerExampleApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Conventional Eureka port 2 | server.port=8761 3 | #Application name 4 | spring.application.name=eureka-server 5 | #Server is not registered with eureka 6 | eureka.client.register-with-eureka=false 7 | #Server is not fetching registry 8 | eureka.client.fetch-registry=false 9 | 10 | #Security 11 | security.user.name=user 12 | security.user.password=password -------------------------------------------------------------------------------- /spring-boot-eureka-example/spring-boot-eureka-server-example/src/test/java/pl/codecouple/SpringBootEurekaServerExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SpringBootEurekaServerExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/.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-green-mail-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-green-mail-example 2 | spring-boot-green-mail-example 3 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | green-mail 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | green-mail 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 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-mail 31 | 32 | 33 | com.icegreen 34 | greenmail-spring 35 | 1.5.6 36 | test 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/src/main/java/pl/codecouple/GreenMailApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class GreenMailApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(GreenMailApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/src/main/java/pl/codecouple/email/EmailSender.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.email; 2 | 3 | import org.springframework.mail.SimpleMailMessage; 4 | import org.springframework.mail.javamail.JavaMailSender; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * Created by CodeCouple.pl 9 | */ 10 | @Service 11 | class EmailSender { 12 | 13 | private final JavaMailSender javaMailSender; 14 | 15 | EmailSender(JavaMailSender javaMailSender) { 16 | this.javaMailSender = javaMailSender; 17 | } 18 | 19 | void sendEmail(String to, String from, String title, String content) { 20 | SimpleMailMessage mail = new SimpleMailMessage(); 21 | mail.setTo(to); 22 | mail.setFrom(from); 23 | mail.setSubject(title); 24 | mail.setText(content); 25 | javaMailSender.send(mail); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/src/main/resources/application-email.properties: -------------------------------------------------------------------------------- 1 | spring.mail.host=localhost 2 | spring.mail.port=25 -------------------------------------------------------------------------------- /spring-boot-green-mail-example/src/test/java/pl/codecouple/GreenMailApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 GreenMailApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-green-mail-example/src/test/java/pl/codecouple/email/EmailSenderTest.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.email; 2 | 3 | import com.icegreen.greenmail.junit.GreenMailRule; 4 | import com.icegreen.greenmail.util.GreenMailUtil; 5 | import com.icegreen.greenmail.util.ServerSetup; 6 | import org.junit.Rule; 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.ActiveProfiles; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | 14 | import javax.mail.internet.MimeMessage; 15 | 16 | import static org.assertj.core.api.Java6Assertions.assertThat; 17 | 18 | /** 19 | * Created by CodeCouple.pl 20 | */ 21 | @SpringBootTest 22 | @ActiveProfiles("email") 23 | @RunWith(SpringRunner.class) 24 | public class EmailSenderTest { 25 | 26 | @Rule 27 | public GreenMailRule server = new GreenMailRule(new ServerSetup(25, "localhost", "smtp")); 28 | 29 | @Autowired 30 | EmailSender emailSender; 31 | 32 | 33 | @Test 34 | public void shouldSendEmail() throws Exception { 35 | // Given 36 | String to = "test@codecouple.pl"; 37 | String from = "blog@codecouple.pl"; 38 | String title = "Title"; 39 | String content = "Content"; 40 | // When 41 | emailSender.sendEmail(to, from, title, content); 42 | // Then 43 | MimeMessage[] receivedMessages = server.getReceivedMessages(); 44 | assertThat(receivedMessages.length).isEqualTo(1); 45 | 46 | MimeMessage receivedMessage = receivedMessages[0]; 47 | assertThat(receivedMessage.getAllRecipients()[0].toString()).isEqualTo(to); //to 48 | assertThat(receivedMessage.getFrom()[0].toString()).isEqualTo(from); //from 49 | assertThat(receivedMessage.getSubject()).isEqualTo(title); //title 50 | assertThat(receivedMessage.getContent().toString()).contains(content); //content 51 | //Or 52 | assertThat(content).isEqualTo(GreenMailUtil.getBody(server.getReceivedMessages()[0])); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/.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-hystrix-dashboard-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Hystrix Dashboard 2 | This repository contains Spring Boot Hystrix Dashboard example -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | hystrix-dashboard-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | hystrix-dashboard-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-hystrix 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-hystrix-dashboard 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-web 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/src/main/java/pl/codecouple/HystrixDashboardExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 7 | 8 | @SpringBootApplication 9 | @EnableCircuitBreaker 10 | @EnableHystrixDashboard 11 | public class HystrixDashboardExampleApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(HystrixDashboardExampleApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/src/main/java/pl/codecouple/web/RandomController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.util.Random; 8 | 9 | /** 10 | * Created by CodeCouple.pl 11 | */ 12 | @RestController 13 | class RandomController { 14 | 15 | @GetMapping("/") 16 | @HystrixCommand(fallbackMethod = "fallback") 17 | String getRandomNumber() throws InterruptedException { 18 | int result = new Random().nextInt(10); 19 | if (result > 5) { 20 | throw new RuntimeException("¯\\_(ツ)_/¯"); 21 | } 22 | return String.format("The number is {%d}", result); 23 | } 24 | 25 | String fallback(){ 26 | return "Hystrix is working!"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kchrusciel/Spring-Boot-Examples/b853eabf23a53ad0329fcbe44f30b17fc8568611/spring-boot-hystrix-dashboard-example/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-hystrix-dashboard-example/src/test/java/pl/codecouple/HystrixDashboardExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 HystrixDashboardExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-example/.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-hystrix-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Hystrix 2 | This repository contains Spring Boot Hystrix example -------------------------------------------------------------------------------- /spring-boot-hystrix-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | hystrix-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | hystrix-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-hystrix 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-actuator 40 | 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | true 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.cloud 58 | spring-cloud-dependencies 59 | ${spring-cloud.version} 60 | pom 61 | import 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /spring-boot-hystrix-example/src/main/java/pl/codecouple/HystrixExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | 7 | @SpringBootApplication 8 | @EnableCircuitBreaker 9 | public class HystrixExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(HystrixExampleApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-hystrix-example/src/main/java/pl/codecouple/web/RandomController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.util.Random; 8 | 9 | /** 10 | * Created by CodeCouple.pl 11 | */ 12 | @RestController 13 | class RandomController { 14 | 15 | @GetMapping("/") 16 | @HystrixCommand(fallbackMethod = "fallback") 17 | String getRandomNumber() throws InterruptedException { 18 | int result = new Random().nextInt(10); 19 | if (result > 5) { 20 | throw new RuntimeException("¯\\_(ツ)_/¯"); 21 | } 22 | return String.format("The number is {%d}", result); 23 | } 24 | 25 | String fallback(){ 26 | return "Hystrix is working!"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-hystrix-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kchrusciel/Spring-Boot-Examples/b853eabf23a53ad0329fcbe44f30b17fc8568611/spring-boot-hystrix-example/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-hystrix-example/src/test/java/pl/codecouple/HystrixExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 HystrixExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Turbine 2 | This repository contains Spring Boot Turbine example -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/.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-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Turbine 2 | This repository contains Spring Boot Turbine example -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | turbine-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | turbine-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-hystrix 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-hystrix-dashboard 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-turbine 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/src/main/java/pl/codecouple/TurbineServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 7 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 8 | 9 | @SpringBootApplication 10 | @EnableTurbine 11 | @EnableEurekaClient 12 | @EnableHystrixDashboard 13 | public class TurbineServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(TurbineServiceApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8989 2 | spring.application.name=turbine-dashboard 3 | eureka.client.service-url.defaultZone=http://localhost:8761/eureka 4 | turbine.app-config=first-service,second-service 5 | turbine.cluster-name-expression=new String("default") -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-app-example/src/test/java/pl/codecouple/TurbineServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 TurbineServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/.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-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Turbine - Discovery Service 2 | This repository contains Spring Boot Turbine example -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | discovery-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | discovery-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-eureka-server 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/src/main/java/pl/codecouple/DiscoveryServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8761 -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-discovery-example/src/test/java/pl/codecouple/DiscoveryServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DiscoveryServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/.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-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Turbine - First Service 2 | This repository contains Spring Boot Turbine example -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | first-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | first-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-hystrix 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-hystrix-dashboard 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-web 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.cloud 61 | spring-cloud-dependencies 62 | ${spring-cloud.version} 63 | pom 64 | import 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/src/main/java/pl/codecouple/FirstServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | 9 | @SpringBootApplication 10 | @EnableCircuitBreaker 11 | @EnableHystrixDashboard 12 | @EnableEurekaClient 13 | public class FirstServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(FirstServiceApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/src/main/java/pl/codecouple/rest/HystrixController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.rest; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.apache.commons.lang.math.RandomUtils; 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 | /** 10 | * Created by CodeCouple.pl 11 | */ 12 | @RestController 13 | @RequestMapping("/") 14 | public class HystrixController { 15 | 16 | @HystrixCommand(fallbackMethod = "fallback") 17 | @GetMapping 18 | String hystrixMethod(){ 19 | if (RandomUtils.nextInt(10) > 5) { 20 | return "Bingo!"; 21 | } 22 | throw new RuntimeException(); 23 | } 24 | 25 | String fallback(){ 26 | return "Fallback"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | spring.application.name=first-service 3 | eureka.client.service-url.defaultZone=http://localhost:8761/eureka -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-first-app-example/src/test/java/pl/codecouple/FirstServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 FirstServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/.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-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Turbine - Second Service 2 | This repository contains Spring Boot Turbine example -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | second-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | second-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR4 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-eureka 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-hystrix 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-hystrix-dashboard 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-web 48 | 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.cloud 61 | spring-cloud-dependencies 62 | ${spring-cloud.version} 63 | pom 64 | import 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/src/main/java/pl/codecouple/SecondServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | 9 | @SpringBootApplication 10 | @EnableCircuitBreaker 11 | @EnableHystrixDashboard 12 | @EnableEurekaClient 13 | public class SecondServiceApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(SecondServiceApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/src/main/java/pl/codecouple/rest/HystrixSecondController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.rest; 2 | 3 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 4 | import org.apache.commons.lang.math.RandomUtils; 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 | /** 10 | * Created by CodeCouple.pl 11 | */ 12 | @RestController 13 | @RequestMapping("/") 14 | public class HystrixSecondController { 15 | 16 | @HystrixCommand(fallbackMethod = "fallback") 17 | @GetMapping 18 | String hystrixSecondMethod(){ 19 | if (RandomUtils.nextInt(10) > 5) { 20 | return "Bingo!"; 21 | } 22 | throw new RuntimeException(); 23 | } 24 | 25 | String fallback(){ 26 | return "Fallback"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | spring.application.name=second-service 3 | eureka.client.service-url.defaultZone=http://localhost:8761/eureka -------------------------------------------------------------------------------- /spring-boot-hystrix-turbine-example/spring-boot-hystrix-turbine-second-app-example/src/test/java/pl/codecouple/SecondServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SecondServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-properties-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-properties-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Properties 2 | This repository contains Spring Boot Properties example -------------------------------------------------------------------------------- /spring-boot-properties-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple.properties 7 | properties 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | properties 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.2.RELEASE 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 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-test 35 | test 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-configuration-processor 40 | true 41 | 42 | 43 | org.hibernate 44 | hibernate-validator 45 | 5.3.4.Final 46 | 47 | 48 | org.projectlombok 49 | lombok 50 | 1.16.12 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /spring-boot-properties-example/src/main/java/pl/codecouple/properties/PropertiesApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.properties; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.CommandLineRunner; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 8 | import pl.codecouple.properties.custom.CustomProperties; 9 | 10 | @SpringBootApplication 11 | @EnableConfigurationProperties(CustomProperties.class) 12 | public class PropertiesApplication implements CommandLineRunner{ 13 | 14 | @Autowired 15 | CustomProperties customProperties; 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(PropertiesApplication.class, args); 19 | 20 | } 21 | 22 | @Override 23 | public void run(String... strings) throws Exception { 24 | System.out.println(customProperties); 25 | System.out.println(customProperties.getPathMapper().get("first")); 26 | System.out.println(customProperties.getPathMapper().get("second")); 27 | System.out.println(customProperties.getPathMapper().get("third")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-properties-example/src/main/java/pl/codecouple/properties/custom/CustomProperties.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.properties.custom; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.NotEmpty; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; 7 | import org.springframework.validation.annotation.Validated; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * Created by Krzysztof Chruściel. 13 | */ 14 | @Data 15 | @ConfigurationProperties(prefix="custom") 16 | @Validated 17 | public class CustomProperties { 18 | 19 | /** Property value. */ 20 | @NotEmpty 21 | private String property; 22 | 23 | /** Map example. */ 24 | private Map pathMapper; 25 | 26 | /** Connection propeties. */ 27 | private Connection connection; 28 | 29 | @Data 30 | public static class Connection { 31 | 32 | /** Connection port. */ 33 | private int port = 8080; 34 | /** Connection address. */ 35 | private String address = "localhost"; 36 | /** This value is deprecated. */ 37 | private String server; 38 | 39 | @DeprecatedConfigurationProperty(replacement = "custom.connection.address") 40 | @Deprecated 41 | public String getServer() { 42 | return getAddress(); 43 | } 44 | 45 | @Deprecated 46 | public void setServer(String server){ 47 | setAddress(server); 48 | } 49 | 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-properties-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kchrusciel/Spring-Boot-Examples/b853eabf23a53ad0329fcbe44f30b17fc8568611/spring-boot-properties-example/src/main/resources/application.properties -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/.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-rabbitmq-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot RabbitMQ integration example 2 | This repository contains Spring Boot RabbitMQ integration example -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 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-amqp 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | 1.16.6 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/src/main/java/pl/codecouple/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/src/main/java/pl/codecouple/consumer/QueueConsumer.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.consumer; 2 | 3 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 4 | import org.springframework.stereotype.Component; 5 | 6 | /** 7 | * Created by CodeCouple.pl 8 | */ 9 | @Component 10 | class QueueConsumer { 11 | 12 | @RabbitListener(queues = "${queue.name}") 13 | private void reader(String text){ 14 | System.out.println("Consumer: " + text); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/src/main/java/pl/codecouple/producer/QueueProducer.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.producer; 2 | 3 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * Created by CodeCouple.pl 12 | */ 13 | @RestController("/queue") 14 | class QueueProducer { 15 | 16 | @Value("${queue.name}") 17 | private String queueName; 18 | 19 | @Autowired 20 | RabbitTemplate queueSender; 21 | 22 | @GetMapping 23 | String sendToQueue(@RequestParam(value = "message", defaultValue = "CodeCouple.pl") String message){ 24 | queueSender.convertAndSend(queueName, message); 25 | return String.format("Message %s sent! See logs...", message); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #RabbitMQ Host 2 | spring.rabbitmq.host=192.168.99.100 3 | spring.rabbitmq.port=5672 4 | spring.rabbitmq.username=guest 5 | spring.rabbitmq.password=guest 6 | #Application Port 7 | server.port=8081 8 | #Queue 9 | queue.name=code.couple.queue -------------------------------------------------------------------------------- /spring-boot-rabbitmq-example/src/test/java/pl/codecouple/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Resource Server 2 | This repository contains Spring Boot Resource Server example -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/.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-resource-server-example/spring-boot-resource-server-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Resource Server 2 | This repository contains Spring Boot Resource Server example -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | resource-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | resource-server 12 | Resource server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/src/main/java/pl/codecouple/ResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 | 7 | @SpringBootApplication 8 | @EnableResourceServer 9 | public class ResourceServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ResourceServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/src/main/java/pl/codecouple/web/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * Created by CodeCouple.pl 8 | */ 9 | @RestController 10 | class CodeCoupleController { 11 | 12 | @GetMapping("/not-for-all") 13 | String showCodeCouple(){ 14 | return "Code Couple!"; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #User info endpoint 2 | security.oauth2.resource.user-info-uri=https://api.github.com/user 3 | #Prefer user info 4 | security.oauth2.resource.prefer-token-info=false -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-resource-server-example/src/test/java/pl/codecouple/ResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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-resource-server-example/spring-boot-sso-example/.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-resource-server-example/spring-boot-sso-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Single Sign-On 2 | This repository contains Spring Boot Single Sign-On example -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | sso 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | sso 12 | Single Sign-On 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/src/main/java/pl/codecouple/SsoApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SsoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SsoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/src/main/java/pl/codecouple/configuration/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.configuration; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @Configuration 12 | @EnableOAuth2Sso 13 | class WebSecurityConfig extends WebSecurityConfigurerAdapter { 14 | 15 | @Override 16 | protected void configure(HttpSecurity http) throws Exception { 17 | http.authorizeRequests() 18 | .antMatchers("/for-all") 19 | .permitAll() 20 | .anyRequest() 21 | .authenticated(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/src/main/java/pl/codecouple/web/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.security.oauth2.client.OAuth2ClientContext; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by CodeCouple.pl 9 | */ 10 | @RestController 11 | class CodeCoupleController { 12 | 13 | private final OAuth2ClientContext clientContext; 14 | 15 | CodeCoupleController(OAuth2ClientContext clientContext) { 16 | this.clientContext = clientContext; 17 | } 18 | 19 | @GetMapping("/for-all") 20 | String showCodeCouple(){ 21 | return "Code Couple!"; 22 | } 23 | 24 | @GetMapping("/not-for-all") 25 | String showCodeCoupleAwesome(){ 26 | return "Code Couple is awesome!"; 27 | } 28 | 29 | @GetMapping("/token") 30 | String showToken() { 31 | return clientContext.getAccessToken().getValue(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Application name 2 | spring.application.name=auth-service 3 | #Server port 4 | server.port=9191 5 | 6 | #Client id from GitHub 7 | security.oauth2.client.client-id=generated-id 8 | #Client secret from GitHub 9 | security.oauth2.client.client-secret=generated-secret 10 | #URI with access token 11 | security.oauth2.client.access-token-uri=https://github.com/login/oauth/access_token 12 | #URI for authorization 13 | security.oauth2.client.user-authorization-uri=https://github.com/login/oauth/authorize 14 | #Scheme of authentication 15 | security.oauth2.client.client-authentication-scheme=form 16 | 17 | #User info endpoint 18 | security.oauth2.resource.user-info-uri=https://api.github.com/user 19 | #Prefer user info 20 | security.oauth2.resource.prefer-token-info=false -------------------------------------------------------------------------------- /spring-boot-resource-server-example/spring-boot-sso-example/src/test/java/pl/codecouple/SsoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SsoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot REST Docs 2 | This repository contains Spring Boot REST Docs example -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/main/documentation/asciidoc/todos-manual.adoc: -------------------------------------------------------------------------------- 1 | = Todos API Reference 2 | CodeCouple.pl - Version 1.0.1; 3 | :doctype: book 4 | :icons: font 5 | :source-highlighter: highlightjs 6 | :toc: left 7 | :toclevels: 4 8 | :sectlinks: 9 | 10 | 11 | [[headers]] 12 | == Headers 13 | 14 | Curl-request in CodeCouple.pl: 15 | 16 | include::{snippets}/todos/curl-request.adoc[] 17 | include::{snippets}/todos/http-request.adoc[] 18 | include::{snippets}/todos/http-response.adoc[] 19 | 20 | include::{snippets}/todos/response-fields.adoc[] 21 | include::{snippets}/todos/request-parameters.adoc[] -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/main/java/pl/codecouple/DocumentationApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DocumentationApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DocumentationApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/main/java/pl/codecouple/todos/Todo.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.todos; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | 9 | /** 10 | * Created by Krzysztof Chruściel. 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | public class Todo { 15 | 16 | @Id 17 | @GeneratedValue 18 | private Long id; 19 | 20 | private String title; 21 | private String description; 22 | 23 | } -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/main/java/pl/codecouple/todos/TodoController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.todos; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.*; 5 | 6 | /** 7 | * Created by Krzysztof Chruściel. 8 | */ 9 | @RestController 10 | @RequestMapping("/todos") 11 | class TodoController { 12 | 13 | @GetMapping 14 | @ResponseStatus(value = HttpStatus.OK) 15 | Todo getTodoByTitle(@RequestParam(value = "title", required = true) String title){ 16 | return new Todo(1l, "TDD", "Description"); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /spring-boot-rest-docs-example/src/test/java/pl/codecouple/TodoDocumentation.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.junit.Before; 4 | import org.junit.Rule; 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.context.SpringBootTest; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.restdocs.JUnitRestDocumentation; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 14 | import org.springframework.web.context.WebApplicationContext; 15 | 16 | import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; 17 | import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; 18 | import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; 19 | import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; 20 | import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; 21 | import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; 22 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 23 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 24 | 25 | @RunWith(SpringRunner.class) 26 | @SpringBootTest 27 | public class TodoDocumentation { 28 | 29 | @Rule 30 | public JUnitRestDocumentation documentation = new JUnitRestDocumentation("target/generated-snippets"); 31 | 32 | @Autowired 33 | private WebApplicationContext context; 34 | 35 | private MockMvc mockMvc; 36 | 37 | @Before 38 | public void setUp() { 39 | this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) 40 | .apply(documentationConfiguration(this.documentation)) 41 | .build(); 42 | } 43 | 44 | @Test 45 | public void shouldReturnTodo() throws Exception { 46 | this.mockMvc.perform( 47 | get("/todos") 48 | .param("title", "TDD") 49 | .accept(MediaType.APPLICATION_JSON)) 50 | .andExpect(status().isOk()) 51 | .andDo(document("todos", 52 | responseFields( 53 | fieldWithPath("id").description("Todo ID"), 54 | fieldWithPath("title").description("Todo title"), 55 | fieldWithPath("description").description("Todo description")), 56 | requestParameters( 57 | parameterWithName("title").description("Todo title")))); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /spring-boot-sso-example/.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-sso-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Single Sign-On 2 | This repository contains Spring Boot Single Sign-On example -------------------------------------------------------------------------------- /spring-boot-sso-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | sso 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | sso 12 | Single Sign-On 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-oauth2 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-sso-example/src/main/java/pl/codecouple/SsoApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SsoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SsoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-sso-example/src/main/java/pl/codecouple/configuration/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.configuration; 2 | 3 | import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @Configuration 12 | @EnableOAuth2Sso 13 | class WebSecurityConfig extends WebSecurityConfigurerAdapter { 14 | 15 | @Override 16 | protected void configure(HttpSecurity http) throws Exception { 17 | http.authorizeRequests() 18 | .antMatchers("/for-all") 19 | .permitAll() 20 | .anyRequest() 21 | .authenticated(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-sso-example/src/main/java/pl/codecouple/web/CodeCoupleController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * Created by CodeCouple.pl 8 | */ 9 | @RestController 10 | class CodeCoupleController { 11 | 12 | @GetMapping("/for-all") 13 | String showCodeCouple(){ 14 | return "Code Couple!"; 15 | } 16 | 17 | @GetMapping("/not-for-all") 18 | String showCodeCoupleAwesome(){ 19 | return "Code Couple is awesome!"; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-sso-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Application name 2 | spring.application.name=auth-service 3 | #Server port 4 | server.port=9191 5 | 6 | #Client id from GitHub 7 | security.oauth2.client.client-id=generated-id 8 | #Client secret from GitHub 9 | security.oauth2.client.client-secret=generated-secret 10 | #URI with access token 11 | security.oauth2.client.access-token-uri=https://github.com/login/oauth/access_token 12 | #URI for authorization 13 | security.oauth2.client.user-authorization-uri=https://github.com/login/oauth/authorize 14 | #Scheme of authentication 15 | security.oauth2.client.client-authentication-scheme=form 16 | 17 | #User info endpoint 18 | security.oauth2.resource.user-info-uri=https://api.github.com/user 19 | #Prefer user info 20 | security.oauth2.resource.prefer-token-info=false -------------------------------------------------------------------------------- /spring-boot-sso-example/src/test/java/pl/codecouple/SsoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SsoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-update-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-update-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-update-example 2 | Spring Boot example of POST, PUT and PATCH methods. 3 | -------------------------------------------------------------------------------- /spring-boot-update-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple.update 7 | update-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | update-example 12 | Example of POST, PUT and PATCH method 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.3.RELEASE 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-data-jpa 36 | 37 | 38 | com.h2database 39 | h2 40 | 1.4.192 41 | 42 | 43 | org.projectlombok 44 | lombok 45 | true 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | org.projectlombok 54 | lombok 55 | 1.16.12 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/UpdateExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class UpdateExampleApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(UpdateExampleApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/todo/Todo.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import org.springframework.util.Assert; 6 | 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.Id; 10 | 11 | /** 12 | * Created by Krzysztof Chruściel. 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @Entity 17 | public class Todo { 18 | 19 | @Id 20 | @GeneratedValue 21 | private Long id; 22 | 23 | private String title; 24 | 25 | private String description; 26 | 27 | public Todo(String title, String description) { 28 | Assert.notNull(title, "Title cannot be null!"); 29 | Assert.hasLength(title, "Title cannot be empty!"); 30 | Assert.notNull(description, "Description cannot be null!"); 31 | Assert.hasLength(description, "Description cannot be empty!"); 32 | this.title = title; 33 | this.description = description; 34 | } 35 | 36 | 37 | public Todo(Long id, String title, String description) { 38 | Assert.notNull(title, "Title cannot be null!"); 39 | Assert.hasLength(title, "Title cannot be empty!"); 40 | Assert.notNull(description, "Description cannot be null!"); 41 | Assert.hasLength(description, "Description cannot be empty!"); 42 | Assert.notNull(id, "ID cannot be null!"); 43 | this.id = id; 44 | this.title = title; 45 | this.description = description; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/todo/TodoController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import java.net.URI; 8 | import java.util.Map; 9 | 10 | /** 11 | * Created by Krzysztof Chruściel. 12 | */ 13 | @RestController 14 | @RequestMapping("/todos") 15 | public class TodoController { 16 | 17 | private final TodoService todoService; 18 | 19 | public TodoController(TodoService todoService) { 20 | this.todoService = todoService; 21 | } 22 | 23 | @PostMapping 24 | @ResponseStatus(value = HttpStatus.CREATED, reason = "Todo created!") 25 | public void addNewTodo(@RequestBody Todo todo){ 26 | todoService.addNewTodo(todo); 27 | } 28 | 29 | @PutMapping("/{id}") 30 | public ResponseEntity updateTodo(@RequestBody Todo todo, @PathVariable Long id) throws TodoNotFound { 31 | Todo todoById = todoService.getTodoById(id); 32 | if(todoById == null){ 33 | todoService.addNewTodo(todo); 34 | return ResponseEntity.created(URI.create(String.format("/todos/%d", id))).build(); 35 | } 36 | todoService.update(todo); 37 | return ResponseEntity.noContent().build(); 38 | } 39 | 40 | @PatchMapping("/{id}") 41 | @ResponseStatus(value = HttpStatus.NO_CONTENT, reason = "Todo partial updated!") 42 | public void updateTodo(@RequestBody Map updates, @PathVariable Long id) throws TodoNotFound { 43 | Todo todo = todoService.getTodoById(id); 44 | if (todo == null) { 45 | throw new TodoNotFound(String.format("Todo with ID %d not exists!", id)); 46 | } 47 | partialUpdate(todo, updates); 48 | } 49 | 50 | private void partialUpdate(Todo todo, Map updates) { 51 | if (updates.containsKey("title")) { 52 | todo.setTitle((String) updates.get("title")); 53 | } 54 | if (updates.containsKey("description")) { 55 | todo.setDescription((String) updates.get("description")); 56 | } 57 | todoService.partialUpdated(todo); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/todo/TodoNotFound.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | /** 7 | * Created by Krzysztof Chruściel. 8 | */ 9 | @ResponseStatus(HttpStatus.NOT_FOUND) 10 | public class TodoNotFound extends Exception { 11 | 12 | public TodoNotFound() { 13 | super("Todo not found!"); 14 | } 15 | 16 | public TodoNotFound(String message) { 17 | super(message); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/todo/TodoRepository.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | /** 7 | * Created by Krzysztof Chruściel. 8 | */ 9 | @Repository 10 | public interface TodoRepository extends JpaRepository{ 11 | } 12 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/java/pl/codecouple/update/todo/TodoService.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * Created by Krzysztof Chruściel. 7 | */ 8 | @Service 9 | public class TodoService { 10 | 11 | 12 | private final TodoRepository todoRepository; 13 | 14 | public TodoService(TodoRepository todoRepository) { 15 | this.todoRepository = todoRepository; 16 | } 17 | 18 | 19 | public void addNewTodo(Todo todo) { 20 | todoRepository.save(todo); 21 | } 22 | 23 | public void update(Todo todo) { 24 | todoRepository.save(todo); 25 | } 26 | 27 | public Todo getTodoById(Long id){ 28 | return todoRepository.findOne(id); 29 | } 30 | 31 | public void partialUpdated(Todo todo) { 32 | todoRepository.save(todo); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #SERVER 2 | server.port=8081 -------------------------------------------------------------------------------- /spring-boot-update-example/src/test/java/pl/codecouple/update/UpdateExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 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.jdbc.AutoConfigureTestDatabase; 8 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | import org.springframework.test.web.servlet.MockMvc; 13 | import org.springframework.test.web.servlet.ResultActions; 14 | import pl.codecouple.update.todo.Todo; 15 | import pl.codecouple.update.todo.TodoService; 16 | 17 | import java.util.HashMap; 18 | 19 | import static org.assertj.core.api.Assertions.assertThat; 20 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; 21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | @AutoConfigureMockMvc 26 | @AutoConfigureTestDatabase 27 | public class UpdateExampleApplicationTests { 28 | 29 | private final ObjectMapper objectMapper = new ObjectMapper(); 30 | 31 | @Autowired 32 | private MockMvc mvc; 33 | 34 | @Autowired 35 | private TodoService todoService; 36 | 37 | 38 | @Test 39 | public void shouldPartialUpdateTodo() throws Exception { 40 | // Given 41 | todoService.addNewTodo(new Todo("title", "description")); 42 | 43 | HashMap updates = new HashMap<>(); 44 | updates.put("title", "new title"); 45 | updates.put("description", "new description"); 46 | 47 | // When 48 | ResultActions result = this.mvc.perform(patch("/todos/1") 49 | .contentType(MediaType.APPLICATION_JSON_UTF8) 50 | .content(objectMapper.writeValueAsString(updates))); 51 | 52 | Todo todoResult = todoService.getTodoById(1L); 53 | 54 | // Then 55 | result.andExpect(status().isNoContent()) 56 | .andExpect(status().reason("Todo partial updated!")); 57 | 58 | assertThat(todoResult).isNotNull(); 59 | assertThat(todoResult.getTitle()).isEqualTo("new title"); 60 | assertThat(todoResult.getDescription()).isEqualTo("new description"); 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/test/java/pl/codecouple/update/todo/TodoRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 7 | import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | import static org.assertj.core.api.Assertions.assertThat; 11 | 12 | /** 13 | * Created by Krzysztof Chruściel. 14 | */ 15 | @RunWith(SpringRunner.class) 16 | @DataJpaTest 17 | public class TodoRepositoryTest { 18 | 19 | @Autowired 20 | TodoRepository todoRepository; 21 | 22 | @Autowired 23 | TestEntityManager testEntityManager; 24 | 25 | @Test 26 | public void shouldSaveTodo() throws Exception { 27 | // Given 28 | Todo todo = new Todo(1L, "title", "description"); 29 | // When 30 | todoRepository.save(todo); 31 | Long result = testEntityManager.getId(todo, Long.class); 32 | // Then 33 | assertThat(result).isNotNull(); 34 | assertThat(result).isEqualTo(1L); 35 | } 36 | 37 | @Test 38 | public void shouldFindTodoByID() throws Exception { 39 | // Given 40 | Todo todo = new Todo("title", "description"); 41 | testEntityManager.persist(todo); 42 | // When 43 | Todo result = todoRepository.findOne(1L); 44 | // Then 45 | assertThat(result).isNotNull(); 46 | assertThat(result.getTitle()).isEqualTo("title"); 47 | assertThat(result.getDescription()).isEqualTo("description"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-update-example/src/test/java/pl/codecouple/update/todo/TodoTest.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.update.todo; 2 | 3 | import org.junit.Rule; 4 | import org.junit.Test; 5 | import org.junit.rules.ExpectedException; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | /** 10 | * Created by Krzysztof Chruściel. 11 | */ 12 | public class TodoTest { 13 | 14 | @Rule 15 | public ExpectedException thrown = ExpectedException.none(); 16 | 17 | @Test 18 | public void shouldThrowExceptionWhenTitleIsNull() throws Exception { 19 | // Given 20 | this.thrown.expect(IllegalArgumentException.class); 21 | this.thrown.expectMessage("Title cannot be null!"); 22 | // When 23 | new Todo(null, "description"); 24 | } 25 | 26 | @Test 27 | public void shouldThrowExceptionWhenTitleIsEmpty() throws Exception { 28 | // Given 29 | this.thrown.expect(IllegalArgumentException.class); 30 | this.thrown.expectMessage("Title cannot be empty!"); 31 | // When 32 | new Todo("", "description"); 33 | } 34 | 35 | @Test 36 | public void shouldThrowExceptionWhenDescriptionIsNull() throws Exception { 37 | // Given 38 | this.thrown.expect(IllegalArgumentException.class); 39 | this.thrown.expectMessage("Description cannot be null!"); 40 | // When 41 | new Todo("title", null); 42 | } 43 | 44 | @Test 45 | public void shouldThrowExceptionWhenDescriptionIsEmpty() throws Exception { 46 | // Given 47 | this.thrown.expect(IllegalArgumentException.class); 48 | this.thrown.expectMessage("Description cannot be empty!"); 49 | // When 50 | new Todo("title", ""); 51 | } 52 | 53 | @Test 54 | public void shouldCreateNewTodo() throws Exception { 55 | // When 56 | Todo result = new Todo("title", "description"); 57 | // Then 58 | assertThat(result).isNotNull(); 59 | assertThat(result.getTitle()).isEqualTo("title"); 60 | assertThat(result.getDescription()).isEqualTo("description"); 61 | } 62 | 63 | @Test 64 | public void shouldThrowExceptionWhenIDIsNull() throws Exception { 65 | // Given 66 | this.thrown.expect(IllegalArgumentException.class); 67 | this.thrown.expectMessage("ID cannot be null!"); 68 | // When 69 | Todo result = new Todo(null, "title", "description"); 70 | } 71 | 72 | @Test 73 | public void shouldCreteNewTodoWithID() throws Exception { 74 | // When 75 | Todo result = new Todo(1L, "title", "description"); 76 | // Then 77 | assertThat(result).isNotNull(); 78 | assertThat(result.getId()).isEqualTo(1L); 79 | assertThat(result.getTitle()).isEqualTo("title"); 80 | assertThat(result.getDescription()).isEqualTo("description"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Zipkin 2 | This repository contains Spring Boot Zipkin example -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-zipkin-client-example 2 | spring-boot-zipkin-client-example 3 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | spring-boot-zipkin-client-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-zipkin-client-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-zipkin 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-starter-eureka 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-dependencies 53 | ${spring-cloud.version} 54 | pom 55 | import 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/src/main/java/pl/codecouple/ClientController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | /** 11 | * Created by Krzysztof Chruściel. 12 | */ 13 | @RestController 14 | public class ClientController { 15 | 16 | private static final Logger LOG = Logger.getLogger(ClientController.class.getName()); 17 | 18 | @Autowired 19 | private RestTemplate restTemplate; 20 | 21 | @Bean 22 | public RestTemplate getRestTemplate() { 23 | return new RestTemplate(); 24 | } 25 | 26 | @GetMapping("/hello") 27 | String sayHello(){ 28 | LOG.info("Hello from Client!"); 29 | return restTemplate.getForEntity("http://localhost:8081/world", String.class).getBody(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/src/main/java/pl/codecouple/SpringBootZipkinClientExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class SpringBootZipkinClientExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootZipkinClientExampleApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zipkin-client 2 | server.port=8082 3 | spring.sleuth.sampler.percentage=1.0 -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-client-example/src/test/java/pl/codecouple/SpringBootZipkinClientExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SpringBootZipkinClientExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-zipkin-server-example 2 | spring-boot-zipkin-server-example 3 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | tracing-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | zipkin-server 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-eureka 36 | 37 | 38 | io.zipkin.java 39 | zipkin-server 40 | 41 | 42 | io.zipkin.java 43 | zipkin-autoconfigure-ui 44 | LATEST 45 | runtime 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.cloud 58 | spring-cloud-dependencies 59 | ${spring-cloud.version} 60 | pom 61 | import 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/src/main/java/pl/codecouple/TracingServerApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import zipkin.server.EnableZipkinServer; 7 | 8 | @SpringBootApplication 9 | @EnableZipkinServer 10 | @EnableDiscoveryClient 11 | public class TracingServerApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(TracingServerApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zipkin-server 2 | server.port=9411 3 | spring.zipkin.locator.discovery.enabled: true -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-server-example/src/test/java/pl/codecouple/TracingServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 TracingServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Krzysztof Chruściel 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 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-zipkin-service-example 2 | spring-boot-zipkin-service-example 3 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | spring-boot-zipkin-service-example 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-zipkin-service-example 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.4.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Dalston.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-zipkin 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-starter-eureka 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-dependencies 53 | ${spring-cloud.version} 54 | pom 55 | import 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/src/main/java/pl/codecouple/ServiceController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.apache.log4j.Logger; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by Krzysztof Chruściel. 9 | */ 10 | @RestController 11 | public class ServiceController { 12 | 13 | private static final Logger LOG = Logger.getLogger(ServiceController.class.getName()); 14 | 15 | @GetMapping("/world") 16 | String sayWorld(){ 17 | LOG.info("Hello from Service!"); 18 | return "World"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/src/main/java/pl/codecouple/SpringBootZipkinServiceExampleApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class SpringBootZipkinServiceExampleApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SpringBootZipkinServiceExampleApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=zipkin-service 2 | server.port=8081 -------------------------------------------------------------------------------- /spring-boot-zipkin-example/spring-boot-zipkin-service-example/src/test/java/pl/codecouple/SpringBootZipkinServiceExampleApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SpringBootZipkinServiceExampleApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot Zuul Example 2 | This repository contains Spring Boot Zuul example 3 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-eureka-service-example/.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-zuul-example/spring-boot-zuul-eureka-service-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | discovery-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | discovery-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka-server 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-eureka-service-example/src/main/java/pl/codecouple/DiscoveryServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class DiscoveryServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DiscoveryServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-eureka-service-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Conventional Eureka port 2 | server.port=8761 3 | #Application name 4 | spring.application.name=discovery-service 5 | #Server is not registered with eureka 6 | eureka.client.register-with-eureka=false 7 | #Server is not fetching registry 8 | eureka.client.fetch-registry=false -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-eureka-service-example/src/test/java/pl/codecouple/DiscoveryServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 DiscoveryServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-first-service-example/.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-zuul-example/spring-boot-zuul-first-service-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | first-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | first-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-first-service-example/src/main/java/pl/codecouple/FirstServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class FirstServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(FirstServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-first-service-example/src/main/java/pl/codecouple/web/FirstController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * Created by CodeCouple.pl 10 | */ 11 | @RestController 12 | public class FirstController { 13 | 14 | @GetMapping("/codecouple") 15 | public String showCodeCouple(HttpServletRequest request) { 16 | return "CodeCouple first service!"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-first-service-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Random server port 2 | server.port=0 3 | #Application name 4 | spring.application.name=first-service 5 | #Default zone 6 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-second-service-example/.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-zuul-example/spring-boot-zuul-second-service-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | second-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | second-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-second-service-example/src/main/java/pl/codecouple/SecondServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class SecondServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(SecondServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-second-service-example/src/main/java/pl/codecouple/web/SecondController.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.web; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * Created by CodeCouple.pl 8 | */ 9 | @RestController 10 | public class SecondController { 11 | 12 | @GetMapping("/codecouple") 13 | public String showCodeCouple() { 14 | return "CodeCouple second service!"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-second-service-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Random server port 2 | server.port=0 3 | #Application name 4 | spring.application.name=second-service 5 | #Default zone 6 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-second-service-example/src/test/java/pl/codecouple/SecondServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 SecondServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-service-example/.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-zuul-example/spring-boot-zuul-service-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | pl.codecouple 7 | zuul-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | zuul-service 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.9.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Edgware.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-eureka 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-zuul 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-service-example/src/main/java/pl/codecouple/ZuulServiceApplication.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableZuulProxy 11 | public class ZuulServiceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ZuulServiceApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-service-example/src/main/java/pl/codecouple/filters/CustomFilter.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple.filters; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import org.springframework.stereotype.Component; 6 | 7 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER; 8 | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE; 9 | 10 | /** 11 | * Created by CodeCouple.pl 12 | */ 13 | @Component 14 | class CustomFilter extends ZuulFilter { 15 | 16 | @Override 17 | public String filterType() { 18 | return PRE_TYPE; 19 | } 20 | 21 | @Override 22 | public int filterOrder() { 23 | return PRE_DECORATION_FILTER_ORDER - 1 ; 24 | } 25 | 26 | @Override 27 | public boolean shouldFilter() { 28 | return true; 29 | } 30 | 31 | @Override 32 | public Object run() { 33 | RequestContext context = RequestContext.getCurrentContext(); 34 | context.addZuulRequestHeader("Code-Couple-Header", "CodeCouple!"); 35 | return null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-service-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #Server port 2 | server.port=8080 3 | #Application name 4 | spring.application.name=zuul-service 5 | #Default zone 6 | eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/ 7 | 8 | #Zuul prefix 9 | zuul.prefix=/api 10 | #First service 11 | zuul.routes.first-service.path=/first/** 12 | zuul.routes.first-service.serviceId=first-service 13 | #Second service 14 | zuul.routes.second-service.path=/second/** 15 | zuul.routes.second-service.serviceId=second-service -------------------------------------------------------------------------------- /spring-boot-zuul-example/spring-boot-zuul-service-example/src/test/java/pl/codecouple/ZuulServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package pl.codecouple; 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 ZuulServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------