├── spring-cloud-oauth ├── auth-client │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── templates │ │ │ └── personinfo.html │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── oauth │ │ └── authclient │ │ ├── AuthClient.java │ │ ├── filters │ │ └── SimpleFilter.java │ │ └── controller │ │ └── CloudSiteController.java ├── auth-client2 │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── templates │ │ │ └── personinfo.html │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── oauth │ │ └── authclient │ │ ├── AuthClient2.java │ │ ├── filters │ │ └── SimpleFilter.java │ │ └── controller │ │ └── CloudSiteController.java ├── auth-server │ └── src │ │ └── main │ │ ├── resources │ │ ├── certificate │ │ │ └── mykeystore.jks │ │ ├── application.yml │ │ └── templates │ │ │ └── login.html │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── oauth │ │ └── authserver │ │ ├── AuthServer.java │ │ └── config │ │ └── WebMvcConfigurer.java ├── auth-server-sql │ └── src │ │ └── main │ │ ├── resources │ │ ├── certificate │ │ │ └── mykeystore.jks │ │ ├── templates │ │ │ └── login.html │ │ └── data.sql │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── oauth │ │ └── authsql │ │ ├── OauthSqlApplication.java │ │ ├── repository │ │ └── AccountRepository.java │ │ ├── config │ │ ├── WebMvcConfigurer.java │ │ └── AppConfig.java │ │ ├── entities │ │ └── Account.java │ │ └── service │ │ └── AccountUserDetailsService.java ├── auth-resource │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── oauth │ │ │ └── authresource │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ ├── ResourceController.java │ │ │ └── PersonInfoController.java │ │ │ ├── config │ │ │ └── ResourceConfigurer.java │ │ │ └── model │ │ │ └── Person.java │ │ └── resources │ │ └── application.yml └── pom.xml ├── spring-cloud-contract ├── spring-cloud-contract-consumer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── contract │ │ │ └── consumer │ │ │ ├── SpringCloudContractConsumerApplication.java │ │ │ └── controller │ │ │ └── BasicMathController.java │ └── pom.xml └── spring-cloud-contract-producer │ ├── src │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── logback.xml │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── contract │ │ │ └── producer │ │ │ ├── SpringCloudContractProducerApplication.java │ │ │ └── controller │ │ │ └── EvenOddController.java │ └── test │ │ ├── resources │ │ └── contracts │ │ │ ├── shouldReturnOddWhenRequestParamIsOdd.groovy │ │ │ └── shouldReturnEvenWhenRequestParamIsEven.groovy │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── contract │ │ └── producer │ │ └── BaseTestClass.java │ └── pom.xml ├── spring-cloud-sleuth └── src │ └── main │ ├── resources │ └── application.properties │ └── java │ └── com │ └── peterwanghao │ └── spring │ └── cloud │ └── sleuth │ ├── SleuthWebApp.java │ └── SchedulingService.java ├── spring-cloud-hystrix ├── rest-producer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── hystrix │ │ │ └── rest │ │ │ └── producer │ │ │ ├── GreetingController.java │ │ │ ├── RestProducerApplication.java │ │ │ └── GreetingControllerImpl.java │ └── pom.xml ├── hystrix-dashboard-turbine │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── hystrix │ │ └── turbine │ │ └── DashboardTurbineApplication.java ├── spring-cloud-eureka-registry │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── registry │ │ └── EurekaServerApplication.java ├── feign-rest-consumer │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── templates │ │ │ └── greeting-view.html │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── hystrix │ │ └── rest │ │ └── consumer │ │ ├── GreetingClientFallback.java │ │ ├── GreetingClient.java │ │ ├── GreetingController.java │ │ └── RestConsumerFeignApplication.java ├── rest-consumer │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ ├── templates │ │ │ └── greeting-view.html │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── hystrix │ │ └── rest │ │ └── consumer │ │ ├── GreetingService.java │ │ ├── RestConsumerApplication.java │ │ └── GreetingController.java └── pom.xml ├── spring-cloud-zuul ├── spring-zuul-foos-resource │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── org │ │ │ └── peterwanghao │ │ │ └── zuul │ │ │ └── resource │ │ │ ├── ResourceServerApplication.java │ │ │ ├── config │ │ │ └── ResourceServerWebConfig.java │ │ │ └── web │ │ │ ├── dto │ │ │ └── Foo.java │ │ │ └── controller │ │ │ └── FooController.java │ └── pom.xml └── spring-zuul-ui │ └── src │ ├── main │ ├── resources │ │ ├── application.yml │ │ ├── logback.xml │ │ └── templates │ │ │ └── index.html │ └── java │ │ └── org │ │ └── peterwanghao │ │ └── zuul │ │ └── ui │ │ ├── UiApplication.java │ │ └── config │ │ └── CustomZuulFilter.java │ └── test │ └── java │ └── org │ └── peterwanghao │ └── zuul │ └── ui │ └── LiveTest.java ├── spring-cloud-bootstrap ├── discovery │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── bootstrap │ │ └── discovery │ │ └── DiscoveryApplication.java ├── application-config │ ├── readme.txt │ ├── book-service.properties │ ├── rating-service.properties │ ├── discovery.properties │ └── gateway.properties ├── gateway │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── bootstrap │ │ └── gateway │ │ └── GatewayApplication.java ├── book-service │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── bootstrap │ │ └── svcbook │ │ ├── Book.java │ │ └── BookServiceApplication.java ├── rating-service │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── bootstrap │ │ └── svcrating │ │ └── Rating.java ├── config │ └── src │ │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── bootstrap │ │ └── config │ │ └── ConfigApplication.java └── pom.xml ├── spring-cloud-vault ├── src │ ├── test │ │ └── resources │ │ │ ├── bootstrap.properties │ │ │ └── vault.jks │ └── main │ │ ├── resources │ │ ├── vault.jks │ │ ├── application.yml │ │ └── bootstrap.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── vault │ │ └── VaultSampleApplication.java └── vault-config │ ├── sample-policy.hcl │ ├── vault-test.hcl │ ├── database-setup.sql │ ├── localhost.cert │ └── localhost.key ├── spring-cloud-task ├── spring-cloud-task-stream │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── application.properties │ │ │ └── logback.xml │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── task │ │ │ └── SpringCloudTaskSinkApplication.java │ │ └── test │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── task │ │ └── TaskSinkConfiguration.java └── spring-cloud-task-batch │ └── src │ └── main │ ├── resources │ ├── logback.xml │ └── application.yml │ └── java │ └── com │ └── peterwanghao │ └── spring │ └── cloud │ └── task │ ├── HelloWorldTaskConfigurer.java │ └── TaskListener.java ├── spring-cloud-security ├── zipkin │ ├── .settings │ │ ├── org.eclipse.m2e.core.prefs │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.jdt.core.prefs │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── baeldung │ │ └── spring │ │ └── cloud │ │ └── security │ │ └── zipkin │ │ └── ZipkinApplication.java ├── discovery-secure │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── security │ │ └── discovery │ │ ├── SessionConfig.java │ │ └── DiscoveryApplication.java ├── application-config-secure │ ├── book-service.properties │ ├── rating-service.properties │ ├── discovery.properties │ └── gateway.properties ├── gateway-secure │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── security │ │ └── gateway │ │ ├── GatewayApplication.java │ │ ├── SessionConfig.java │ │ └── filter │ │ └── SessionSavingZuulPreFilter.java ├── book-service-secure │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── security │ │ └── svcbook │ │ ├── SessionConfig.java │ │ ├── Book.java │ │ ├── SecurityConfig.java │ │ └── BookServiceApplication.java ├── rating-service-secure │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── security │ │ └── svcrating │ │ ├── SessionConfig.java │ │ ├── Rating.java │ │ └── SecurityConfig.java ├── config-secure │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── security │ │ │ └── config │ │ │ └── ConfigApplication.java │ │ └── resources │ │ └── application.properties └── pom.xml ├── spring-cloud-zuul-eureka ├── eureka-server │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── server │ │ └── EurekaServerApplication.java ├── eureka-client1 │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── client │ │ ├── GreetingController.java │ │ └── EurekaClientApplication.java ├── eureka-client2 │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── client │ │ ├── GreetingController.java │ │ └── EurekaClientApplication.java ├── zuul-server │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.properties │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── baeldung │ │ └── spring │ │ └── cloud │ │ └── zuul │ │ └── ZuulApplication.java └── pom.xml ├── spring-cloud-config ├── server │ └── src │ │ └── main │ │ ├── resources │ │ ├── config-server.jks │ │ ├── bootstrap.properties │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── config │ │ └── server │ │ └── ConfigServer.java ├── client │ └── src │ │ └── main │ │ ├── resources │ │ └── bootstrap.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── config │ │ └── client │ │ └── ConfigClient.java └── pom.xml ├── spring-cloud-archaius ├── simple_config │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── config.properties │ │ │ ├── other-config.properties │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── archaius │ │ │ └── simple │ │ │ ├── SimpleApplication.java │ │ │ └── config │ │ │ └── ApplicationPropertiesConfigurations.java │ └── pom.xml ├── jdbc-config │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── data.sql │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── archaius │ │ │ └── jdbc │ │ │ ├── entity │ │ │ └── Properties.java │ │ │ ├── JdbcSourcesApplication.java │ │ │ ├── config │ │ │ └── ApplicationPropertiesConfigurations.java │ │ │ └── controller │ │ │ └── ConfigPropertiesController.java │ └── pom.xml ├── zookeeper-config │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.properties │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── archaius │ │ │ └── zookeeper │ │ │ └── ZookeeperConfigApplication.java │ └── pom.xml └── dynamodb-config │ ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── archaius │ │ └── dynamodb │ │ ├── entity │ │ ├── ArchaiusPropertiesRepository.java │ │ └── ArchaiusProperties.java │ │ ├── DynamoDBSourcesApplication.java │ │ └── controller │ │ └── ConfigPropertiesController.java │ └── pom.xml ├── spring-cloud-consul ├── consul-prop │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── bootstrap.yml │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── consul │ │ │ └── properties │ │ │ ├── DistributedPropertiesApplication.java │ │ │ ├── MyProperties.java │ │ │ └── DistributedPropertiesController.java │ └── pom.xml ├── consul-client │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── consul │ │ │ └── client │ │ │ └── DiscoveryClientApplication.java │ └── pom.xml ├── consul-service │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── consul │ │ │ └── service │ │ │ ├── ServiceDiscoveryApplication.java │ │ │ └── ServiceDiscoveryController.java │ └── pom.xml └── pom.xml ├── spring-cloud-zookeeper ├── ServiceConsumer │ └── src │ │ └── main │ │ ├── resources │ │ ├── templates │ │ │ └── greeting-view.html │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── greeting │ │ ├── GreetingApplication.java │ │ ├── GreetingController.java │ │ └── HelloWorldClient.java ├── ServiceProvider │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── helloworld │ │ ├── HelloWorldController.java │ │ └── HelloWorldApplication.java └── pom.xml ├── spring-cloud-eureka ├── spring-cloud-eureka-feign-client │ └── src │ │ └── main │ │ ├── resources │ │ ├── application.yml │ │ └── templates │ │ │ └── greeting-view.html │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── feign │ │ └── client │ │ ├── GreetingClient.java │ │ └── FeignClientApplication.java ├── spring-cloud-eureka-client │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── client │ │ ├── GreetingController.java │ │ └── EurekaClientApplication.java ├── spring-cloud-eureka-server │ └── src │ │ └── main │ │ ├── resources │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── eureka │ │ └── server │ │ └── EurekaServerApplication.java └── pom.xml ├── spring-cloud-ribbon-client └── src │ ├── main │ ├── resources │ │ └── application.yml │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── ribbon │ │ └── client │ │ ├── RibbonConfiguration.java │ │ └── ServerLocationApp.java │ └── test │ └── java │ └── com │ └── peterwanghao │ └── spring │ └── cloud │ └── ribbon │ └── client │ └── TestServiceProvider.java └── spring-cloud-stream ├── spring-cloud-stream-rabbit ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── peterwanghao │ │ │ └── spring │ │ │ └── cloud │ │ │ └── stream │ │ │ └── rabbit │ │ │ ├── processor │ │ │ └── MyProcessor.java │ │ │ ├── model │ │ │ └── LogMessage.java │ │ │ ├── MyLoggerServiceApplication.java │ │ │ └── MultipleOutputsServiceApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── peterwanghao │ │ └── spring │ │ └── cloud │ │ └── stream │ │ └── rabbit │ │ └── MyLoggerApplicationIntegrationTest.java └── pom.xml └── pom.xml /spring-cloud-oauth/auth-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spring-cloud-sleuth/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=Sleuth Tutorial -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=rest-producer 2 | server.port=9090 3 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.contextPath=/spring-zuul-foos-resource 2 | server.port=8081 -------------------------------------------------------------------------------- /spring-cloud-bootstrap/discovery/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=discovery 2 | spring.cloud.config.uri=http://localhost:8081 -------------------------------------------------------------------------------- /spring-cloud-vault/src/test/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.vault.token=2HgD0nKyaDjI5TICz9pObW2T 2 | 3 | logging.level.org.springframework=INFO -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-stream/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot -------------------------------------------------------------------------------- /spring-cloud-vault/src/main/resources/vault.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-vault/src/main/resources/vault.jks -------------------------------------------------------------------------------- /spring-cloud-vault/src/test/resources/vault.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-vault/src/test/resources/vault.jks -------------------------------------------------------------------------------- /spring-cloud-security/zipkin/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/application-config/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-bootstrap/application-config/readme.txt -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8761 2 | 3 | eureka.client.registerWithEureka=false 4 | eureka.client.fetchRegistry=false -------------------------------------------------------------------------------- /spring-cloud-vault/vault-config/sample-policy.hcl: -------------------------------------------------------------------------------- 1 | path "secret/fakebank" { 2 | capabilities = ["read"] 3 | allowed_parameters = { 4 | "api_key" = [] 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/hystrix-dashboard-turbine/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/spring-cloud-eureka-registry/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /spring-cloud-config/server/src/main/resources/config-server.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-config/server/src/main/resources/config-server.jks -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | zuul: 2 | routes: 3 | foos: 4 | path: /foos/** 5 | url: http://localhost:8081/spring-zuul-foos-resource/foos 6 | -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | springcloud.archaius.properties.one=one FROM:config.properties 2 | springcloud.archaius.properties.three=three FROM:config.properties 3 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/application-config/book-service.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=book-service 2 | server.port=8083 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 -------------------------------------------------------------------------------- /spring-cloud-bootstrap/application-config/rating-service.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=rating-service 2 | server.port=8084 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 6 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server/src/main/resources/certificate/mykeystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-oauth/auth-server/src/main/resources/certificate/mykeystore.jks -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/src/main/resources/other-config.properties: -------------------------------------------------------------------------------- 1 | springcloud.archaius.properties.one=one FROM:other-config.properties 2 | springcloud.archaius.properties.four=four FROM:other-config.properties 3 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/resources/certificate/mykeystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterwanghao/spring-cloud-examples/HEAD/spring-cloud-oauth/auth-server-sql/src/main/resources/certificate/mykeystore.jks -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | springcloud.archaius.properties.one=one FROM:application.properties 3 | springcloud.archaius.properties.two=two FROM:application.properties 4 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=consumer02 2 | server.port=8082 3 | feign.hystrix.enabled=true 4 | 5 | eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka} -------------------------------------------------------------------------------- /spring-cloud-vault/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: fakebank 4 | 5 | datasource: 6 | url: jdbc:mysql://localhost:3306/fakebank 7 | username: v-fake-60fSchsFo 8 | password: A1a-24NNCeaazWCp2EE7 9 | -------------------------------------------------------------------------------- /spring-cloud-security/discovery-secure/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=discovery 2 | spring.cloud.config.uri=http://localhost:8081 3 | 4 | spring.cloud.config.username=configUser 5 | spring.cloud.config.password=configPassword -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into properties 2 | values('springcloud.archaius.properties.one', 'one FROM:jdbc_source'); 3 | 4 | insert into properties 5 | values('springcloud.archaius.properties.three', 'three FROM:jdbc_source'); -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: myPro 4 | cloud: 5 | consul: 6 | host: localhost 7 | port: 8500 8 | config: 9 | enabled: true 10 | server: 11 | port: 8509 -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | springcloud.archaius.properties.one=one FROM:application.properties 3 | springcloud.archaius.properties.two=two FROM:application.properties 4 | spring.h2.console.enabled=true 5 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/gateway/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=gateway 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client1/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=spring-cloud-eureka-client 2 | server.port=8081 3 | 4 | eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka} 5 | eureka.instance.preferIpAddress=true -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client2/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=spring-cloud-eureka-client 2 | server.port=8082 3 | 4 | eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8761/eureka} 5 | eureka.instance.preferIpAddress=true -------------------------------------------------------------------------------- /spring-cloud-security/zipkin/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /spring-cloud-archaius/zookeeper-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | springcloud.archaius.properties.one=one FROM:application.properties 3 | springcloud.archaius.properties.two=two FROM:application.properties 4 | spring.application.name=zookeeper-config 5 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/book-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=book-service 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=consumer01 2 | server.port=8080 3 | 4 | feign.hystrix.enabled=true 5 | eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka} 6 | eureka.instance.preferIpAddress=true -------------------------------------------------------------------------------- /spring-cloud-bootstrap/rating-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=rating-service 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceConsumer/src/main/resources/templates/greeting-view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Greeting Page 5 | 6 | 7 |

8 | 9 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/hystrix-dashboard-turbine/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/spring-cloud-eureka-registry/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceConsumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: Greeting 4 | cloud: 5 | zookeeper: 6 | connect-string: localhost:2181 7 | server: 8 | port: 8083 9 | logging: 10 | level: 11 | org.apache.zookeeper.ClientCnxn: WARN -------------------------------------------------------------------------------- /spring-cloud-bootstrap/application-config/discovery.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=discovery 2 | server.port=8082 3 | 4 | eureka.instance.hostname=localhost 5 | 6 | eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/ 7 | eureka.client.register-with-eureka=false 8 | eureka.client.fetch-registry=false -------------------------------------------------------------------------------- /spring-cloud-config/server/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | #对称密钥 2 | #encrypt.key=symmetricKey 3 | 4 | #非对称密钥 5 | encrypt.key-store.location=classpath:/config-server.jks 6 | encrypt.key-store.password=my-s70r3-s3cr3t 7 | encrypt.key-store.alias=config-server-key 8 | encrypt.key-store.secret=my-k34-s3cr3t -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-feign-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-cloud-eureka-feign-client 4 | 5 | server: 6 | port: 8080 7 | 8 | eureka: 9 | client: 10 | serviceUrl: 11 | defaultZone: ${EUREKA_URI:http://localhost:8888/eureka} -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-feign-client/src/main/resources/templates/greeting-view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Greeting Page 5 | 6 | 7 |

8 | 9 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/resources/templates/greeting-view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Greetings from Hystrix 5 | 6 | 7 |

8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-cloud-security/zipkin/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/resources/templates/greeting-view.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Greetings from Hystrix 5 | 6 | 7 |

8 | 9 | 10 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/spring-cloud-eureka-registry/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 2 | 3 | eureka.instance.hostname=localhost 4 | eureka.client.registerWithEureka=false 5 | eureka.client.fetchRegistry=false 6 | eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /spring-cloud-security/application-config-secure/book-service.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=book-service 2 | server.port=8083 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 6 | 7 | management.security.sessions=never 8 | 9 | spring.redis.host=localhost 10 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | springcloud.archaius.properties.one=one FROM:application.properties 3 | springcloud.archaius.properties.two=two FROM:application.properties 4 | amazon.dynamodb.endpoint=http://localhost:8000/ 5 | aws.accessKeyId=key 6 | aws.secretKey=key2 7 | -------------------------------------------------------------------------------- /spring-cloud-security/application-config-secure/rating-service.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=rating-service 2 | server.port=8084 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 6 | 7 | management.security.sessions=never 8 | 9 | spring.redis.host=localhost 10 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-cloud-hystrix/hystrix-dashboard-turbine/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/spring-cloud-eureka-registry/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.8 6 | -------------------------------------------------------------------------------- /spring-cloud-ribbon-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-cloud-ribbon 4 | 5 | server: 6 | port: 8888 7 | 8 | ping-server: 9 | ribbon: 10 | eureka: 11 | enabled: false 12 | listOfServers: localhost:8081,localhost:8082 13 | ServerListRefreshInterval: 15000 -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-cloud-eureka-client 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | serviceUrl: 11 | defaultZone: ${EUREKA_URI:http://localhost:8888/eureka} 12 | instance: 13 | preferIpAddress: true -------------------------------------------------------------------------------- /spring-cloud-security/zipkin/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=zipkin 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | spring.cloud.config.username=configUser 5 | spring.cloud.config.password=configPassword 6 | 7 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-hystrix/hystrix-dashboard-turbine/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=hystrix-dashboard-turbine 2 | server.port=8000 3 | turbine.appConfig=consumer01,consumer02 4 | turbine.aggregator.clusterConfig= default 5 | turbine.clusterNameExpression= new String("default") 6 | 7 | eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8888/eureka} -------------------------------------------------------------------------------- /spring-cloud-security/gateway-secure/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=gateway 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | spring.cloud.config.username=configUser 6 | spring.cloud.config.password=configPassword 7 | 8 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceProvider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: HelloWorld 4 | cloud: 5 | zookeeper: 6 | connect-string: localhost:2181 7 | discovery: 8 | enabled: true 9 | server: 10 | port: 8081 11 | endpoints: 12 | restart: 13 | enabled: true 14 | logging: 15 | level: 16 | org.apache.zookeeper.ClientCnxn: WARN -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 #服务注册中心端口号 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost #服务注册中心实例的主机名 7 | client: 8 | registerWithEureka: false #是否向服务注册中心注册自己 9 | fetchRegistry: false #是否检索服务 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 12 | -------------------------------------------------------------------------------- /spring-cloud-security/application-config-secure/discovery.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=discovery 2 | server.port=8082 3 | 4 | eureka.instance.hostname=localhost 5 | 6 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ 7 | eureka.client.register-with-eureka=false 8 | eureka.client.fetch-registry=false 9 | 10 | spring.redis.host=localhost 11 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-cloud-security/book-service-secure/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=book-service 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | spring.cloud.config.username=configUser 6 | spring.cloud.config.password=configPassword 7 | 8 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-security/rating-service-secure/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.cloud.config.name=rating-service 2 | spring.cloud.config.discovery.service-id=config 3 | spring.cloud.config.discovery.enabled=true 4 | 5 | spring.cloud.config.username=configUser 6 | spring.cloud.config.password=configPassword 7 | 8 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-consul/consul-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: myCli 4 | cloud: 5 | consul: 6 | host: localhost 7 | port: 8500 8 | discovery: 9 | healthCheckPath: /my-health-check 10 | healthCheckInterval: 20s 11 | enabled: true 12 | instanceId: ${spring.application.name}:${random.value} 13 | server: 14 | port: 8505 -------------------------------------------------------------------------------- /spring-cloud-consul/consul-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: myApp 4 | cloud: 5 | consul: 6 | host: localhost 7 | port: 8500 8 | discovery: 9 | healthCheckPath: /my-health-check 10 | healthCheckInterval: 20s 11 | enabled: true 12 | instanceId: ${spring.application.name}:${random.value} 13 | server: 14 | port: 8501 -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client/src/main/resources/templates/personinfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Getting Personal Information 6 | 7 | 8 |

Providing Person Information

9 |

10 | Person's information: 11 |

12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/resources/templates/personinfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Getting Personal Information 6 | 7 | 8 |

Providing Person Information

9 |

10 | Person's information: 11 |

12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-vault/vault-config/vault-test.hcl: -------------------------------------------------------------------------------- 1 | /* 2 | * Sample configuration file for tests 3 | */ 4 | 5 | // Enable UI 6 | ui = true 7 | 8 | // Filesystem storage 9 | storage "file" { 10 | path = "./vault-data" 11 | } 12 | 13 | // TCP Listener using a self-signed certificate 14 | listener "tcp" { 15 | address = "127.0.0.1:8200" 16 | tls_cert_file = "localhost.cert" 17 | tls_key_file = "localhost.key" 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/zuul-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8762 2 | spring.application.name=zuul-server 3 | eureka.instance.preferIpAddress=true 4 | eureka.client.registerWithEureka=true 5 | eureka.client.fetchRegistry=true 6 | eureka.serviceurl.defaultzone=http://localhost:8761/eureka/ 7 | management.security.enabled=false 8 | security.basic.enabled=false 9 | hystrix.command.default.execution.timeout.enabled=false 10 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-client/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/zuul-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-batch/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-stream/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client1/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client2/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-consumer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-cloud-config/client/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=config-client 2 | server.port=8000 3 | 4 | #spring.profiles.active=production 5 | spring.cloud.config.uri=http://localhost:8888 6 | #spring.cloud.config.profile=development 7 | #spring.cloud.config.profile=symmetric 8 | spring.cloud.config.profile=asymmetric 9 | spring.cloud.config.label=master 10 | spring.cloud.config.username=root 11 | spring.cloud.config.password=s3cr3t 12 | spring.cloud.config.fail-fast=true 13 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Make the application available at http://localhost:7070/authserver 2 | server: 3 | port: 7070 4 | contextPath: /authserver 5 | 6 | # Our certificate settings for enabling JWT tokens 7 | jwt: 8 | certificate: 9 | store: 10 | file: classpath:/certificate/mykeystore.jks 11 | password: abirkhan04 12 | key: 13 | alias: myauthkey 14 | password: abirkhan04 15 | 16 | 17 | security: 18 | oauth2: 19 | resource: 20 | filter-order: 3 21 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/test/resources/contracts/shouldReturnOddWhenRequestParamIsOdd.groovy: -------------------------------------------------------------------------------- 1 | import org.springframework.cloud.contract.spec.Contract 2 | 3 | Contract.make { 4 | description "should return odd when number input is odd" 5 | request { 6 | method GET() 7 | url("/validate/prime-number") { 8 | queryParameters { 9 | parameter("number", "1") 10 | } 11 | } 12 | } 13 | response { 14 | body("Odd") 15 | status 200 16 | } 17 | } -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-client/src/main/java/com/peterwanghao/spring/cloud/eureka/client/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | 5 | /** 6 | * @ClassName: GreetingController 7 | * @Description:打招呼服务 8 | * @author: wanghao 9 | * @date: 2018年3月14日 下午3:58:56 10 | * @version V1.0 11 | * 12 | */ 13 | public interface GreetingController { 14 | @RequestMapping("/greeting") 15 | String greeting(); 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/test/resources/contracts/shouldReturnEvenWhenRequestParamIsEven.groovy: -------------------------------------------------------------------------------- 1 | import org.springframework.cloud.contract.spec.Contract 2 | 3 | Contract.make { 4 | description "should return even when number input is even" 5 | request { 6 | method GET() 7 | url("/validate/prime-number") { 8 | queryParameters { 9 | parameter("number", "2") 10 | } 11 | } 12 | } 13 | response { 14 | body("Even") 15 | status 200 16 | } 17 | } -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client1/src/main/java/com/peterwanghao/spring/cloud/eureka/client/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | 5 | /** 6 | * @ClassName: GreetingController 7 | * @Description:TODO(这里用一句话描述这个类的作用) 8 | * @author: wanghao 9 | * @date: 2018年9月17日 下午4:45:45 10 | * @version V1.0 11 | * 12 | */ 13 | public interface GreetingController { 14 | @RequestMapping("/greeting") 15 | String greeting(); 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client2/src/main/java/com/peterwanghao/spring/cloud/eureka/client/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | 5 | /** 6 | * @ClassName: GreetingController 7 | * @Description:TODO(这里用一句话描述这个类的作用) 8 | * @author: wanghao 9 | * @date: 2018年9月17日 下午4:45:45 10 | * @version V1.0 11 | * 12 | */ 13 | public interface GreetingController { 14 | @RequestMapping("/greeting") 15 | String greeting(); 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/src/main/java/com/peterwanghao/spring/cloud/archaius/dynamodb/entity/ArchaiusPropertiesRepository.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.dynamodb.entity; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | /** 6 | * @ClassName: ArchaiusPropertiesRepository 7 | * @Description:TODO(这里用一句话描述这个类的作用) 8 | * @author: wanghao 9 | * @date: 2018年11月20日 下午4:57:16 10 | * @version V1.0 11 | * 12 | */ 13 | public interface ArchaiusPropertiesRepository extends CrudRepository { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/java/com/peterwanghao/spring/cloud/archaius/jdbc/entity/Properties.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.jdbc.entity; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | /** 7 | * @ClassName: Properties 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年11月20日 下午4:36:35 11 | * @version V1.0 12 | * 13 | */ 14 | @Entity 15 | public class Properties { 16 | 17 | @Id 18 | private String key; 19 | 20 | @SuppressWarnings("unused") 21 | private String value; 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-config/server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=config-server 2 | server.port=8888 3 | 4 | #配置Git仓库位置 5 | spring.cloud.config.server.git.uri=ssh://admin@localhost:29418/Test.git 6 | #配置仓库路径下的相对搜索位置,可以配置多个 7 | spring.cloud.config.server.git.searchPaths=config-repo 8 | #配置为true表示启动时就克隆配置缓存到本地。 9 | spring.cloud.config.server.git.clone-on-start=true 10 | #访问Git仓库的用户名 11 | spring.cloud.config.server.git.username=admin 12 | #访问Git仓库的用户密码 13 | spring.cloud.config.server.git.password=admin 14 | 15 | #Basic-Authentication 16 | security.user.name=root 17 | security.user.password=s3cr3t 18 | -------------------------------------------------------------------------------- /spring-cloud-sleuth/src/main/java/com/peterwanghao/spring/cloud/sleuth/SleuthWebApp.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.sleuth; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: SleuthWebApp 8 | * @Description:Spring Boot主应用类 9 | * @author: wanghao 10 | * @date: 2018年4月11日 上午11:02:19 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class SleuthWebApp { 16 | public static void main(String[] args) { 17 | SpringApplication.run(SleuthWebApp.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server/src/main/java/com/peterwanghao/spring/cloud/oauth/authserver/AuthServer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.*; 5 | 6 | /** 7 | * @ClassName: AuthServer 8 | * @Description:OAuth认证服务 9 | * @author: wanghao 10 | * @date: 2018年7月19日 下午2:21:34 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class AuthServer { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(AuthServer.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-feign-client/src/main/java/com/peterwanghao/spring/cloud/feign/client/GreetingClient.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.feign.client; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @ClassName: GreetingClient 8 | * @Description:打招呼服务客户 9 | * @author: wanghao 10 | * @date: 2018年3月14日 下午4:25:35 11 | * @version V1.0 12 | * 13 | */ 14 | @FeignClient("spring-cloud-eureka-client") 15 | public interface GreetingClient{ 16 | @RequestMapping("/greeting") 17 | String greeting(); 18 | } 19 | -------------------------------------------------------------------------------- /spring-cloud-vault/vault-config/database-setup.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- Sample schema for testing vault database secrets 3 | -- 4 | create schema fakebank; 5 | use fakebank; 6 | create table account( 7 | id decimal(16,0), 8 | name varchar(30), 9 | branch_id decimal(16,0), 10 | customer_id decimal(16,0), 11 | primary key (id)); 12 | 13 | -- 14 | -- MySQL user that will be used by Vault to create other users on demand 15 | -- 16 | create user 'fakebank-admin'@'%' identified by 'Sup&rSecre7!'; 17 | grant all privileges on fakebank.* to 'fakebank-admin'@'%' with grant option; 18 | grant create user on *.* to 'fakebank-admin' with grant option; 19 | 20 | flush privileges; 21 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/producer/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.producer; 2 | 3 | import org.springframework.web.bind.annotation.PathVariable; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * @ClassName: GreetingController 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年8月15日 下午4:23:04 11 | * @version V1.0 12 | * 13 | */ 14 | public interface GreetingController { 15 | @RequestMapping("/greeting/{username}") 16 | String greeting(@PathVariable("username") String username); 17 | } 18 | -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-batch/src/main/java/com/peterwanghao/spring/cloud/task/HelloWorldTaskConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.task; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.cloud.task.configuration.DefaultTaskConfigurer; 6 | 7 | /** 8 | * @ClassName: HelloWorldTaskConfigurer 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年10月12日 下午1:45:05 12 | * @version V1.0 13 | * 14 | */ 15 | public class HelloWorldTaskConfigurer extends DefaultTaskConfigurer { 16 | 17 | public HelloWorldTaskConfigurer(DataSource dataSource) { 18 | super(dataSource); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceProvider/src/main/java/com/peterwanghao/spring/cloud/helloworld/HelloWorldController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.helloworld; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @ClassName: HelloWorldController 8 | * @Description:RESTful服务,HelloWorld 9 | * @author: wanghao 10 | * @date: 2018年3月23日 下午5:39:42 11 | * @version V1.0 12 | * 13 | */ 14 | @RestController 15 | public class HelloWorldController { 16 | @GetMapping("/helloworld") 17 | public String HelloWorld() { 18 | return "Hello World!"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-vault/src/main/java/com/peterwanghao/spring/cloud/vault/VaultSampleApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.vault; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: VaultSampleApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年10月18日 下午4:55:09 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class VaultSampleApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(VaultSampleApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/java/com/peterwanghao/spring/cloud/oauth/authresource/Application.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authresource; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: Application 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年7月19日 下午2:37:57 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-security/discovery-secure/src/main/java/com/peterwanghao/spring/cloud/security/discovery/SessionConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.discovery; 2 | 3 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 4 | import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer; 5 | 6 | /** 7 | * @ClassName: SessionConfig 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年5月2日 上午11:04:15 11 | * @version V1.0 12 | * 13 | */ 14 | @EnableRedisHttpSession 15 | public class SessionConfig extends AbstractHttpSessionApplicationInitializer { 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/src/main/java/com/peterwanghao/spring/cloud/archaius/simple/SimpleApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.simple; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: SimpleApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年11月7日 下午3:46:03 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class SimpleApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(SimpleApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=config 2 | server.port=8081 3 | 4 | #配置Git仓库位置 5 | spring.cloud.config.server.git.uri=ssh://admin@localhost:29418/Test.git 6 | #配置仓库路径下的相对搜索位置,可以配置多个 7 | spring.cloud.config.server.git.searchPaths=application-config 8 | #配置为true表示启动时就克隆配置缓存到本地。 9 | spring.cloud.config.server.git.clone-on-start=true 10 | #访问Git仓库的用户名 11 | spring.cloud.config.server.git.username=admin 12 | #访问Git仓库的用户密码 13 | spring.cloud.config.server.git.password=admin 14 | 15 | eureka.client.region = default 16 | eureka.client.registryFetchIntervalSeconds = 5 17 | eureka.client.serviceUrl.defaultZone=http://localhost:8082/eureka/ -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-batch/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org: 4 | springframework: 5 | cloud: 6 | task=DEBUG 7 | 8 | spring: 9 | application: 10 | name=helloWorld 11 | datasource: 12 | url: jdbc:mysql://localhost:3306/springcloud?useSSL=false 13 | username: root 14 | password: 123456 15 | jpa: 16 | hibernate: 17 | ddl-auto: create-drop 18 | properties: 19 | hibernate: 20 | dialect: org.hibernate.dialect.MySQL5Dialect 21 | batch: 22 | initialize-schema: always 23 | maven: 24 | remoteRepositories: 25 | springRepo: 26 | url: https://repo.spring.io/libs-snapshot -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/OauthSqlApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | 7 | /** 8 | * @ClassName: OauthSqlApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年7月25日 下午4:58:52 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | public class OauthSqlApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(OauthSqlApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.peterwanghao.spring.cloud.oauth.authsql.entities.Account; 6 | 7 | import java.util.Optional; 8 | 9 | /** 10 | * @ClassName: AccountRepository 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年7月25日 下午2:41:42 14 | * @version V1.0 15 | * 16 | */ 17 | public interface AccountRepository extends JpaRepository { 18 | Optional findByUsername(String username); 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/java/com/peterwanghao/spring/cloud/archaius/jdbc/JdbcSourcesApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.jdbc; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: JdbcSourcesApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年11月20日 下午4:38:25 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class JdbcSourcesApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(JdbcSourcesApplication.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/producer/RestProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.producer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: RestProducerApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年8月15日 下午4:21:45 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class RestProducerApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(RestProducerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/src/main/java/com/peterwanghao/spring/cloud/archaius/dynamodb/DynamoDBSourcesApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.dynamodb; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: DynamoDBSourcesApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年11月20日 下午5:20:34 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class DynamoDBSourcesApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(DynamoDBSourcesApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-consul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.peterwanghao.spring.cloud 5 | spring-cloud-examples 6 | 0.0.1-SNAPSHOT 7 | 8 | spring-cloud-consul 9 | pom 10 | spring-cloud-consul 11 | 12 | consul-service 13 | consul-client 14 | consul-prop 15 | 16 | -------------------------------------------------------------------------------- /spring-cloud-archaius/zookeeper-config/src/main/java/com/peterwanghao/spring/cloud/archaius/zookeeper/ZookeeperConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.zookeeper; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: ZookeeperConfigApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年11月21日 下午2:06:35 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class ZookeeperConfigApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ZookeeperConfigApplication.class, args); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/GreetingClientFallback.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 2 | 3 | import org.springframework.stereotype.Component; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | 6 | /** 7 | * @ClassName: GreetingClientFallback 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年8月15日 下午5:30:12 11 | * @version V1.0 12 | * 13 | */ 14 | @Component 15 | public class GreetingClientFallback implements GreetingClient { 16 | 17 | @Override 18 | public String greeting(@PathVariable("username") String username) { 19 | return "Hello User!"; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-service/src/main/java/com/peterwanghao/spring/cloud/consul/service/ServiceDiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.service; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | 6 | /** 7 | * @ClassName: ServiceDiscoveryApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年12月6日 下午2:20:53 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class ServiceDiscoveryApplication { 16 | public static void main(String[] args) { 17 | new SpringApplicationBuilder(ServiceDiscoveryApplication.class).web(true).run(args); 18 | } 19 | } -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-archaius 8 | 0.0.1-SNAPSHOT 9 | 10 | simple_config 11 | simple_config 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-web 17 | 18 | 19 | -------------------------------------------------------------------------------- /spring-cloud-config/server/src/main/java/com/peterwanghao/spring/cloud/config/server/ConfigServer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.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 | /** 8 | * @ClassName: ConfigServer 9 | * @Description:微服务框架Spring Cloud Config 实现的配置中心 10 | * @author: wanghao 11 | * @date: 2018年3月20日 下午1:43:17 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableConfigServer 17 | public class ConfigServer { 18 | public static void main(String[] args) { 19 | SpringApplication.run(ConfigServer.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/java/com/peterwanghao/spring/cloud/oauth/authresource/controller/ResourceController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authresource.controller; 2 | 3 | import java.security.Principal; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @ClassName: ResourceController 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年7月19日 下午2:47:55 12 | * @version V1.0 13 | * 14 | */ 15 | @RestController 16 | public class ResourceController { 17 | 18 | @RequestMapping("/user") 19 | public Principal user(Principal user) { 20 | return user; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /spring-cloud-oauth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.peterwanghao.spring.cloud 5 | spring-cloud-examples 6 | 0.0.1-SNAPSHOT 7 | 8 | spring-cloud-oauth 9 | pom 10 | 11 | auth-server 12 | auth-resource 13 | auth-client 14 | auth-client2 15 | auth-server-sql 16 | 17 | -------------------------------------------------------------------------------- /spring-cloud-security/book-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcbook/SessionConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcbook; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 5 | import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer; 6 | 7 | /** 8 | * @ClassName: SessionConfig 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年5月2日 上午11:31:00 12 | * @version V1.0 13 | * 14 | */ 15 | @Configuration 16 | @EnableRedisHttpSession 17 | public class SessionConfig extends AbstractHttpSessionApplicationInitializer { 18 | } 19 | -------------------------------------------------------------------------------- /spring-cloud-security/rating-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcrating/SessionConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcrating; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 5 | import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer; 6 | 7 | /** 8 | * @ClassName: SessionConfig 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年5月2日 下午1:27:47 12 | * @version V1.0 13 | * 14 | */ 15 | @Configuration 16 | @EnableRedisHttpSession 17 | public class SessionConfig extends AbstractHttpSessionApplicationInitializer { 18 | } 19 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceConsumer/src/main/java/com/peterwanghao/spring/cloud/greeting/GreetingApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.greeting; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @ClassName: GreetingApplication 9 | * @Description:服务消费者 10 | * @author: wanghao 11 | * @date: 2018年3月23日 下午5:45:09 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | public class GreetingApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(GreetingApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/config/src/main/java/com/peterwanghao/spring/cloud/bootstrap/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * @ClassName: ConfigApplication 9 | * @Description:配置中心,将所有配置保存到一个Git仓库 10 | * @author: wanghao 11 | * @date: 2018年4月25日 上午10:06:50 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableConfigServer 17 | public class ConfigApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(ConfigApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-security/config-secure/src/main/java/com/peterwanghao/spring/cloud/security/config/ConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * @ClassName: ConfigApplication 9 | * @Description:配置中心,将所有配置保存到一个Git仓库 10 | * @author: wanghao 11 | * @date: 2018年5月2日 上午9:57:15 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableConfigServer 17 | public class ConfigApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(ConfigApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceProvider/src/main/java/com/peterwanghao/spring/cloud/helloworld/HelloWorldApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.helloworld; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @ClassName: HelloWorldApplication 9 | * @Description:服务提供者 10 | * @author: wanghao 11 | * @date: 2018年3月23日 下午5:37:59 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | public class HelloWorldApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(HelloWorldApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/main/java/com/peterwanghao/spring/cloud/contract/producer/SpringCloudContractProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.contract.producer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @ClassName: SpringCloudContractProducerApplication 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2019年1月10日 下午3:49:26 11 | * @version V1.0 12 | * 13 | */ 14 | @SpringBootApplication 15 | public class SpringCloudContractProducerApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(SpringCloudContractProducerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/discovery/src/main/java/com/peterwanghao/spring/cloud/bootstrap/discovery/DiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.discovery; 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 | /** 8 | * @ClassName: DiscoveryApplication 9 | * @Description:服务注册中心 10 | * @author: wanghao 11 | * @date: 2018年4月17日 下午3:16:06 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class DiscoveryApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(DiscoveryApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | stream: 4 | bindings: 5 | input: 6 | destination: queue.log.messages 7 | binder: local_rabbit 8 | group: logMessageConsumers 9 | output: 10 | destination: queue.pretty.log.messages 11 | binder: local_rabbit 12 | binders: 13 | local_rabbit: 14 | type: rabbit 15 | environment: 16 | spring: 17 | rabbitmq: 18 | host: localhost 19 | port: 5672 20 | username: guest 21 | password: guest 22 | virtual-host: / 23 | server: 24 | port: 0 25 | management: 26 | health: 27 | binders: 28 | enabled: true -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-stream/src/test/java/com/peterwanghao/spring/cloud/task/TaskSinkConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.task; 2 | 3 | import static org.mockito.Mockito.mock; 4 | 5 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | * @ClassName: TaskSinkConfiguration 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年10月12日 下午2:53:53 14 | * @version V1.0 15 | * 16 | */ 17 | @Configuration 18 | public class TaskSinkConfiguration { 19 | 20 | @Bean 21 | public TaskLauncher taskLauncher() { 22 | return mock(TaskLauncher.class); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-cloud-security/discovery-secure/src/main/java/com/peterwanghao/spring/cloud/security/discovery/DiscoveryApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.discovery; 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 | /** 8 | * @ClassName: DiscoveryApplication 9 | * @Description:服务注册中心 10 | * @author: wanghao 11 | * @date: 2018年5月2日 上午10:10:05 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class DiscoveryApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(DiscoveryApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-server/src/main/java/com/peterwanghao/spring/cloud/eureka/server/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.server; 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 | /** 8 | * @ClassName: EurekaServerApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年9月17日 下午4:29:59 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class EurekaServerApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(EurekaServerApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/java/org/peterwanghao/zuul/resource/ResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.resource; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.support.SpringBootServletInitializer; 6 | 7 | /** 8 | * @ClassName: ResourceServerApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年9月11日 上午9:32:25 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | public class ResourceServerApplication extends SpringBootServletInitializer{ 17 | public static void main(String[] args) { 18 | SpringApplication.run(ResourceServerApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-security/zipkin/src/main/java/com/baeldung/spring/cloud/security/zipkin/ZipkinApplication.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.spring.cloud.security.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import zipkin.server.EnableZipkinServer; 7 | 8 | /** 9 | * @ClassName: ZipkinApplication 10 | * @Description:服务跟踪 11 | * @author: wanghao 12 | * @date: 2018年5月4日 上午9:58:15 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableEurekaClient 18 | @EnableZipkinServer 19 | public class ZipkinApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(ZipkinApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/spring-cloud-eureka-registry/src/main/java/com/peterwanghao/spring/cloud/eureka/registry/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.registry; 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 | /** 8 | * @ClassName: EurekaServerApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年8月20日 上午10:33:09 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class EurekaServerApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(EurekaServerApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/main/java/org/peterwanghao/zuul/ui/UiApplication.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.ui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.web.support.SpringBootServletInitializer; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | /** 9 | * @ClassName: UiApplication 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年9月11日 上午9:58:33 13 | * @version V1.0 14 | * 15 | */ 16 | @EnableZuulProxy 17 | @SpringBootApplication 18 | public class UiApplication extends SpringBootServletInitializer{ 19 | public static void main(String[] args) { 20 | SpringApplication.run(UiApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-security/config-secure/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=config 2 | server.port=8081 3 | 4 | #配置Git仓库位置 5 | spring.cloud.config.server.git.uri=ssh://admin@localhost:29418/Test.git 6 | #配置仓库路径下的相对搜索位置,可以配置多个 7 | spring.cloud.config.server.git.searchPaths=application-config-secure 8 | #配置为true表示启动时就克隆配置缓存到本地。 9 | spring.cloud.config.server.git.clone-on-start=true 10 | #访问Git仓库的用户名 11 | spring.cloud.config.server.git.username=admin 12 | #访问Git仓库的用户密码 13 | spring.cloud.config.server.git.password=admin 14 | 15 | eureka.client.region = default 16 | eureka.client.registryFetchIntervalSeconds = 5 17 | eureka.client.serviceUrl.defaultZone=http://discUser:discPassword@localhost:8082/eureka/ 18 | 19 | security.user.name=configUser 20 | security.user.password=configPassword 21 | security.user.role=SYSTEM -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceConsumer/src/main/java/com/peterwanghao/spring/cloud/greeting/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.greeting; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @ClassName: GreetingController 9 | * @Description:本地Web应用接口,调用HelloWorld服务客户端 10 | * @author: wanghao 11 | * @date: 2018年3月23日 下午5:46:19 12 | * @version V1.0 13 | * 14 | */ 15 | @RestController 16 | public class GreetingController { 17 | @Autowired 18 | private HelloWorldClient helloWorldClient; 19 | 20 | @GetMapping("/get-greeting") 21 | public String greeting() { 22 | 23 | return helloWorldClient.HelloWorld(); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-stream/src/main/java/com/peterwanghao/spring/cloud/task/SpringCloudTaskSinkApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.task; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.task.launcher.annotation.EnableTaskLauncher; 6 | 7 | /** 8 | * @ClassName: SpringCloudTaskSinkApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年10月12日 下午2:45:54 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableTaskLauncher 17 | public class SpringCloudTaskSinkApplication { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(SpringCloudTaskSinkApplication.class, args); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/zuul-server/src/main/java/com/baeldung/spring/cloud/zuul/ZuulApplication.java: -------------------------------------------------------------------------------- 1 | package com.baeldung.spring.cloud.zuul; 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.netflix.zuul.EnableZuulProxy; 7 | 8 | /** 9 | * @ClassName: ZuulApplication 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年9月17日 下午4:59:44 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableZuulProxy 18 | @EnableDiscoveryClient 19 | public class ZuulApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(ZuulApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/main/java/com/peterwanghao/spring/cloud/contract/producer/controller/EvenOddController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.contract.producer.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @ClassName: EvenOddController 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2019年1月10日 下午3:50:55 12 | * @version V1.0 13 | * 14 | */ 15 | @RestController 16 | public class EvenOddController { 17 | @GetMapping("/validate/prime-number") 18 | public String isNumberPrime(@RequestParam("number") Integer number) { 19 | return number % 2 == 0 ? "Even" : "Odd"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/GreetingClient.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | 8 | /** 9 | * @ClassName: GreetingClient 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年8月15日 下午5:03:25 13 | * @version V1.0 14 | * 15 | */ 16 | @FeignClient(name = "rest-producer", url = "http://localhost:9090", fallback = GreetingClientFallback.class) 17 | public interface GreetingClient { 18 | @RequestMapping("/greeting/{username}") 19 | String greeting(@PathVariable("username") String username); 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-client/src/main/java/com/peterwanghao/spring/cloud/consul/client/DiscoveryClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.client; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @ClassName: DiscoveryClientApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年12月6日 下午2:24:36 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableDiscoveryClient 17 | public class DiscoveryClientApplication { 18 | public static void main(String[] args) { 19 | new SpringApplicationBuilder(DiscoveryClientApplication.class).web(true).run(args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/gateway/src/main/java/com/peterwanghao/spring/cloud/bootstrap/gateway/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.gateway; 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 | /** 9 | * @ClassName: GatewayApplication 10 | * @Description:微服务网关 11 | * @author: wanghao 12 | * @date: 2018年4月25日 下午1:11:59 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableZuulProxy 18 | @EnableEurekaClient 19 | public class GatewayApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(GatewayApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-server/src/main/java/com/peterwanghao/spring/cloud/eureka/server/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.server; 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 | /** 8 | * @ClassName: EurekaServerApplication 9 | * @Description:微服务框架Spring Cloud Netflix Eureka 实现的服务注册中心 10 | * @author: wanghao 11 | * @date: 2018年3月14日 下午3:38:29 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class EurekaServerApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(EurekaServerApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-ribbon-client/src/test/java/com/peterwanghao/spring/cloud/ribbon/client/TestServiceProvider.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.ribbon.client; 2 | 3 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassName: TestConfig 10 | * @Description:服务提供者,提供一个定位服务 11 | * @author: wanghao 12 | * @date: 2018年3月28日 下午2:21:25 13 | * @version V1.0 14 | * 15 | */ 16 | @Configuration 17 | @EnableAutoConfiguration 18 | @RestController 19 | public class TestServiceProvider { 20 | 21 | @RequestMapping(value = "/locate") 22 | public String locationDetails() { 23 | return "Beijing"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/java/org/peterwanghao/zuul/resource/config/ResourceServerWebConfig.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.resource.config; 2 | 3 | import org.springframework.context.annotation.ComponentScan; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 7 | 8 | /** 9 | * @ClassName: ResourceServerWebConfig 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年9月11日 上午9:34:23 13 | * @version V1.0 14 | * 15 | */ 16 | @Configuration 17 | @EnableWebMvc 18 | @ComponentScan({ "org.peterwanghao.zuul.resource.web.controller" }) 19 | public class ResourceServerWebConfig extends WebMvcConfigurerAdapter { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/src/main/java/com/peterwanghao/spring/cloud/consul/properties/DistributedPropertiesApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.properties; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @ClassName: DistributedPropertiesApplication 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年12月6日 下午2:29:21 12 | * @version V1.0 13 | * 14 | */ 15 | @SpringBootApplication 16 | @RestController 17 | public class DistributedPropertiesApplication { 18 | public static void main(String[] args) { 19 | new SpringApplicationBuilder(DistributedPropertiesApplication.class).web(true).run(args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-security/gateway-secure/src/main/java/com/peterwanghao/spring/cloud/security/gateway/GatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.gateway; 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 | /** 9 | * @ClassName: GatewayApplication 10 | * @Description:微服务网关 11 | * @author: wanghao 12 | * @date: 2018年5月2日 上午10:18:43 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableZuulProxy 18 | @EnableEurekaClient 19 | public class GatewayApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(GatewayApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/src/main/java/com/peterwanghao/spring/cloud/consul/properties/MyProperties.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.properties; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @ClassName: MyProperties 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年12月6日 下午2:28:16 12 | * @version V1.0 13 | * 14 | */ 15 | @RefreshScope 16 | @Configuration 17 | @ConfigurationProperties("my") 18 | public class MyProperties { 19 | private String prop; 20 | 21 | public String getProp() { 22 | return prop; 23 | } 24 | 25 | public void setProp(String prop) { 26 | this.prop = prop; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/config/WebMvcConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | /** 8 | * @ClassName: WebMvcConfigurer 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年7月25日 下午5:00:26 12 | * @version V1.0 13 | * 14 | */ 15 | @Configuration 16 | public class WebMvcConfigurer extends WebMvcConfigurerAdapter { 17 | 18 | @Override 19 | public void addViewControllers(ViewControllerRegistry registry) { 20 | registry.addViewController("login").setViewName("login"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-security/gateway-secure/src/main/java/com/peterwanghao/spring/cloud/security/gateway/SessionConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.gateway; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.session.data.redis.RedisFlushMode; 5 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 6 | import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer; 7 | 8 | /** 9 | * @ClassName: SessionConfig 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年5月2日 上午11:16:45 13 | * @version V1.0 14 | * 15 | */ 16 | @Configuration 17 | @EnableRedisHttpSession(redisFlushMode = RedisFlushMode.IMMEDIATE) 18 | public class SessionConfig extends AbstractHttpSessionApplicationInitializer { 19 | } 20 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/application-config/gateway.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=gateway 2 | server.port=8080 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 6 | 7 | zuul.routes.book-service.path=/book-service/** 8 | zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization 9 | hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000 10 | 11 | zuul.routes.rating-service.path=/rating-service/** 12 | zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization 13 | hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000 14 | 15 | zuul.routes.discovery.path=/discovery/** 16 | zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization 17 | zuul.routes.discovery.url=http://localhost:8082 18 | hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000 -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server/src/main/java/com/peterwanghao/spring/cloud/oauth/authserver/config/WebMvcConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authserver.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | /** 8 | * @ClassName: WebMvcConfigurer 9 | * @Description:TODO(这里用一句话描述这个类的作用) 10 | * @author: wanghao 11 | * @date: 2018年7月19日 下午2:13:01 12 | * @version V1.0 13 | * 14 | */ 15 | @Configuration 16 | public class WebMvcConfigurer extends WebMvcConfigurerAdapter { 17 | 18 | @Override 19 | public void addViewControllers(ViewControllerRegistry registry) { 20 | registry.addViewController("login").setViewName("login"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.peterwanghao.spring.cloud 5 | spring-cloud-examples 6 | 0.0.1-SNAPSHOT 7 | 8 | spring-cloud-hystrix 9 | pom 10 | spring-cloud-hystrix 11 | 熔断器 12 | 13 | rest-producer 14 | rest-consumer 15 | feign-rest-consumer 16 | spring-cloud-eureka-registry 17 | hystrix-dashboard-turbine 18 | 19 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/peterwanghao/spring/cloud/stream/rabbit/processor/MyProcessor.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.stream.rabbit.processor; 2 | 3 | import org.springframework.cloud.stream.annotation.Input; 4 | import org.springframework.cloud.stream.annotation.Output; 5 | import org.springframework.messaging.MessageChannel; 6 | import org.springframework.messaging.SubscribableChannel; 7 | 8 | /** 9 | * @ClassName: MyProcessor 10 | * @Description:自定义处理器,创建一个输入两个输出的通道 11 | * @author: wanghao 12 | * @date: 2018年5月11日 上午10:43:42 13 | * @version V1.0 14 | * 15 | */ 16 | public interface MyProcessor { 17 | String INPUT = "myInput"; 18 | 19 | @Input 20 | SubscribableChannel myInput(); 21 | 22 | @Output("myOutput") 23 | MessageChannel anOutput(); 24 | 25 | @Output 26 | MessageChannel anotherOutput(); 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/java/org/peterwanghao/zuul/resource/web/dto/Foo.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.resource.web.dto; 2 | 3 | /** 4 | * @ClassName: Foo 5 | * @Description:TODO(这里用一句话描述这个类的作用) 6 | * @author: wanghao 7 | * @date: 2018年9月11日 上午9:36:53 8 | * @version V1.0 9 | * 10 | */ 11 | public class Foo { 12 | private long id; 13 | private String name; 14 | 15 | public Foo() { 16 | super(); 17 | } 18 | 19 | public Foo(final long id, final String name) { 20 | super(); 21 | 22 | this.id = id; 23 | this.name = name; 24 | } 25 | 26 | public long getId() { 27 | return id; 28 | } 29 | 30 | public void setId(final long id) { 31 | this.id = id; 32 | } 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(final String name) { 39 | this.name = name; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Peter Spring cloud Security OAuth 6 | 7 | 8 | 9 |

Login

10 | 11 | 12 |
13 |
14 |

Username and Password:

15 |

16 | 17 | 18 |

19 |

20 | 21 | 22 |

23 |

24 | 25 |

26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Peter Spring cloud Security OAuth 6 | 7 | 8 | 9 |

Login

10 | 11 | 12 |
13 |
14 |

Username and Password:

15 |

16 | 17 | 18 |

19 |

20 | 21 | 22 |

23 |

24 | 25 |

26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Make the application available at http://localhost:9000 2 | 3 | server: 4 | port: 9000 5 | 6 | # Configure the public key to use for verifying the incoming JWT tokens 7 | security: 8 | sessions: NEVER 9 | oauth2: 10 | resource: 11 | jwt: 12 | keyValue: | 13 | -----BEGIN PUBLIC KEY----- 14 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhiiifKv6Otf5PyqIE+LQ 15 | EiJRRh6q8piPY9Okq+RfRu9Bue0D8hq7aFxcgkLZ6Bg9CAS+w1KdaE5MMeOCVVxv 16 | rpRETzVpAsh6GL5nBc679jSqMzjr3V4uty46ilL4VHKSxlZh5Nmz5EMHPI5iwpNs 17 | 8U5n3QiwsTk514FXad54xPSPH3i/pDzGSZHrVcwDVaOKn7gFiIqP86vkJB47JZv8 18 | T6P5RK7Rj06zoG45DMGWG3DQv6o1/Jm4IJQWj0AUD3bSHqzXkPr7qyMYvkE4kyMH 19 | 6aVAsAYMxilZFlJMv2b8N883gdi3LEeOJo8zZr5IWyyROfepdeOL7UkAXddAj+dL 20 | WQIDAQAB 21 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /spring-cloud-security/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.peterwanghao.spring.cloud 5 | spring-cloud-examples 6 | 0.0.1-SNAPSHOT 7 | 8 | spring-cloud-security 9 | pom 10 | spring-cloud-security 11 | Spring Cloud 服务安全防护 12 | 13 | config-secure 14 | discovery-secure 15 | gateway-secure 16 | book-service-secure 17 | rating-service-secure 18 | zipkin 19 | 20 | -------------------------------------------------------------------------------- /spring-cloud-vault/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | vault: 4 | uri: https://localhost:8200 5 | connection-timeout: 5000 6 | read-timeout: 15000 7 | config: 8 | order: -10 9 | 10 | ssl: 11 | trust-store: classpath:/vault.jks 12 | trust-store-password: changeit 13 | 14 | generic: 15 | enabled: true 16 | application-name: fakebank 17 | 18 | kv: 19 | enabled: false 20 | backend: kv 21 | application-name: fakebank 22 | 23 | database: 24 | enabled: true 25 | role: fakebank-accounts-ro 26 | backend: database 27 | username-property: spring.datasource.username 28 | password-property: spring.datasource.password 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/AuthClient.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | import com.peterwanghao.spring.cloud.oauth.authclient.filters.SimpleFilter; 8 | 9 | /** 10 | * @ClassName: Application 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年7月19日 下午3:21:27 14 | * @version V1.0 15 | * 16 | */ 17 | @SpringBootApplication 18 | public class AuthClient { 19 | public static void main(String[] args) { 20 | SpringApplication.run(AuthClient.class, args); 21 | } 22 | 23 | @Bean 24 | public SimpleFilter simpleFilter() { 25 | return new SimpleFilter(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/hystrix-dashboard-turbine/src/main/java/com/peterwanghao/spring/cloud/hystrix/turbine/DashboardTurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.turbine; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 7 | 8 | /** 9 | * @ClassName: DashboardTurbineApplication 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年8月20日 下午2:48:17 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableHystrixDashboard 18 | @EnableTurbine 19 | public class DashboardTurbineApplication { 20 | public static void main(String[] args) { 21 | SpringApplication.run(DashboardTurbineApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/AuthClient2.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | import com.peterwanghao.spring.cloud.oauth.authclient.filters.SimpleFilter; 8 | 9 | /** 10 | * @ClassName: Application 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年7月19日 下午3:21:27 14 | * @version V1.0 15 | * 16 | */ 17 | @SpringBootApplication 18 | public class AuthClient2 { 19 | public static void main(String[] args) { 20 | SpringApplication.run(AuthClient2.class, args); 21 | } 22 | 23 | @Bean 24 | public SimpleFilter simpleFilter() { 25 | return new SimpleFilter(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/peterwanghao/spring/cloud/stream/rabbit/model/LogMessage.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.stream.rabbit.model; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @ClassName: LogMessage 7 | * @Description:消息类 8 | * @author: wanghao 9 | * @date: 2018年5月11日 上午10:33:55 10 | * @version V1.0 11 | * 12 | */ 13 | public class LogMessage implements Serializable { 14 | 15 | private static final long serialVersionUID = 1194171350176151128L; 16 | private String message; 17 | 18 | public LogMessage() { 19 | 20 | } 21 | 22 | public LogMessage(String message) { 23 | this.message = message; 24 | } 25 | 26 | public String getMessage() { 27 | return message; 28 | } 29 | 30 | public void setMessage(String message) { 31 | this.message = message; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return message; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | /** Oauth - populate the oauth_client_details table */ 2 | INSERT INTO `oauth_client_details` (`client_id`, `client_secret`, `scope`, `authorized_grant_types`, `web_server_redirect_uri`, `access_token_validity`, `refresh_token_validity`, `additional_information`, `autoapprove`) 3 | VALUES 4 | ('second', 'passwordforauthserver', 'read', 'authorization_code,password,refresh_token,implicit', 'http://localhost:8081/', '30', '1800', '{}', 'true') 5 | ON DUPLICATE key UPDATE 6 | client_secret = VALUES(`client_secret`), 7 | scope = VALUES(`scope`), 8 | authorized_grant_types = VALUES(`authorized_grant_types`), 9 | access_token_validity = VALUES(`access_token_validity`), 10 | additional_information = VALUES(`additional_information`); 11 | 12 | INSERT INTO `oauth_example`.`account` (`id`, `password`, `username`) VALUES (' 1 ', 'user', 'user') 13 | ON DUPLICATE key UPDATE 14 | password = VALUES(`password`), 15 | username = VALUES(`username`); 16 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/GreetingService.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 2 | 3 | import org.springframework.stereotype.Service; 4 | import org.springframework.web.client.RestTemplate; 5 | 6 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 7 | 8 | /** 9 | * @ClassName: GreetingService 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年8月15日 下午4:40:56 13 | * @version V1.0 14 | * 15 | */ 16 | @Service 17 | public class GreetingService { 18 | @HystrixCommand(fallbackMethod = "defaultGreeting") 19 | public String getGreeting(String username) { 20 | return new RestTemplate().getForObject("http://localhost:9090/greeting/{username}", String.class, username); 21 | } 22 | 23 | @SuppressWarnings("unused") 24 | private String defaultGreeting(String username) { 25 | return "Hello User!"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-security/application-config-secure/gateway.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=gateway 2 | server.port=8080 3 | 4 | eureka.client.region = default 5 | eureka.client.registryFetchIntervalSeconds = 5 6 | 7 | management.security.sessions=always 8 | 9 | zuul.routes.book-service.path=/book-service/** 10 | zuul.routes.book-service.sensitive-headers=Set-Cookie,Authorization 11 | hystrix.command.book-service.execution.isolation.thread.timeoutInMilliseconds=600000 12 | 13 | zuul.routes.rating-service.path=/rating-service/** 14 | zuul.routes.rating-service.sensitive-headers=Set-Cookie,Authorization 15 | hystrix.command.rating-service.execution.isolation.thread.timeoutInMilliseconds=600000 16 | 17 | zuul.routes.discovery.path=/discovery/** 18 | zuul.routes.discovery.sensitive-headers=Set-Cookie,Authorization 19 | zuul.routes.discovery.url=http://localhost:8082 20 | hystrix.command.discovery.execution.isolation.thread.timeoutInMilliseconds=600000 21 | 22 | spring.redis.host=localhost 23 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-consumer/src/main/java/com/peterwanghao/spring/cloud/contract/consumer/SpringCloudContractConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.contract.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | /** 9 | * @ClassName: SpringCloudContractConsumerApplication 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2019年1月10日 下午5:14:16 13 | * @version V1.0 14 | * 15 | */ 16 | @SpringBootApplication 17 | public class SpringCloudContractConsumerApplication { 18 | public static void main(String[] args) { 19 | SpringApplication.run(SpringCloudContractConsumerApplication.class, args); 20 | } 21 | 22 | @Bean 23 | RestTemplate restTemplate() { 24 | return new RestTemplate(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/src/main/java/com/peterwanghao/spring/cloud/archaius/dynamodb/entity/ArchaiusProperties.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.dynamodb.entity; 2 | 3 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; 4 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 5 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 6 | 7 | import lombok.AllArgsConstructor; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | 11 | /** 12 | * @ClassName: ArchaiusProperties 13 | * @Description:TODO(这里用一句话描述这个类的作用) 14 | * @author: wanghao 15 | * @date: 2018年11月20日 下午4:55:46 16 | * @version V1.0 17 | * 18 | */ 19 | @Getter 20 | @Setter 21 | @AllArgsConstructor 22 | @DynamoDBTable(tableName = "archaiusProperties") 23 | public class ArchaiusProperties { 24 | 25 | @DynamoDBHashKey 26 | @DynamoDBAttribute 27 | private String key; 28 | 29 | @DynamoDBAttribute 30 | private String value; 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/test/java/org/peterwanghao/zuul/ui/LiveTest.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.ui; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import io.restassured.RestAssured; 8 | import io.restassured.response.Response; 9 | 10 | /** 11 | * @ClassName: LiveTest 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年9月11日 上午10:09:51 15 | * @version V1.0 16 | * 17 | */ 18 | public class LiveTest { 19 | @Test 20 | public void whenSendRequestToFooResource_thenOK() { 21 | final Response response = RestAssured.get("http://localhost:8080/foos/1"); 22 | assertEquals(200, response.getStatusCode()); 23 | } 24 | 25 | @Test 26 | public void whenSendRequest_thenHeaderAdded() { 27 | final Response response = RestAssured.get("http://localhost:8080/foos/1"); 28 | assertEquals(200, response.getStatusCode()); 29 | assertEquals("TestSample", response.getHeader("Test")); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-service/src/main/java/com/peterwanghao/spring/cloud/consul/service/ServiceDiscoveryController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.service; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassName: ServiceDiscoveryController 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年12月6日 下午2:22:07 13 | * @version V1.0 14 | * 15 | */ 16 | @RestController 17 | public class ServiceDiscoveryController { 18 | @GetMapping("/ping") 19 | public String ping() { 20 | return " Service ping"; 21 | } 22 | 23 | @GetMapping("/my-health-check") 24 | public ResponseEntity myCustomCheck() { 25 | String message = "Testing my healh check function"; 26 | return new ResponseEntity<>(message, HttpStatus.FORBIDDEN); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/producer/GreetingControllerImpl.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.producer; 2 | 3 | import org.springframework.web.bind.annotation.PathVariable; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * @ClassName: GreetingControllerImpl 8 | * @Description:TODO(这里用一句话描述这个类的作用) 9 | * @author: wanghao 10 | * @date: 2018年8月15日 下午4:24:48 11 | * @version V1.0 12 | * 13 | */ 14 | @RestController 15 | public class GreetingControllerImpl implements GreetingController { 16 | 17 | /** 18 | *

Title: greeting

19 | *

Description:

20 | * @param username 21 | * @return 22 | * @see com.peterwanghao.spring.cloud.hystrix.rest.producer.GreetingController#greeting(java.lang.String) 23 | */ 24 | @Override 25 | public String greeting(@PathVariable("username") String username) { 26 | return String.format("Hello %s!\n", username); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/RestConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 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 | /** 10 | * @ClassName: RestConsumerApplication 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年8月15日 下午4:39:33 14 | * @version V1.0 15 | * 16 | */ 17 | @SpringBootApplication 18 | @EnableEurekaClient 19 | @EnableCircuitBreaker 20 | @EnableHystrixDashboard 21 | public class RestConsumerApplication { 22 | public static void main(String[] args) { 23 | SpringApplication.run(RestConsumerApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/java/com/peterwanghao/spring/cloud/oauth/authresource/controller/PersonInfoController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authresource.controller; 2 | 3 | import org.springframework.security.access.prepost.PreAuthorize; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.peterwanghao.spring.cloud.oauth.authresource.model.Person; 9 | 10 | /** 11 | * @ClassName: PersonInfoController 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午2:43:05 15 | * @version V1.0 16 | * 17 | */ 18 | @RestController 19 | public class PersonInfoController { 20 | 21 | @GetMapping("/person") 22 | @PreAuthorize("hasAnyRole('ADMIN', 'USER')") 23 | public @ResponseBody Person personInfo() { 24 | return new Person("peter", "Beijing", "China", 29, "Male"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-archaius 8 | 0.0.1-SNAPSHOT 9 | 10 | jdbc-config 11 | jdbc-config 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-web 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-data-jpa 21 | 22 | 23 | com.h2database 24 | h2 25 | runtime 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.Model; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * @ClassName: GreetingController 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年8月15日 下午5:00:42 14 | * @version V1.0 15 | * 16 | */ 17 | @Controller 18 | public class GreetingController { 19 | @Autowired 20 | private GreetingClient greetingClient; 21 | 22 | @RequestMapping("/get-greeting/{username}") 23 | public String getGreeting(Model model, @PathVariable("username") String username) { 24 | model.addAttribute("greeting", greetingClient.greeting(username)); 25 | return "greeting-view"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/GreetingController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.Model; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * @ClassName: GreetingController 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年8月15日 下午4:42:40 14 | * @version V1.0 15 | * 16 | */ 17 | @Controller 18 | public class GreetingController { 19 | @Autowired 20 | private GreetingService greetingService; 21 | 22 | @RequestMapping("/get-greeting/{username}") 23 | public String getGreeting(Model model, @PathVariable("username") String username) { 24 | model.addAttribute("greeting", greetingService.getGreeting(username)); 25 | return "greeting-view"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-security/rating-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcrating/Rating.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcrating; 2 | 3 | /** 4 | * @ClassName: Rating 5 | * @Description:评分对象类 6 | * @author: wanghao 7 | * @date: 2018年5月2日 上午10:35:11 8 | * @version V1.0 9 | * 10 | */ 11 | public class Rating { 12 | private Long id; 13 | private Long bookId; 14 | private int stars; 15 | 16 | public Rating() { 17 | } 18 | 19 | public Rating(Long id, Long bookId, int stars) { 20 | this.id = id; 21 | this.bookId = bookId; 22 | this.stars = stars; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public Long getBookId() { 34 | return bookId; 35 | } 36 | 37 | public void setBookId(Long bookId) { 38 | this.bookId = bookId; 39 | } 40 | 41 | public int getStars() { 42 | return stars; 43 | } 44 | 45 | public void setStars(int stars) { 46 | this.stars = stars; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/book-service/src/main/java/com/peterwanghao/spring/cloud/bootstrap/svcbook/Book.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.svcbook; 2 | 3 | /** 4 | * @ClassName: Book 5 | * @Description:图书对象类 6 | * @author: wanghao 7 | * @date: 2018年4月25日 下午1:40:26 8 | * @version V1.0 9 | * 10 | */ 11 | public class Book { 12 | private Long id; 13 | private String author; 14 | private String title; 15 | 16 | public Book() { 17 | } 18 | 19 | public Book(Long id, String author, String title) { 20 | this.id = id; 21 | this.author = author; 22 | this.title = title; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getAuthor() { 34 | return author; 35 | } 36 | 37 | public void setAuthor(String author) { 38 | this.author = author; 39 | } 40 | 41 | public String getTitle() { 42 | return title; 43 | } 44 | 45 | public void setTitle(String title) { 46 | this.title = title; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-cloud-security/book-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcbook/Book.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcbook; 2 | 3 | /** 4 | * @ClassName: Book 5 | * @Description:图书对象类 6 | * @author: wanghao 7 | * @date: 2018年5月2日 上午10:26:50 8 | * @version V1.0 9 | * 10 | */ 11 | public class Book { 12 | private Long id; 13 | private String author; 14 | private String title; 15 | 16 | public Book() { 17 | } 18 | 19 | public Book(Long id, String author, String title) { 20 | this.id = id; 21 | this.author = author; 22 | this.title = title; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getAuthor() { 34 | return author; 35 | } 36 | 37 | public void setAuthor(String author) { 38 | this.author = author; 39 | } 40 | 41 | public String getTitle() { 42 | return title; 43 | } 44 | 45 | public void setTitle(String title) { 46 | this.title = title; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/rating-service/src/main/java/com/peterwanghao/spring/cloud/bootstrap/svcrating/Rating.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.svcrating; 2 | 3 | /** 4 | * @ClassName: Rating 5 | * @Description:TODO(这里用一句话描述这个类的作用) 6 | * @author: wanghao 7 | * @date: 2018年4月25日 下午2:13:50 8 | * @version V1.0 9 | * 10 | */ 11 | public class Rating { 12 | private Long id; 13 | private Long bookId; 14 | private int stars; 15 | 16 | public Rating() { 17 | } 18 | 19 | public Rating(Long id, Long bookId, int stars) { 20 | this.id = id; 21 | this.bookId = bookId; 22 | this.stars = stars; 23 | } 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public Long getBookId() { 34 | return bookId; 35 | } 36 | 37 | public void setBookId(Long bookId) { 38 | this.bookId = bookId; 39 | } 40 | 41 | public int getStars() { 42 | return stars; 43 | } 44 | 45 | public void setStars(int stars) { 46 | this.stars = stars; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/src/main/java/com/peterwanghao/spring/cloud/consul/properties/DistributedPropertiesController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.consul.properties; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @ClassName: DistributedPropertiesController 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年12月6日 下午2:30:13 13 | * @version V1.0 14 | * 15 | */ 16 | @RestController 17 | public class DistributedPropertiesController { 18 | @Value("${my.prop}") 19 | String value; 20 | 21 | @Autowired 22 | private MyProperties properties; 23 | 24 | @GetMapping("/getConfigFromValue") 25 | public String getConfigFromValue() { 26 | return value; 27 | } 28 | 29 | @GetMapping("/getConfigFromProperty") 30 | public String getConfigFromProperty() { 31 | return properties.getProp(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/main/java/org/peterwanghao/zuul/ui/config/CustomZuulFilter.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.ui.config; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import com.netflix.zuul.ZuulFilter; 6 | import com.netflix.zuul.context.RequestContext; 7 | 8 | /** 9 | * @ClassName: CustomZuulFilter 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年9月11日 上午10:02:13 13 | * @version V1.0 14 | * 15 | */ 16 | @Component 17 | public class CustomZuulFilter extends ZuulFilter { 18 | @Override 19 | public Object run() { 20 | final RequestContext ctx = RequestContext.getCurrentContext(); 21 | ctx.addZuulRequestHeader("Test", "TestSample"); 22 | return null; 23 | } 24 | 25 | @Override 26 | public boolean shouldFilter() { 27 | return true; 28 | } 29 | 30 | @Override 31 | public int filterOrder() { 32 | return 1110; 33 | } 34 | 35 | @Override 36 | public String filterType() { 37 | return "pre"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-cloud-ribbon-client/src/main/java/com/peterwanghao/spring/cloud/ribbon/client/RibbonConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.ribbon.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | 6 | import com.netflix.client.config.IClientConfig; 7 | import com.netflix.loadbalancer.IPing; 8 | import com.netflix.loadbalancer.IRule; 9 | import com.netflix.loadbalancer.PingUrl; 10 | import com.netflix.loadbalancer.WeightedResponseTimeRule; 11 | 12 | /** 13 | * @ClassName: RibbonConfiguration 14 | * @Description:负载均衡配置 15 | * @author: wanghao 16 | * @date: 2018年3月28日 下午2:10:59 17 | * @version V1.0 18 | * 19 | */ 20 | public class RibbonConfiguration { 21 | @Autowired 22 | IClientConfig ribbonClientConfig; 23 | 24 | // 判断服务实例是否有效,ping某个url判断其是否alive 25 | @Bean 26 | public IPing ribbonPing(IClientConfig config) { 27 | return new PingUrl(); 28 | } 29 | 30 | // 负载均衡策略,根据服务实例的运行情况来计算权重 31 | @Bean 32 | public IRule ribbonRule(IClientConfig config) { 33 | return new WeightedResponseTimeRule(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-client/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-consul 8 | 0.0.1-SNAPSHOT 9 | 10 | consul-client 11 | consul-client 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-consul-all 16 | ${spring-cloud-starter-consul.version} 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-test 22 | test 23 | 24 | 25 | 26 | 27 | 1.3.0.RELEASE 28 | 29 | -------------------------------------------------------------------------------- /spring-cloud-sleuth/src/main/java/com/peterwanghao/spring/cloud/sleuth/SchedulingService.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.sleuth; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.scheduling.annotation.Scheduled; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * @ClassName: SchedulingService 11 | * @Description:定时服务 12 | * @author: wanghao 13 | * @date: 2018年4月11日 下午2:18:09 14 | * @version V1.0 15 | * 16 | */ 17 | @Service 18 | public class SchedulingService { 19 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 20 | private final SleuthService sleuthService; 21 | 22 | @Autowired 23 | public SchedulingService(SleuthService sleuthService) { 24 | this.sleuthService = sleuthService; 25 | } 26 | 27 | @Scheduled(fixedDelay = 30000) 28 | public void scheduledWork() throws InterruptedException { 29 | logger.info("Start some work from the scheduled task"); 30 | sleuthService.asyncMethod(); 31 | logger.info("End work from scheduled task"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/feign-rest-consumer/src/main/java/com/peterwanghao/spring/cloud/hystrix/rest/consumer/RestConsumerFeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.hystrix.rest.consumer; 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.feign.EnableFeignClients; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | 10 | /** 11 | * @ClassName: RestConsumerFeignApplication 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年8月15日 下午4:58:22 15 | * @version V1.0 16 | * 17 | */ 18 | @SpringBootApplication 19 | @EnableEurekaClient 20 | @EnableFeignClients 21 | @EnableCircuitBreaker 22 | @EnableHystrixDashboard 23 | public class RestConsumerFeignApplication { 24 | public static void main(String[] args) { 25 | SpringApplication.run(RestConsumerFeignApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-task/spring-cloud-task-batch/src/main/java/com/peterwanghao/spring/cloud/task/TaskListener.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.task; 2 | 3 | import java.util.logging.Logger; 4 | 5 | import org.springframework.cloud.task.listener.TaskExecutionListener; 6 | import org.springframework.cloud.task.repository.TaskExecution; 7 | 8 | /** 9 | * @ClassName: TaskListener 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年10月12日 下午1:50:47 13 | * @version V1.0 14 | * 15 | */ 16 | public class TaskListener implements TaskExecutionListener { 17 | 18 | private final static Logger LOGGER = Logger.getLogger(TaskListener.class.getName()); 19 | 20 | @Override 21 | public void onTaskEnd(TaskExecution arg0) { 22 | // TODO Auto-generated method stub 23 | LOGGER.info("End of Task"); 24 | } 25 | 26 | @Override 27 | public void onTaskFailed(TaskExecution arg0, Throwable arg1) { 28 | // TODO Auto-generated method stub 29 | 30 | } 31 | 32 | @Override 33 | public void onTaskStartup(TaskExecution arg0) { 34 | // TODO Auto-generated method stub 35 | LOGGER.info("Task Startup"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-vault/vault-config/localhost.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIC+zCCAeOgAwIBAgIJAKoy5OBgOKYwMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV 3 | BAMMCWxvY2FsaG9zdDAeFw0xODA4MDkwMTM1MzJaFw0yODA4MDYwMTM1MzJaMBQx 4 | EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC 5 | ggEBAMXiHqB5dYdxJ1+abSG55gb3NNo3fzNbkjp/tAIl1FUeyCyyP/yERrkUkhFj 6 | 4gg/q1YHUO/ftc0PdL/JBaVBTKnzsxgp7hY/dUEkZqXZ649X0UrJIRd13w5N71cL 7 | P1+PjCrqokMVceU18kK7CyaOmiTKYFmt/RTJQLmFQspmJXNSiq7zUvAgyvoY5TzJ 8 | n7MuSobHXq17pnlm+XbnAgDJUt9yR6BC2dFF20iZU4uTXy2VRngfLey3p+6in0TO 9 | jD4cEMJqwgUbjiI8m/hESCketVkq0W0qkkVfWBNzz5qqGHNRbhZBwT7SM0MuXum+ 10 | qEY7n7jcQAk5BDb613liVQjQ0tkCAwEAAaNQME4wHQYDVR0OBBYEFHYjQ0/HJgXd 11 | BnqM4jLPjmygfi8fMB8GA1UdIwQYMBaAFHYjQ0/HJgXdBnqM4jLPjmygfi8fMAwG 12 | A1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBABSf++sinLT9dFnC+B6ut5Zp 13 | haTL7PA1/CdmhTdE2vlFPGGw2BD4c/gphBsHKSNHE96irTqFXI/kl6labQpZ5P8G 14 | JORLfaAyl58UT1FayxL4ISzwsp+UrqO60vxkYyLkbEJjuaxIv11oOoFDIp5oBTqe 15 | BVoCfcTjYtTr+IwwlypLPrVTnDNGX5oPIBbTUFvR0t5RaLZgmXLT78ERhWOLINqh 16 | Yi6j7fYaRm/C5IQ8N/TASot7V0SMH2Rt6PrzJb5SLV8r+yozg2BSfU6hZUyKwABR 17 | N3zppKvKzdhlVo9OuSW3x4Tb3V+CVE/8CmTwRfhab9SCmvmaa2FxI+8/2OPVWDU= 18 | -----END CERTIFICATE----- 19 | -------------------------------------------------------------------------------- /spring-cloud-archaius/simple_config/src/main/java/com/peterwanghao/spring/cloud/archaius/simple/config/ApplicationPropertiesConfigurations.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.simple.config; 2 | 3 | import org.apache.commons.configuration.AbstractConfiguration; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import com.netflix.config.DynamicConfiguration; 8 | import com.netflix.config.FixedDelayPollingScheduler; 9 | import com.netflix.config.PolledConfigurationSource; 10 | import com.netflix.config.sources.URLConfigurationSource; 11 | 12 | /** 13 | * @ClassName: ApplicationPropertiesConfigurations 14 | * @Description:TODO(这里用一句话描述这个类的作用) 15 | * @author: wanghao 16 | * @date: 2018年11月7日 下午3:49:58 17 | * @version V1.0 18 | * 19 | */ 20 | @Configuration 21 | public class ApplicationPropertiesConfigurations { 22 | @Bean 23 | public AbstractConfiguration addApplicationPropertiesSource() { 24 | PolledConfigurationSource source = new URLConfigurationSource("classpath:other-config.properties"); 25 | return new DynamicConfiguration(source, new FixedDelayPollingScheduler()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | com.peterwanghao.spring.cloud 5 | spring-cloud-consul 6 | 0.0.1-SNAPSHOT 7 | 8 | consul-service 9 | consul-service 10 | 11 | 12 | 13 | org.springframework.cloud 14 | spring-cloud-starter-consul-all 15 | ${spring-cloud-starter-consul.version} 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-test 21 | test 22 | 23 | 24 | 25 | 26 | 1.3.0.RELEASE 27 | 28 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Make the application available at http://localhost:8080 2 | # These are default settings, but we add them for clarity. 3 | server: 4 | port: 8080 5 | contextPath: / 6 | 7 | # Configure the Authorization Server and User Info Resource Server details 8 | security: 9 | oauth2: 10 | client: 11 | accessTokenUri: http://localhost:7070/authserver/oauth/token 12 | userAuthorizationUri: http://localhost:7070/authserver/oauth/authorize 13 | clientId: first 14 | clientSecret: passwordforauthserver 15 | resource: 16 | userInfoUri: http://localhost:9000/user 17 | 18 | person: 19 | url: http://localhost:9000/person 20 | 21 | # Proxies the calls to http://localhost:8080/api/* to our REST service at http://localhost:9000/* 22 | # and automatically includes our OAuth2 token in the request headers 23 | zuul: 24 | routes: 25 | resource: 26 | path: /api/** 27 | url: http://localhost:9000 28 | user: 29 | path: /user/** 30 | url: http://localhost:9000/user 31 | 32 | # Make sure the OAuth2 token is only relayed when using the internal API, 33 | # do not pass any authentication to the external API 34 | proxy: 35 | auth: 36 | routes: 37 | api: oauth2 -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Make the application available at http://localhost:8081 2 | # These are default settings, but we add them for clarity. 3 | server: 4 | port: 8081 5 | contextPath: / 6 | 7 | # Configure the Authorization Server and User Info Resource Server details 8 | security: 9 | oauth2: 10 | client: 11 | accessTokenUri: http://localhost:7077/authserver/oauth/token 12 | userAuthorizationUri: http://localhost:7077/authserver/oauth/authorize 13 | clientId: second 14 | clientSecret: passwordforauthserver 15 | resource: 16 | userInfoUri: http://localhost:9000/user 17 | 18 | person: 19 | url: http://localhost:9000/person 20 | 21 | # Proxies the calls to http://localhost:8081/api/* to our REST service at http://localhost:9000/* 22 | # and automatically includes our OAuth2 token in the request headers 23 | zuul: 24 | routes: 25 | resource: 26 | path: /api/** 27 | url: http://localhost:9000 28 | user: 29 | path: /user/** 30 | url: http://localhost:9000/user 31 | 32 | # Make sure the OAuth2 token is only relayed when using the internal API, 33 | # do not pass any authentication to the external API 34 | proxy: 35 | auth: 36 | routes: 37 | api: oauth2 -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/peterwanghao/spring/cloud/stream/rabbit/MyLoggerServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.stream.rabbit; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.stream.annotation.EnableBinding; 6 | import org.springframework.cloud.stream.annotation.StreamListener; 7 | import org.springframework.cloud.stream.messaging.Processor; 8 | import org.springframework.messaging.handler.annotation.SendTo; 9 | 10 | import com.peterwanghao.spring.cloud.stream.rabbit.model.LogMessage; 11 | /** 12 | * @ClassName: MyLoggerServiceApplication 13 | * @Description:主程序类,监听消息并按一定格式返回 14 | * @author: wanghao 15 | * @date: 2018年5月11日 上午10:31:26 16 | * @version V1.0 17 | * 18 | */ 19 | @SpringBootApplication 20 | @EnableBinding(Processor.class) 21 | public class MyLoggerServiceApplication { 22 | public static void main(String[] args) { 23 | SpringApplication.run(MyLoggerServiceApplication.class, args); 24 | } 25 | 26 | @StreamListener(Processor.INPUT) 27 | @SendTo(Processor.OUTPUT) 28 | public LogMessage enrichLogMessage(LogMessage log) { 29 | return new LogMessage(String.format("[1]: %s", log.getMessage())); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/filters/SimpleFilter.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient.filters; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import com.netflix.zuul.context.RequestContext; 5 | import com.netflix.zuul.ZuulFilter; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | /** 11 | * @ClassName: SimpleFilter 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午3:22:58 15 | * @version V1.0 16 | * 17 | */ 18 | public class SimpleFilter extends ZuulFilter { 19 | 20 | private static Logger log = LoggerFactory.getLogger(SimpleFilter.class); 21 | 22 | @Override 23 | public String filterType() { 24 | return "pre"; 25 | } 26 | 27 | @Override 28 | public int filterOrder() { 29 | return 1; 30 | } 31 | 32 | @Override 33 | public boolean shouldFilter() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public Object run() { 39 | RequestContext ctx = RequestContext.getCurrentContext(); 40 | HttpServletRequest request = ctx.getRequest(); 41 | 42 | log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); 43 | 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/filters/SimpleFilter.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient.filters; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import com.netflix.zuul.context.RequestContext; 5 | import com.netflix.zuul.ZuulFilter; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | /** 11 | * @ClassName: SimpleFilter 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午3:22:58 15 | * @version V1.0 16 | * 17 | */ 18 | public class SimpleFilter extends ZuulFilter { 19 | 20 | private static Logger log = LoggerFactory.getLogger(SimpleFilter.class); 21 | 22 | @Override 23 | public String filterType() { 24 | return "pre"; 25 | } 26 | 27 | @Override 28 | public int filterOrder() { 29 | return 1; 30 | } 31 | 32 | @Override 33 | public boolean shouldFilter() { 34 | return true; 35 | } 36 | 37 | @Override 38 | public Object run() { 39 | RequestContext ctx = RequestContext.getCurrentContext(); 40 | HttpServletRequest request = ctx.getRequest(); 41 | 42 | log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString())); 43 | 44 | return null; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/ServiceConsumer/src/main/java/com/peterwanghao/spring/cloud/greeting/HelloWorldClient.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.greeting; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 5 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 6 | import org.springframework.cloud.netflix.feign.FeignClient; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | /** 13 | * @ClassName: HelloWorldClient 14 | * @Description:HelloWorld服务客户端,通过Spring Cloud Feign声明式服务调用实现。 15 | * @author: wanghao 16 | * @date: 2018年3月23日 下午5:47:19 17 | * @version V1.0 18 | * 19 | */ 20 | @Configuration 21 | @EnableFeignClients 22 | @EnableDiscoveryClient 23 | public class HelloWorldClient { 24 | @Autowired 25 | private TheClient theClient; 26 | 27 | @FeignClient(name = "HelloWorld") 28 | interface TheClient { 29 | 30 | @RequestMapping(path = "/helloworld", method = RequestMethod.GET) 31 | @ResponseBody 32 | String HelloWorld(); 33 | } 34 | 35 | public String HelloWorld() { 36 | return theClient.HelloWorld(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-consumer/src/main/java/com/peterwanghao/spring/cloud/contract/consumer/controller/BasicMathController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.contract.consumer.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.*; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | /** 11 | * @ClassName: BasicMathController 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2019年1月10日 下午5:16:14 15 | * @version V1.0 16 | * 17 | */ 18 | @RestController 19 | public class BasicMathController { 20 | @Autowired 21 | private RestTemplate restTemplate; 22 | 23 | @GetMapping("/calculate") 24 | public String checkOddAndEven(@RequestParam("number") Integer number) { 25 | HttpHeaders httpHeaders = new HttpHeaders(); 26 | httpHeaders.add("Content-Type", "application/json"); 27 | 28 | ResponseEntity responseEntity = restTemplate.exchange( 29 | "http://localhost:8090/validate/prime-number?number=" + number, HttpMethod.GET, 30 | new HttpEntity<>(httpHeaders), String.class); 31 | 32 | return responseEntity.getBody(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-cloud-consul/consul-prop/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-consul 8 | 0.0.1-SNAPSHOT 9 | 10 | consul-prop 11 | consul-prop 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-consul-all 16 | ${spring-cloud-starter-consul.version} 17 | 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-consul-config 22 | ${spring-cloud-starter-consul.version} 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | 1.5.10.RELEASE 29 | test 30 | 31 | 32 | 33 | 34 | 1.3.0.RELEASE 35 | 36 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/controller/CloudSiteController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestOperations; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | /** 11 | * @ClassName: CloudSiteController 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午3:26:39 15 | * @version V1.0 16 | * 17 | */ 18 | @RestController 19 | public class CloudSiteController { 20 | 21 | @Autowired 22 | private RestOperations restOperations; 23 | 24 | @GetMapping("/") 25 | @ResponseBody 26 | public String hello() { 27 | return "Hello From Auth-Client!"; 28 | } 29 | 30 | @GetMapping("/personInfo") 31 | public ModelAndView person() { 32 | ModelAndView mav = new ModelAndView("personinfo"); 33 | String personResourceUrl = "http://localhost:9000/person"; 34 | mav.addObject("person", restOperations.getForObject(personResourceUrl, String.class)); 35 | return mav; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-client2/src/main/java/com/peterwanghao/spring/cloud/oauth/authclient/controller/CloudSiteController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authclient.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.ResponseBody; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestOperations; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | /** 11 | * @ClassName: CloudSiteController 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午3:26:39 15 | * @version V1.0 16 | * 17 | */ 18 | @RestController 19 | public class CloudSiteController { 20 | 21 | @Autowired 22 | private RestOperations restOperations; 23 | 24 | @GetMapping("/") 25 | @ResponseBody 26 | public String hello() { 27 | return "Hello From Auth-Client2!"; 28 | } 29 | 30 | @GetMapping("/personInfo") 31 | public ModelAndView person() { 32 | ModelAndView mav = new ModelAndView("personinfo"); 33 | String personResourceUrl = "http://localhost:9000/person"; 34 | mav.addObject("person", restOperations.getForObject(personResourceUrl, String.class)); 35 | return mav; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/java/com/peterwanghao/spring/cloud/archaius/jdbc/config/ApplicationPropertiesConfigurations.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.jdbc.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.apache.commons.configuration.AbstractConfiguration; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | import com.netflix.config.DynamicConfiguration; 11 | import com.netflix.config.FixedDelayPollingScheduler; 12 | import com.netflix.config.PolledConfigurationSource; 13 | import com.netflix.config.sources.JDBCConfigurationSource; 14 | 15 | /** 16 | * @ClassName: ApplicationPropertiesConfigurations 17 | * @Description:TODO(这里用一句话描述这个类的作用) 18 | * @author: wanghao 19 | * @date: 2018年11月20日 下午4:32:44 20 | * @version V1.0 21 | * 22 | */ 23 | @Configuration 24 | public class ApplicationPropertiesConfigurations { 25 | 26 | @Autowired 27 | DataSource h2DataSource; 28 | 29 | @Bean 30 | public AbstractConfiguration addApplicationPropertiesSource() { 31 | PolledConfigurationSource source = new JDBCConfigurationSource(h2DataSource, 32 | "select distinct key, value from properties", "key", "value"); 33 | return new DynamicConfiguration(source, new FixedDelayPollingScheduler()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/java/com/peterwanghao/spring/cloud/oauth/authresource/config/ResourceConfigurer.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authresource.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 9 | 10 | /** 11 | * @ClassName: ResourceConfigurer 12 | * @Description:REST API Resource Server. 13 | * @author: wanghao 14 | * @date: 2018年7月19日 下午2:39:35 15 | * @version V1.0 16 | * 17 | */ 18 | @Configuration 19 | @EnableWebSecurity 20 | @EnableResourceServer 21 | @EnableGlobalMethodSecurity(prePostEnabled = true) // Allow method annotations like @PreAuthorize 22 | public class ResourceConfigurer extends ResourceServerConfigurerAdapter { 23 | 24 | @Override 25 | public void configure(HttpSecurity http) throws Exception { 26 | http.httpBasic().disable(); 27 | http.authorizeRequests().anyRequest().authenticated(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /spring-cloud-config/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.peterwanghao.spring.cloud 6 | spring-cloud-examples 7 | 0.0.1-SNAPSHOT 8 | 9 | spring-cloud-config 10 | pom 11 | 12 | server 13 | client 14 | 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | ${maven-compiler-plugin.version} 27 | 28 | ${java.version} 29 | ${java.version} 30 | 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-maven-plugin 35 | ${spring-boot-maven-plugin.version} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/entities/Account.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql.entities; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * @ClassName: Account 10 | * @Description:TODO(这里用一句话描述这个类的作用) 11 | * @author: wanghao 12 | * @date: 2018年7月25日 下午2:43:21 13 | * @version V1.0 14 | * 15 | */ 16 | @Entity 17 | public class Account { 18 | @Id 19 | @GeneratedValue 20 | private Long id; 21 | @Column(name = "username", length = 128) 22 | private String username; 23 | @Column(name = "password", length = 128) 24 | private String password; 25 | 26 | public Account() { 27 | } 28 | 29 | public Account(String username, String password) { 30 | 31 | this.username = username; 32 | this.password = password; 33 | } 34 | 35 | public Long getId() { 36 | return id; 37 | } 38 | 39 | public void setId(Long id) { 40 | this.id = id; 41 | } 42 | 43 | public String getUsername() { 44 | return username; 45 | } 46 | 47 | public void setUsername(String username) { 48 | this.username = username; 49 | } 50 | 51 | public String getPassword() { 52 | return password; 53 | } 54 | 55 | public void setPassword(String password) { 56 | this.password = password; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /spring-cloud-config/client/src/main/java/com/peterwanghao/spring/cloud/config/client/ConfigClient.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.config.client; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * @ClassName: ConfigClient 14 | * @Description:模拟一个应用调用配置中心获取配置项 15 | * @author: wanghao 16 | * @date: 2018年3月20日 下午2:57:38 17 | * @version V1.0 18 | * 19 | */ 20 | @SpringBootApplication 21 | @RestController 22 | public class ConfigClient { 23 | @Value("${user.role}") 24 | private String role; 25 | 26 | @Value("${user.password}") 27 | private String password; 28 | 29 | public static void main(String[] args) { 30 | SpringApplication.run(ConfigClient.class, args); 31 | } 32 | 33 | @RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE) 34 | public String whoami(@PathVariable("username") String username) { 35 | return String.format("Hello %s! You are a(n) %s and your password is '%s'.\n", username, role, password); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-resource/src/main/java/com/peterwanghao/spring/cloud/oauth/authresource/model/Person.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authresource.model; 2 | 3 | /** 4 | * @ClassName: Person 5 | * @Description:用户信息对象 6 | * @author: wanghao 7 | * @date: 2018年7月19日 下午2:43:46 8 | * @version V1.0 9 | * 10 | */ 11 | public class Person { 12 | private String name; 13 | private String city; 14 | private String country; 15 | private Integer age; 16 | private String sex; 17 | 18 | public Person(String name, String city, String country, Integer age, String sex) { 19 | this.name = name; 20 | this.city = city; 21 | this.country = country; 22 | this.age = age; 23 | this.sex = sex; 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public String getCity() { 35 | return city; 36 | } 37 | 38 | public void setCity(String city) { 39 | this.city = city; 40 | } 41 | 42 | public String getCountry() { 43 | return country; 44 | } 45 | 46 | public void setCountry(String country) { 47 | this.country = country; 48 | } 49 | 50 | public Integer getAge() { 51 | return age; 52 | } 53 | 54 | public void setAge(Integer age) { 55 | this.age = age; 56 | } 57 | 58 | public String getSex() { 59 | return sex; 60 | } 61 | 62 | public void setSex(String sex) { 63 | this.sex = sex; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-feign-client/src/main/java/com/peterwanghao/spring/cloud/feign/client/FeignClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.feign.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.Model; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | 12 | /** 13 | * @ClassName: FeignClientApplication 14 | * @Description:

打招呼服务客户端实现,一个服务消费者。

15 | *

微服务框架Spring Cloud Netflix Eureka 实现的客户端, 16 | * 通过声明式服务调用发现和消费服务。

17 | * @author: wanghao 18 | * @date: 2018年3月14日 下午4:27:07 19 | * @version V1.0 20 | * 21 | */ 22 | @SpringBootApplication 23 | @EnableEurekaClient 24 | @EnableFeignClients 25 | @Controller 26 | public class FeignClientApplication { 27 | @Autowired 28 | private GreetingClient greetingClient; 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(FeignClientApplication.class, args); 32 | } 33 | 34 | @RequestMapping("/get-greeting") 35 | public String greeting(Model model) { 36 | model.addAttribute("greeting", greetingClient.greeting()); 37 | return "greeting-view"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-cloud-stream/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-examples 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-stream 11 | pom 12 | spring-cloud-stream 13 | Spring Cloud消息驱动的微服务 14 | 15 | spring-cloud-stream-rabbit 16 | 17 | 18 | 19 | UTF-8 20 | 21 | 22 | 23 | 24 | 25 | 26 | org.apache.maven.plugins 27 | maven-compiler-plugin 28 | ${maven-compiler-plugin.version} 29 | 30 | ${java.version} 31 | ${java.version} 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | ${spring-boot-maven-plugin.version} 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-contract 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-contract-consumer 11 | spring-cloud-contract-consumer 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-contract-wiremock 16 | test 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-contract-stub-runner 21 | test 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-rest 30 | 31 | 32 | com.peterwanghao.spring.cloud 33 | spring-cloud-contract-producer 34 | 0.0.1-SNAPSHOT 35 | test 36 | 37 | 38 | -------------------------------------------------------------------------------- /spring-cloud-zookeeper/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.peterwanghao.spring.cloud 6 | spring-cloud-examples 7 | 0.0.1-SNAPSHOT 8 | 9 | spring-cloud-zookeeper 10 | pom 11 | spring-cloud-zookeeper 12 | 使用Zookeeper作为服务注册中心的例子 13 | 14 | ServiceProvider 15 | ServiceConsumer 16 | 17 | 18 | UTF-8 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.apache.maven.plugins 26 | maven-compiler-plugin 27 | ${maven-compiler-plugin.version} 28 | 29 | ${java.version} 30 | ${java.version} 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | ${spring-boot-maven-plugin.version} 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-archaius 8 | 0.0.1-SNAPSHOT 9 | 10 | dynamodb-config 11 | dynamodb-config 12 | 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | com.amazonaws 22 | aws-java-sdk-dynamodb 23 | 24 | 25 | com.github.derjust 26 | spring-data-dynamodb 27 | ${spring.dynamo.version} 28 | 29 | 30 | com.netflix.archaius 31 | archaius-aws 32 | ${archaius.version} 33 | 34 | 35 | org.projectlombok 36 | lombok 37 | provided 38 | 39 | 40 | 41 | 42 | 4.5.0 43 | 0.7.6 44 | 45 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-contract 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-contract-producer 11 | spring-cloud-contract-producer 12 | 13 | 14 | org.springframework.cloud 15 | spring-cloud-starter-contract-verifier 16 | test 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-web 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-data-rest 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-contract-maven-plugin 32 | 3.0.0 33 | true 34 | 35 | com.peterwanghao.spring.cloud.contract.producer.BaseTestClass 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /spring-cloud-contract/spring-cloud-contract-producer/src/test/java/com/peterwanghao/spring/cloud/contract/producer/BaseTestClass.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.contract.producer; 2 | 3 | import io.restassured.module.mockmvc.RestAssuredMockMvc; 4 | import org.junit.Before; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | import org.springframework.cloud.contract.verifier.messaging.boot.AutoConfigureMessageVerifier; 9 | import org.springframework.test.annotation.DirtiesContext; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 12 | import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder; 13 | 14 | import com.peterwanghao.spring.cloud.contract.producer.controller.EvenOddController; 15 | 16 | /** 17 | * @ClassName: BaseTestClass 18 | * @Description:TODO(这里用一句话描述这个类的作用) 19 | * @author: wanghao 20 | * @date: 2019年1月10日 下午3:54:39 21 | * @version V1.0 22 | * 23 | */ 24 | @RunWith(SpringRunner.class) 25 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) 26 | @DirtiesContext 27 | @AutoConfigureMessageVerifier 28 | public class BaseTestClass { 29 | @Autowired 30 | private EvenOddController evenOddController; 31 | 32 | @Before 33 | public void setup() { 34 | StandaloneMockMvcBuilder standaloneMockMvcBuilder = MockMvcBuilders.standaloneSetup(evenOddController); 35 | RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-stream 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-stream-rabbit 11 | spring-cloud-stream-rabbit 12 | Spring Cloud消息驱动微服务RabbitMQ中间件 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-stream-rabbit 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-stream-test-support 22 | test 23 | 24 | 25 | org.apache.httpcomponents 26 | httpcore 27 | 4.4.8 28 | 29 | 30 | 31 | 32 | 33 | org.springframework.cloud 34 | spring-cloud-starter-parent 35 | ${spring-cloud-dependencies.version} 36 | pom 37 | import 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /spring-cloud-ribbon-client/src/main/java/com/peterwanghao/spring/cloud/ribbon/client/ServerLocationApp.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.ribbon.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.cloud.netflix.ribbon.RibbonClient; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | /** 14 | * @ClassName: ServerLocationApp 15 | * @Description:使用Spring Cloud Ribbon实现的客户端负载均衡 16 | * @author: wanghao 17 | * @date: 2018年3月28日 下午2:08:36 18 | * @version V1.0 19 | * 20 | */ 21 | @SpringBootApplication 22 | @RestController 23 | @RibbonClient(name = "ping-a-server", configuration = RibbonConfiguration.class) 24 | public class ServerLocationApp { 25 | 26 | @LoadBalanced 27 | @Bean 28 | RestTemplate getRestTemplate() { 29 | return new RestTemplate(); 30 | } 31 | 32 | @Autowired 33 | RestTemplate restTemplate; 34 | 35 | @RequestMapping("/server-location") 36 | public String serverLocation() { 37 | String servLoc = this.restTemplate.getForObject("http://ping-server/locate", String.class); 38 | return servLoc; 39 | } 40 | 41 | public static void main(String[] args) { 42 | SpringApplication.run(ServerLocationApp.class, args); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-cloud-security/book-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcbook/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcbook; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | 10 | /** 11 | * @ClassName: SecurityConfig 12 | * @Description:TODO(这里用一句话描述这个类的作用) 13 | * @author: wanghao 14 | * @date: 2018年5月2日 下午1:17:10 15 | * @version V1.0 16 | * 17 | */ 18 | @EnableWebSecurity 19 | @Configuration 20 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 21 | 22 | @Autowired 23 | public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception { 24 | // try in memory auth with no users to support the case that this will allow for 25 | // users that are logged in to go anywhere 26 | auth.inMemoryAuthentication(); 27 | } 28 | 29 | @Override 30 | protected void configure(HttpSecurity http) throws Exception { 31 | http.httpBasic().disable().authorizeRequests() 32 | .antMatchers("/books").permitAll() 33 | .antMatchers("/books/*").hasAnyRole("USER", "ADMIN").anyRequest() 34 | .authenticated().and().csrf().disable(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/main/java/com/peterwanghao/spring/cloud/stream/rabbit/MultipleOutputsServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.stream.rabbit; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.stream.annotation.EnableBinding; 7 | import org.springframework.cloud.stream.annotation.StreamListener; 8 | import org.springframework.messaging.Message; 9 | import org.springframework.messaging.support.MessageBuilder; 10 | 11 | import com.peterwanghao.spring.cloud.stream.rabbit.processor.MyProcessor; 12 | 13 | /** 14 | * @ClassName: MultipleOutputsServiceApplication 15 | * @Description:主程序类,根据接收的数据返回到不同的输出队列。 16 | * @author: wanghao 17 | * @date: 2018年5月11日 上午10:48:53 18 | * @version V1.0 19 | * 20 | */ 21 | @SpringBootApplication 22 | @EnableBinding(MyProcessor.class) 23 | public class MultipleOutputsServiceApplication { 24 | public static void main(String[] args) { 25 | SpringApplication.run(MultipleOutputsServiceApplication.class, args); 26 | } 27 | 28 | @Autowired 29 | private MyProcessor processor; 30 | 31 | @StreamListener(MyProcessor.INPUT) 32 | public void routeValues(Integer val) { 33 | if (val < 10) { 34 | processor.anOutput().send(message(val)); 35 | } else { 36 | processor.anotherOutput().send(message(val)); 37 | } 38 | } 39 | 40 | private static final Message message(T val) { 41 | return MessageBuilder.withPayload(val).build(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-zuul 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-zuul-foos-resource 11 | war 12 | spring-zuul-foos-resource 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | org.apache.commons 21 | commons-lang3 22 | ${commons-lang3.version} 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-starter-parent 31 | ${spring-cloud-dependencies.version} 32 | pom 33 | import 34 | 35 | 36 | 37 | 38 | 39 | spring-zuul-foos-resource 40 | 41 | 42 | src/main/resources 43 | true 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /spring-cloud-security/book-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcbook/BookServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcbook; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * @ClassName: BookServiceApplication 16 | * @Description:业务系统-图书服务 17 | * @author: wanghao 18 | * @date: 2018年5月2日 上午10:28:04 19 | * @version V1.0 20 | * 21 | */ 22 | @SpringBootApplication 23 | @EnableEurekaClient 24 | @RestController 25 | @RequestMapping("/books") 26 | public class BookServiceApplication { 27 | 28 | public static void main(String[] args) { 29 | SpringApplication.run(BookServiceApplication.class, args); 30 | } 31 | 32 | private List bookList = Arrays.asList(new Book(1L, "Spring Cloud微服务实战", "翟永超"), 33 | new Book(2L, "Mastering Spring Cloud", "Piotr Mińkowski")); 34 | 35 | @GetMapping("") 36 | public List findAllBooks() { 37 | return bookList; 38 | } 39 | 40 | @GetMapping("/{bookId}") 41 | public Book findBook(@PathVariable Long bookId) { 42 | return bookList.stream().filter(b -> b.getId().equals(bookId)).findFirst().orElse(null); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-foos-resource/src/main/java/org/peterwanghao/zuul/resource/web/controller/FooController.java: -------------------------------------------------------------------------------- 1 | package org.peterwanghao.zuul.resource.web.controller; 2 | 3 | import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; 4 | import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import org.peterwanghao.zuul.resource.web.dto.Foo; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.ResponseBody; 15 | 16 | /** 17 | * @ClassName: FooController 18 | * @Description:TODO(这里用一句话描述这个类的作用) 19 | * @author: wanghao 20 | * @date: 2018年9月11日 上午9:38:26 21 | * @version V1.0 22 | * 23 | */ 24 | @Controller 25 | public class FooController { 26 | public FooController() { 27 | super(); 28 | } 29 | 30 | // API - read 31 | @RequestMapping(method = RequestMethod.GET, value = "/foos/{id}") 32 | @ResponseBody 33 | public Foo findById(@PathVariable final long id, HttpServletRequest req, HttpServletResponse res) { 34 | // System.out.println(req.getHeaderNames()); 35 | // System.out.println("------" + req.getHeader("Test")); 36 | if (req.getHeader("Test") != null) { 37 | res.addHeader("Test", req.getHeader("Test")); 38 | } 39 | return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-cloud-hystrix/rest-producer/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-hystrix 8 | 0.0.1-SNAPSHOT 9 | 10 | rest-producer 11 | rest-producer 12 | Restful服务提供者 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-web 18 | 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-parent 26 | ${spring-cloud-dependencies.version} 27 | pom 28 | import 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-compiler-plugin 38 | 39 | 1.8 40 | 1.8 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client1/src/main/java/com/peterwanghao/spring/cloud/eureka/client/EurekaClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.context.annotation.Lazy; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.netflix.discovery.EurekaClient; 12 | 13 | /** 14 | * @ClassName: EurekaClientApplication 15 | * @Description:TODO(这里用一句话描述这个类的作用) 16 | * @author: wanghao 17 | * @date: 2018年9月17日 下午4:45:25 18 | * @version V1.0 19 | * 20 | */ 21 | @SpringBootApplication 22 | @EnableEurekaClient 23 | @RestController 24 | public class EurekaClientApplication implements GreetingController { 25 | @Autowired 26 | @Lazy 27 | private EurekaClient eurekaClient; 28 | 29 | @Value("${spring.application.name}") 30 | private String appName; 31 | 32 | @Value("${server.port}") 33 | private String portNumber; 34 | 35 | public static void main(String[] args) { 36 | SpringApplication.run(EurekaClientApplication.class, args); 37 | } 38 | 39 | @Override 40 | public String greeting() { 41 | System.out.println("Request received on port number " + portNumber); 42 | return String.format("Hello from '%s with Port Number %s'!", eurekaClient.getApplication(appName).getName(), 43 | portNumber); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/eureka-client2/src/main/java/com/peterwanghao/spring/cloud/eureka/client/EurekaClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.context.annotation.Lazy; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.netflix.discovery.EurekaClient; 12 | 13 | /** 14 | * @ClassName: EurekaClientApplication 15 | * @Description:TODO(这里用一句话描述这个类的作用) 16 | * @author: wanghao 17 | * @date: 2018年9月17日 下午4:45:25 18 | * @version V1.0 19 | * 20 | */ 21 | @SpringBootApplication 22 | @EnableEurekaClient 23 | @RestController 24 | public class EurekaClientApplication implements GreetingController { 25 | @Autowired 26 | @Lazy 27 | private EurekaClient eurekaClient; 28 | 29 | @Value("${spring.application.name}") 30 | private String appName; 31 | 32 | @Value("${server.port}") 33 | private String portNumber; 34 | 35 | public static void main(String[] args) { 36 | SpringApplication.run(EurekaClientApplication.class, args); 37 | } 38 | 39 | @Override 40 | public String greeting() { 41 | System.out.println("Request received on port number " + portNumber); 42 | return String.format("Hello from '%s with Port Number %s'!", eurekaClient.getApplication(appName).getName(), 43 | portNumber); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-examples 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-bootstrap 11 | pom 12 | spring-cloud-bootstrap 13 | Spring Cloud 工程,包含Zipkin服务跟踪 14 | 15 | 16 | discovery 17 | config 18 | gateway 19 | book-service 20 | rating-service 21 | 22 | 23 | UTF-8 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.apache.maven.plugins 31 | maven-compiler-plugin 32 | ${maven-compiler-plugin.version} 33 | 34 | ${java.version} 35 | ${java.version} 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-maven-plugin 41 | ${spring-boot-maven-plugin.version} 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /spring-cloud-security/rating-service-secure/src/main/java/com/peterwanghao/spring/cloud/security/svcrating/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.svcrating; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 | /** 10 | * @ClassName: SecurityConfig 11 | * @Description:TODO(这里用一句话描述这个类的作用) 12 | * @author: wanghao 13 | * @date: 2018年5月2日 下午1:28:46 14 | * @version V1.0 15 | * 16 | */ 17 | @EnableWebSecurity 18 | @Configuration 19 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 20 | 21 | @Autowired 22 | public void configureGlobal1(AuthenticationManagerBuilder auth) throws Exception { 23 | //try in memory auth with no users to support the case that this will allow for users that are logged in to go anywhere 24 | auth.inMemoryAuthentication(); 25 | } 26 | 27 | @Override 28 | protected void configure(HttpSecurity http) throws Exception { 29 | http.httpBasic().disable().authorizeRequests() 30 | .antMatchers("/ratings").hasRole("ADMIN") 31 | .antMatchers("/ratings/all").hasAnyRole("USER", "ADMIN").anyRequest() 32 | .authenticated().and().csrf().disable(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-cloud-archaius/zookeeper-config/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-archaius 8 | 0.0.1-SNAPSHOT 9 | 10 | zookeeper-config 11 | zookeeper-config 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-web 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-zookeeper-config 21 | 22 | 23 | 24 | org.apache.zookeeper 25 | zookeeper 26 | 27 | 28 | 29 | 30 | org.apache.zookeeper 31 | zookeeper 32 | ${zookeeper.version} 33 | 34 | 35 | org.slf4j 36 | slf4j-log4j12 37 | 38 | 39 | 40 | 41 | 42 | 43 | 2.0.0.RELEASE 44 | 3.8.0 45 | 46 | -------------------------------------------------------------------------------- /spring-cloud-bootstrap/book-service/src/main/java/com/peterwanghao/spring/cloud/bootstrap/svcbook/BookServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.bootstrap.svcbook; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | /** 15 | * @ClassName: BookServiceApplication 16 | * @Description:业务系统-图书服务 17 | * @author: wanghao 18 | * @date: 2018年4月25日 下午1:33:11 19 | * @version V1.0 20 | * 21 | */ 22 | @SpringBootApplication 23 | @EnableEurekaClient 24 | @RestController 25 | @RequestMapping("/books") 26 | public class BookServiceApplication { 27 | public static void main(String[] args) { 28 | SpringApplication.run(BookServiceApplication.class, args); 29 | } 30 | 31 | private List bookList = Arrays.asList( 32 | new Book(1L, "Spring Cloud微服务实战", "翟永超"), 33 | new Book(2L, "Mastering Spring Cloud", "Piotr Mińkowski") 34 | ); 35 | 36 | @GetMapping("") 37 | public List findAllBooks() { 38 | return bookList; 39 | } 40 | 41 | @GetMapping("/{bookId}") 42 | public Book findBook(@PathVariable Long bookId) { 43 | return bookList.stream().filter(b -> b.getId().equals(bookId)).findFirst().orElse(null); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-cloud-zuul/spring-zuul-ui/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Zuul 6 | 7 | 8 | 9 | 10 |
11 | 19 | 20 | 21 | 22 | 23 | 24 | 39 |
40 |
41 |

Foo Details

42 |
43 | 44 | {{foo.id}} 45 |
46 | 47 |
48 | 49 | {{foo.name}} 50 |
51 | 52 |
53 | New Foo 54 |
55 | 56 |
57 | 58 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/service/AccountUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.security.core.authority.AuthorityUtils; 5 | import org.springframework.security.core.userdetails.User; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.peterwanghao.spring.cloud.oauth.authsql.repository.AccountRepository; 12 | 13 | /** 14 | * @ClassName: AccountUserDetailsService 15 | * @Description:TODO(这里用一句话描述这个类的作用) 16 | * @author: wanghao 17 | * @date: 2018年7月25日 下午2:40:02 18 | * @version V1.0 19 | * 20 | */ 21 | @Service 22 | public class AccountUserDetailsService implements UserDetailsService { 23 | private AccountRepository accountRepository; 24 | 25 | @Autowired 26 | public AccountUserDetailsService(AccountRepository accountRepository) { 27 | this.accountRepository = accountRepository; 28 | } 29 | 30 | @Override 31 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 32 | return accountRepository 33 | .findByUsername(username) 34 | .map(account -> new User(account.getUsername(), account.getPassword(), AuthorityUtils.createAuthorityList("ROLE_USER"))) 35 | .orElseThrow(() -> new UsernameNotFoundException("Could not find " + username)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-cloud-zuul-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.peterwanghao.spring.cloud 7 | spring-cloud-examples 8 | 0.0.1-SNAPSHOT 9 | 10 | spring-cloud-zuul-eureka 11 | pom 12 | spring-cloud-zuul-eureka 13 | Zuul和Eureka的负载均衡示例 14 | 15 | eureka-server 16 | eureka-client1 17 | eureka-client2 18 | zuul-server 19 | 20 | 21 | 22 | UTF-8 23 | 1.10 24 | 1.2.10 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | ${maven-compiler-plugin.version} 34 | 35 | ${java.version} 36 | ${java.version} 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-maven-plugin 42 | ${spring-boot-maven-plugin.version} 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /spring-cloud-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.peterwanghao.spring.cloud 6 | spring-cloud-examples 7 | 0.0.1-SNAPSHOT 8 | 9 | spring-cloud-eureka 10 | pom 11 | Spring Cloud Eureka 12 | Spring Cloud Eureka Server and Sample Clients 13 | 14 | spring-cloud-eureka-server 15 | spring-cloud-eureka-client 16 | spring-cloud-eureka-feign-client 17 | 18 | 19 | 20 | UTF-8 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | org.apache.maven.plugins 29 | maven-compiler-plugin 30 | ${maven-compiler-plugin.version} 31 | 32 | ${java.version} 33 | ${java.version} 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | ${spring-boot-maven-plugin.version} 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /spring-cloud-stream/spring-cloud-stream-rabbit/src/test/java/com/peterwanghao/spring/cloud/stream/rabbit/MyLoggerApplicationIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.stream.rabbit; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.cloud.stream.messaging.Processor; 9 | import org.springframework.cloud.stream.test.binder.MessageCollector; 10 | import org.springframework.messaging.support.MessageBuilder; 11 | import org.springframework.test.annotation.DirtiesContext; 12 | import org.springframework.test.context.ContextConfiguration; 13 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 14 | 15 | import com.peterwanghao.spring.cloud.stream.rabbit.model.LogMessage; 16 | 17 | /** 18 | * @ClassName: MyLoggerApplicationIntegrationTest 19 | * @Description:TODO(这里用一句话描述这个类的作用) 20 | * @author: wanghao 21 | * @date: 2018年5月11日 上午10:58:30 22 | * @version V1.0 23 | * 24 | */ 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @ContextConfiguration(classes = MyLoggerServiceApplication.class) 27 | @DirtiesContext 28 | public class MyLoggerApplicationIntegrationTest { 29 | @Autowired 30 | private Processor pipe; 31 | 32 | @Autowired 33 | private MessageCollector messageCollector; 34 | 35 | @Test 36 | public void whenSendMessage_thenResponseShouldUpdateText() { 37 | pipe.input().send(MessageBuilder.withPayload(new LogMessage("This is my message")).build()); 38 | 39 | Object payload = messageCollector.forChannel(pipe.output()).poll().getPayload(); 40 | 41 | assertEquals("[1]: This is my message", payload.toString()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-cloud-security/gateway-secure/src/main/java/com/peterwanghao/spring/cloud/security/gateway/filter/SessionSavingZuulPreFilter.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.security.gateway.filter; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.session.Session; 9 | import org.springframework.session.SessionRepository; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.servlet.http.HttpSession; 13 | 14 | /** 15 | * @ClassName: SessionSavingZuulPreFilter 16 | * @Description:TODO(这里用一句话描述这个类的作用) 17 | * @author: wanghao 18 | * @date: 2018年5月2日 上午11:21:25 19 | * @version V1.0 20 | * 21 | */ 22 | @Component 23 | public class SessionSavingZuulPreFilter extends ZuulFilter { 24 | 25 | private Logger log = LoggerFactory.getLogger(this.getClass()); 26 | 27 | @Autowired 28 | private SessionRepository repository; 29 | 30 | @Override 31 | public boolean shouldFilter() { 32 | return true; 33 | } 34 | 35 | @Override 36 | public Object run() { 37 | RequestContext context = RequestContext.getCurrentContext(); 38 | HttpSession httpSession = context.getRequest().getSession(); 39 | Session session = repository.getSession(httpSession.getId()); 40 | 41 | context.addZuulRequestHeader("Cookie", "SESSION=" + httpSession.getId()); 42 | log.info("ZuulPreFilter session proxy: {}", session.getId()); 43 | return null; 44 | } 45 | 46 | @Override 47 | public String filterType() { 48 | return "pre"; 49 | } 50 | 51 | @Override 52 | public int filterOrder() { 53 | return 0; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-cloud-vault/vault-config/localhost.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEAxeIeoHl1h3EnX5ptIbnmBvc02jd/M1uSOn+0AiXUVR7ILLI/ 3 | /IRGuRSSEWPiCD+rVgdQ79+1zQ90v8kFpUFMqfOzGCnuFj91QSRmpdnrj1fRSskh 4 | F3XfDk3vVws/X4+MKuqiQxVx5TXyQrsLJo6aJMpgWa39FMlAuYVCymYlc1KKrvNS 5 | 8CDK+hjlPMmfsy5KhsderXumeWb5ducCAMlS33JHoELZ0UXbSJlTi5NfLZVGeB8t 6 | 7Len7qKfRM6MPhwQwmrCBRuOIjyb+ERIKR61WSrRbSqSRV9YE3PPmqoYc1FuFkHB 7 | PtIzQy5e6b6oRjufuNxACTkENvrXeWJVCNDS2QIDAQABAoIBACEyB5VACtlHwCUn 8 | kLshplbwzWr1+F6zM9qgZaAenHoTCd2FoXpI7lxJ+R71tItRsvphi9BRpPvbZehu 9 | XoYUaDnyac7Z6djNmGvvIVEdN4j6YF+9UdHPsjWCGW5uspjjSc5BQisiw9KBtDxB 10 | iGNVdMJLONKSf2wnPrZgho3RiOLJX/poPyGTkMHuhBVvo4oy7Ax3XalaAcufgqwm 11 | YBQJ1Tka+33EUiLkxzJTXxNbIAI2scP8jhGn6mokS0V4gZPxJKUZEyydXRWwi6ex 12 | ua/7q76ELJS5b+xKRYfGsvavFDx8R+LqX8oegALD33ki3rm1MQW7GmikRL98+EVW 13 | Q9mQsqECgYEA/IrP8vycbJOgn1vriNItFcZtczSBlrXCRF0up2cqKMs9c+T5i51x 14 | ZKXK5lo3DfMT+YDM+iiGZ9+vM0UA2VxbFD3XV9mQDBaNC+Duknqxx+OLmWva9YwR 15 | nMaevqVV9LCn+GgUcK+IygEnpzpdP4q8YcXAfGAnZgnihN/AUYAaB70CgYEAyJe4 16 | yO0S9gAH5aoDdooL0YXrH/Dzd+fAgNsawLhoOltcoZqZFWeAllM0GsrCpfTRltuy 17 | dn9ca3YK0GlWl7h5rDle1HO3nhp1FcpeG1oxmkeQta3PG66uUuMccTAljCLFrEe3 18 | DguH8+qdjhLk+ZnUB9AVkS79pzdwuEHVljCK600CgYB6mMygkh9B2lzkX9Q0xItc 19 | gcqKXdf3GN9pHq9SVxOxYBDCHUtDirgMeyvHrc4COJneyrc3TcsJzB4aToo9+sbA 20 | SdErdZOnOp9YP+axN1zsw7r2TNSr1UaLjCRuOodC1SuFvMkHdz95iRv946h2+1u+ 21 | PyjVeDxIHc5YYOLU7dI1JQKBgQDF5KDBYNm25brkwcCe3nvgXfzjyyN25KUOupn/ 22 | DS6Oe/m72Lgz3KOIKleaIvS7IvbunJnIu8dioNb0Wye5kJ5A4WyDrhG1IabnM3l6 23 | BJYw/W9vPSS4y7FhRnuV0wkH4nofh7S5X3jlk02Sj2NkN3Vtq8TLMY++uzwyG4jq 24 | ncM/dQKBgQC+6mA5OfbVN4lRn+zrSiIH5gpvZYPh9wXeTnDWHa13sJsu3e8AQxtk 25 | TfE0W13UV5jhGL8Wvyyxn+doGFTdcZapOlwuoQ6RcgHcVQm2sOl60GAa4idmm0A6 26 | TcgnIOTyVRlNBoWLCfN83BlGz4gcDpnuZZ/0JuguixgLS323hQlLvg== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /spring-cloud-archaius/jdbc-config/src/main/java/com/peterwanghao/spring/cloud/archaius/jdbc/controller/ConfigPropertiesController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.jdbc.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.netflix.config.DynamicPropertyFactory; 10 | import com.netflix.config.DynamicStringProperty; 11 | 12 | /** 13 | * @ClassName: ConfigPropertiesController 14 | * @Description:TODO(这里用一句话描述这个类的作用) 15 | * @author: wanghao 16 | * @date: 2018年11月20日 下午4:34:28 17 | * @version V1.0 18 | * 19 | */ 20 | @RestController 21 | public class ConfigPropertiesController { 22 | 23 | private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory.getInstance() 24 | .getStringProperty("springcloud.archaius.properties.one", "not found!"); 25 | 26 | private DynamicStringProperty propertyTwoWithDynamic = DynamicPropertyFactory.getInstance() 27 | .getStringProperty("springcloud.archaius.properties.two", "not found!"); 28 | 29 | private DynamicStringProperty propertyThreeWithDynamic = DynamicPropertyFactory.getInstance() 30 | .getStringProperty("springcloud.archaius.properties.three", "not found!"); 31 | 32 | @GetMapping("/properties-from-dynamic") 33 | public Map getPropertiesFromDynamic() { 34 | Map properties = new HashMap<>(); 35 | properties.put(propertyOneWithDynamic.getName(), propertyOneWithDynamic.get()); 36 | properties.put(propertyTwoWithDynamic.getName(), propertyTwoWithDynamic.get()); 37 | properties.put(propertyThreeWithDynamic.getName(), propertyThreeWithDynamic.get()); 38 | return properties; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-cloud-eureka/spring-cloud-eureka-client/src/main/java/com/peterwanghao/spring/cloud/eureka/client/EurekaClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.eureka.client; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.context.annotation.Lazy; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import com.netflix.discovery.EurekaClient; 12 | 13 | /** 14 | * @ClassName: EurekaClientApplication 15 | * @Description:

打招呼服务实现。一个服务提供者。

16 | *

微服务框架Spring Cloud Netflix Eureka 实现的客户端, 17 | * 作为一个微服务应用向服务注册中心发布自己。

18 | * @author: wanghao 19 | * @date: 2018年3月14日 下午4:01:07 20 | * @version V1.0 21 | * 22 | */ 23 | @SpringBootApplication 24 | @EnableEurekaClient 25 | @RestController 26 | public class EurekaClientApplication implements GreetingController { 27 | 28 | @Autowired 29 | @Lazy 30 | private EurekaClient eurekaClient; 31 | 32 | @Value("${spring.application.name}") 33 | private String appName; 34 | 35 | public static void main(String[] args) { 36 | SpringApplication.run(EurekaClientApplication.class, args); 37 | } 38 | 39 | /** 40 | *

Title: greeting

41 | *

Description:

42 | * @return 43 | * @see com.peterwanghao.spring.cloud.eureka.client.GreetingController#greeting() 44 | */ 45 | @Override 46 | public String greeting() { 47 | return String.format("Hello from '%s'!", eurekaClient.getApplication(appName).getName()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-cloud-oauth/auth-server-sql/src/main/java/com/peterwanghao/spring/cloud/oauth/authsql/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.oauth.authsql.config; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.jdbc.datasource.DriverManagerDataSource; 9 | import org.springframework.security.oauth2.provider.token.TokenStore; 10 | import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; 11 | 12 | /** 13 | * @ClassName: AppConfig 14 | * @Description:TODO(这里用一句话描述这个类的作用) 15 | * @author: wanghao 16 | * @date: 2018年7月25日 下午2:08:03 17 | * @version V1.0 18 | * 19 | */ 20 | @Configuration 21 | public class AppConfig { 22 | @Value("${spring.datasource.url}") 23 | private String datasourceUrl; 24 | 25 | @Value("${spring.database.driverClassName}") 26 | private String dbDriverClassName; 27 | 28 | @Value("${spring.datasource.username}") 29 | private String dbUsername; 30 | 31 | @Value("${spring.datasource.password}") 32 | private String dbPassword; 33 | 34 | @Bean 35 | public DataSource dataSource() { 36 | final DriverManagerDataSource dataSource = new DriverManagerDataSource(); 37 | 38 | dataSource.setDriverClassName(dbDriverClassName); 39 | dataSource.setUrl(datasourceUrl); 40 | dataSource.setUsername(dbUsername); 41 | dataSource.setPassword(dbPassword); 42 | 43 | return dataSource; 44 | } 45 | 46 | @Bean 47 | public TokenStore tokenStore() { 48 | return new JdbcTokenStore(dataSource()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-cloud-archaius/dynamodb-config/src/main/java/com/peterwanghao/spring/cloud/archaius/dynamodb/controller/ConfigPropertiesController.java: -------------------------------------------------------------------------------- 1 | package com.peterwanghao.spring.cloud.archaius.dynamodb.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.netflix.config.DynamicPropertyFactory; 10 | import com.netflix.config.DynamicStringProperty; 11 | 12 | /** 13 | * @ClassName: ConfigPropertiesController 14 | * @Description:TODO(这里用一句话描述这个类的作用) 15 | * @author: wanghao 16 | * @date: 2018年11月20日 下午5:02:49 17 | * @version V1.0 18 | * 19 | */ 20 | @RestController 21 | public class ConfigPropertiesController { 22 | 23 | private DynamicStringProperty propertyOneWithDynamic = DynamicPropertyFactory.getInstance() 24 | .getStringProperty("springcloud.archaius.properties.one", "not found!"); 25 | 26 | private DynamicStringProperty propertyTwoWithDynamic = DynamicPropertyFactory.getInstance() 27 | .getStringProperty("springcloud.archaius.properties.two", "not found!"); 28 | 29 | private DynamicStringProperty propertyThreeWithDynamic = DynamicPropertyFactory.getInstance() 30 | .getStringProperty("springcloud.archaius.properties.three", "not found!"); 31 | 32 | @GetMapping("/properties-from-dynamic") 33 | public Map getPropertiesFromDynamic() { 34 | Map properties = new HashMap<>(); 35 | properties.put(propertyOneWithDynamic.getName(), propertyOneWithDynamic.get()); 36 | properties.put(propertyTwoWithDynamic.getName(), propertyTwoWithDynamic.get()); 37 | properties.put(propertyThreeWithDynamic.getName(), propertyThreeWithDynamic.get()); 38 | return properties; 39 | } 40 | } 41 | --------------------------------------------------------------------------------