├── .DS_Store ├── .gitignore ├── README.md ├── 第01课 └── demo │ ├── .DS_Store │ ├── .idea │ ├── compiler.xml │ ├── encodings.xml │ ├── inspectionProfiles │ │ └── Project_Default.xml │ ├── libraries │ │ ├── Maven__ch_qos_logback_logback_classic_1_2_3.xml │ │ ├── Maven__ch_qos_logback_logback_core_1_2_3.xml │ │ ├── Maven__com_fasterxml_classmate_1_4_0.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_9_8.xml │ │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_9_8.xml │ │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_8.xml │ │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_8.xml │ │ ├── Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_8.xml │ │ ├── Maven__javax_annotation_javax_annotation_api_1_3_2.xml │ │ ├── Maven__javax_validation_validation_api_2_0_1_Final.xml │ │ ├── Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml │ │ ├── Maven__org_apache_logging_log4j_log4j_to_slf4j_2_11_2.xml │ │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_9_0_16.xml │ │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_9_0_16.xml │ │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_9_0_16.xml │ │ ├── Maven__org_hibernate_validator_hibernate_validator_6_0_14_Final.xml │ │ ├── Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml │ │ ├── Maven__org_slf4j_jul_to_slf4j_1_7_25.xml │ │ ├── Maven__org_slf4j_slf4j_api_1_7_25.xml │ │ ├── Maven__org_springframework_boot_spring_boot_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_starter_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_starter_json_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_boot_spring_boot_starter_web_2_1_3_RELEASE.xml │ │ ├── Maven__org_springframework_spring_aop_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_beans_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_context_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_core_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_expression_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_jcl_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_web_5_1_5_RELEASE.xml │ │ ├── Maven__org_springframework_spring_webmvc_5_1_5_RELEASE.xml │ │ └── Maven__org_yaml_snakeyaml_1_23.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml │ ├── demo.iml │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── DemoApplication.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── application.yml │ └── target │ ├── api.war │ ├── api.war.original │ ├── api │ └── WEB-INF │ │ ├── classes │ │ ├── application.yml │ │ └── com │ │ │ └── lynn │ │ │ ├── DemoApplication.class │ │ │ └── HelloController.class │ │ └── lib │ │ ├── classmate-1.4.0.jar │ │ ├── hibernate-validator-6.0.14.Final.jar │ │ ├── jackson-annotations-2.9.0.jar │ │ ├── jackson-core-2.9.8.jar │ │ ├── jackson-databind-2.9.8.jar │ │ ├── jackson-datatype-jdk8-2.9.8.jar │ │ ├── jackson-datatype-jsr310-2.9.8.jar │ │ ├── jackson-module-parameter-names-2.9.8.jar │ │ ├── javax.annotation-api-1.3.2.jar │ │ ├── jboss-logging-3.3.2.Final.jar │ │ ├── jul-to-slf4j-1.7.25.jar │ │ ├── log4j-api-2.11.2.jar │ │ ├── log4j-to-slf4j-2.11.2.jar │ │ ├── logback-classic-1.2.3.jar │ │ ├── logback-core-1.2.3.jar │ │ ├── slf4j-api-1.7.25.jar │ │ ├── snakeyaml-1.23.jar │ │ ├── spring-aop-5.1.5.RELEASE.jar │ │ ├── spring-beans-5.1.5.RELEASE.jar │ │ ├── spring-boot-2.1.3.RELEASE.jar │ │ ├── spring-boot-autoconfigure-2.1.3.RELEASE.jar │ │ ├── spring-boot-starter-2.1.3.RELEASE.jar │ │ ├── spring-boot-starter-json-2.1.3.RELEASE.jar │ │ ├── spring-boot-starter-logging-2.1.3.RELEASE.jar │ │ ├── spring-boot-starter-tomcat-2.1.3.RELEASE.jar │ │ ├── spring-boot-starter-web-2.1.3.RELEASE.jar │ │ ├── spring-context-5.1.5.RELEASE.jar │ │ ├── spring-core-5.1.5.RELEASE.jar │ │ ├── spring-expression-5.1.5.RELEASE.jar │ │ ├── spring-jcl-5.1.5.RELEASE.jar │ │ ├── spring-web-5.1.5.RELEASE.jar │ │ ├── spring-webmvc-5.1.5.RELEASE.jar │ │ ├── tomcat-embed-core-9.0.16.jar │ │ ├── tomcat-embed-el-9.0.16.jar │ │ ├── tomcat-embed-websocket-9.0.16.jar │ │ └── validation-api-2.0.1.Final.jar │ ├── classes │ ├── application.yml │ └── com │ │ └── lynn │ │ ├── DemoApplication.class │ │ └── HelloController.class │ ├── maven-archiver │ └── pom.properties │ └── maven-status │ └── maven-compiler-plugin │ └── compile │ └── default-compile │ ├── createdFiles.lst │ └── inputFiles.lst ├── 第02课 └── demo │ ├── .idea │ ├── compiler.xml │ ├── encodings.xml │ ├── inspectionProfiles │ │ └── Project_Default.xml │ ├── misc.xml │ ├── modules.xml │ ├── uiDesigner.xml │ ├── vcs.xml │ └── workspace.xml │ ├── demo.iml │ ├── pom.xml │ ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ ├── Aliyun.java │ │ │ │ ├── AliyunAuto.java │ │ │ │ ├── ApiInterceptor.java │ │ │ │ ├── AuthorizeIn.java │ │ │ │ ├── DemoApplication.java │ │ │ │ ├── HelloController.java │ │ │ │ ├── WebConfig.java │ │ │ │ ├── WebExceptionAspect.java │ │ │ │ ├── controller │ │ │ │ └── PageController.java │ │ │ │ └── version │ │ │ │ ├── ApiVersion.java │ │ │ │ ├── ApiVersionCondition.java │ │ │ │ └── CustomRequestMappingHandlerMapping.java │ │ └── resources │ │ │ ├── application-dev.yml │ │ │ ├── application-prod.yml │ │ │ ├── application.yml │ │ │ └── templates │ │ │ └── index.ftl │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ └── target │ ├── classes │ ├── application-dev.yml │ ├── application-prod.yml │ ├── application.yml │ ├── com │ │ └── lynn │ │ │ ├── Aliyun$1.class │ │ │ ├── Aliyun$Builder.class │ │ │ ├── Aliyun.class │ │ │ ├── AliyunAuto.class │ │ │ ├── ApiInterceptor.class │ │ │ ├── AuthorizeIn.class │ │ │ ├── DemoApplication.class │ │ │ ├── HelloController.class │ │ │ ├── WebConfig.class │ │ │ ├── WebExceptionAspect.class │ │ │ ├── controller │ │ │ └── PageController.class │ │ │ └── version │ │ │ ├── ApiVersion.class │ │ │ ├── ApiVersionCondition.class │ │ │ └── CustomRequestMappingHandlerMapping.class │ └── templates │ │ └── index.ftl │ └── test-classes │ └── com │ └── lynn │ └── test │ └── TestDB.class ├── 第03课 └── demo │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── lynn │ │ └── DemoApplication.java │ └── resources │ ├── application-dev.yml │ ├── application-prod.yml │ └── application.yml ├── 第04课 └── springcloud │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第05课 └── springcloud │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── application.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第06课 └── springcloud │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── application.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiGlobalFilter.java │ │ │ ├── Application.java │ │ │ ├── ErrorHandlerConfiguration.java │ │ │ └── JsonExceptionHandler.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第07课 └── springcloud │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── application.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── feign │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ └── feign │ │ │ │ ├── ApiService.java │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiGlobalFilter.java │ │ │ ├── Application.java │ │ │ ├── ErrorHandlerConfiguration.java │ │ │ └── JsonExceptionHandler.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第08课 └── springcloud │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── application.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── feign │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ └── feign │ │ │ │ ├── ApiController.java │ │ │ │ ├── ApiService.java │ │ │ │ ├── ApiServiceError.java │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiGlobalFilter.java │ │ │ ├── Application.java │ │ │ ├── ErrorHandlerConfiguration.java │ │ │ └── JsonExceptionHandler.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第09课 ├── config │ └── eurekaclient.yml └── springcloud │ ├── config │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── config │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── bootstrap.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── feign │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ └── feign │ │ │ │ ├── ApiController.java │ │ │ │ ├── ApiService.java │ │ │ │ ├── ApiServiceError.java │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiGlobalFilter.java │ │ │ ├── Application.java │ │ │ ├── ErrorHandlerConfiguration.java │ │ │ └── JsonExceptionHandler.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第10课 └── springcloud │ ├── config │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── config │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── bootstrap.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── feign │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ └── feign │ │ │ │ ├── ApiController.java │ │ │ │ ├── ApiService.java │ │ │ │ ├── ApiServiceError.java │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiGlobalFilter.java │ │ │ ├── Application.java │ │ │ ├── ErrorHandlerConfiguration.java │ │ │ └── JsonExceptionHandler.java │ │ └── resources │ │ └── application.yml │ └── pom.xml ├── 第11课 └── springcloud │ ├── config │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── config │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── eurekaclient │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ ├── Application.java │ │ │ └── HelloController.java │ │ └── resources │ │ └── bootstrap.yml │ ├── eurekaserver │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── feign │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── lynn │ │ │ │ └── feign │ │ │ │ ├── ApiController.java │ │ │ │ ├── ApiService.java │ │ │ │ ├── ApiServiceError.java │ │ │ │ └── Application.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── lynn │ │ └── test │ │ └── TestDB.java │ ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── lynn │ │ │ └── gateway │ │ │ ├── ApiFallbackProvider.java │ │ │ ├── ApiFilter.java │ │ │ └── Application.java │ │ └── resources │ │ └── application.yml │ ├── pom.xml │ └── zipkin │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── lynn │ │ └── zipkin │ │ └── Application.java │ └── resources │ └── application.yml ├── 第12课 └── demo │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── lynn │ │ └── demo │ │ ├── Application.java │ │ ├── DistributedLockHandler.java │ │ ├── HelloController.java │ │ ├── Lock.java │ │ ├── lock │ │ ├── AquiredLockWorker.java │ │ ├── DistributedLocker.java │ │ ├── RedisLocker.java │ │ ├── RedissonConnector.java │ │ └── UnableToAquireLockException.java │ │ └── zk │ │ └── DistributedLock.java │ └── resources │ └── application.yml └── 第13课 └── demo ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── lynn │ │ └── demo │ │ ├── Application.java │ │ ├── DistributedLockHandler.java │ │ ├── HelloController.java │ │ ├── Lock.java │ │ ├── config │ │ ├── MyBatisConfig1.java │ │ └── MyBatisConfig2.java │ │ ├── db │ │ ├── DBConfig1.java │ │ └── DBConfig2.java │ │ ├── entity │ │ └── User.java │ │ ├── lock │ │ ├── AquiredLockWorker.java │ │ ├── DistributedLocker.java │ │ ├── RedisLocker.java │ │ ├── RedissonConnector.java │ │ └── UnableToAquireLockException.java │ │ ├── service │ │ └── UserService.java │ │ ├── test01 │ │ └── UserMapper1.java │ │ ├── test02 │ │ └── UserMapper2.java │ │ └── zk │ │ └── DistributedLock.java └── resources │ └── application.yml └── test └── java └── com └── lynn └── demo └── test └── TestDB.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringCloudLesson 2 | SpringCloud从入门到精通系列课程 3 | -------------------------------------------------------------------------------- /第01课/demo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/.DS_Store -------------------------------------------------------------------------------- /第01课/demo/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /第01课/demo/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /第01课/demo/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_classmate_1_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_11_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_apache_logging_log4j_log4j_to_slf4j_2_11_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_9_0_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_9_0_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_9_0_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_14_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_aop_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_beans_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_context_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_core_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_expression_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_jcl_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_web_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_springframework_spring_webmvc_5_1_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/libraries/Maven__org_yaml_snakeyaml_1_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第01课/demo/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /第01课/demo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /第01课/demo/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /第01课/demo/src/main/java/com/lynn/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | public class DemoApplication extends SpringBootServletInitializer { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DemoApplication.class, args); 13 | } 14 | 15 | @Override 16 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 17 | return application.sources(DemoApplication.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第01课/demo/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | @RestController 7 | public class HelloController{ 8 | 9 | @RequestMapping("hello") 10 | String hello() { 11 | return "Hello World!"; 12 | } 13 | 14 | 15 | } -------------------------------------------------------------------------------- /第01课/demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | servlet: 4 | context-path: /api -------------------------------------------------------------------------------- /第01课/demo/target/api.war: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api.war -------------------------------------------------------------------------------- /第01课/demo/target/api.war.original: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api.war.original -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | servlet: 4 | context-path: /api -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/classes/com/lynn/DemoApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/classes/com/lynn/DemoApplication.class -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/classes/com/lynn/HelloController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/classes/com/lynn/HelloController.class -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/classmate-1.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/classmate-1.4.0.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/hibernate-validator-6.0.14.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/hibernate-validator-6.0.14.Final.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-annotations-2.9.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-annotations-2.9.0.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-core-2.9.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-core-2.9.8.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-databind-2.9.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-databind-2.9.8.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-datatype-jdk8-2.9.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-datatype-jdk8-2.9.8.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-datatype-jsr310-2.9.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-datatype-jsr310-2.9.8.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jackson-module-parameter-names-2.9.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jackson-module-parameter-names-2.9.8.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/javax.annotation-api-1.3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/javax.annotation-api-1.3.2.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jboss-logging-3.3.2.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jboss-logging-3.3.2.Final.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/jul-to-slf4j-1.7.25.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/jul-to-slf4j-1.7.25.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/log4j-api-2.11.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/log4j-api-2.11.2.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/log4j-to-slf4j-2.11.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/log4j-to-slf4j-2.11.2.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/logback-classic-1.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/logback-classic-1.2.3.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/logback-core-1.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/logback-core-1.2.3.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/slf4j-api-1.7.25.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/slf4j-api-1.7.25.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/snakeyaml-1.23.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/snakeyaml-1.23.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-aop-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-aop-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-beans-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-beans-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-autoconfigure-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-autoconfigure-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-json-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-json-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-logging-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-logging-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-tomcat-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-tomcat-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-web-2.1.3.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-boot-starter-web-2.1.3.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-context-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-context-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-core-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-core-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-expression-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-expression-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-jcl-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-jcl-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-web-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-web-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/spring-webmvc-5.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/spring-webmvc-5.1.5.RELEASE.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/tomcat-embed-core-9.0.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/tomcat-embed-core-9.0.16.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/tomcat-embed-el-9.0.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/tomcat-embed-el-9.0.16.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/tomcat-embed-websocket-9.0.16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/tomcat-embed-websocket-9.0.16.jar -------------------------------------------------------------------------------- /第01课/demo/target/api/WEB-INF/lib/validation-api-2.0.1.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/api/WEB-INF/lib/validation-api-2.0.1.Final.jar -------------------------------------------------------------------------------- /第01课/demo/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | servlet: 4 | context-path: /api -------------------------------------------------------------------------------- /第01课/demo/target/classes/com/lynn/DemoApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/classes/com/lynn/DemoApplication.class -------------------------------------------------------------------------------- /第01课/demo/target/classes/com/lynn/HelloController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第01课/demo/target/classes/com/lynn/HelloController.class -------------------------------------------------------------------------------- /第01课/demo/target/maven-archiver/pom.properties: -------------------------------------------------------------------------------- 1 | #Created by Apache Maven 3.3.9 2 | version=1.0-SNAPSHOT 3 | groupId=com.lynn 4 | artifactId=demo 5 | -------------------------------------------------------------------------------- /第01课/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst: -------------------------------------------------------------------------------- 1 | com/lynn/DemoApplication.class 2 | com/lynn/HelloController.class 3 | -------------------------------------------------------------------------------- /第01课/demo/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst: -------------------------------------------------------------------------------- 1 | /Volumes/李熠/课程/gitchat/SpringCloudLesson/第01课/demo/src/main/java/com/lynn/DemoApplication.java 2 | /Volumes/李熠/课程/gitchat/SpringCloudLesson/第01课/demo/src/main/java/com/lynn/HelloController.java 3 | -------------------------------------------------------------------------------- /第02课/demo/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /第02课/demo/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /第02课/demo/.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /第02课/demo/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /第02课/demo/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /第02课/demo/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/AliyunAuto.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | @ConfigurationProperties(prefix = "oss") 8 | public class AliyunAuto { 9 | 10 | private String appKey; 11 | 12 | private String appSecret; 13 | 14 | private String bucket; 15 | 16 | private String endPoint; 17 | 18 | public String getAppKey() { 19 | return appKey; 20 | } 21 | 22 | public void setAppKey(String appKey) { 23 | this.appKey = appKey; 24 | } 25 | 26 | public String getAppSecret() { 27 | return appSecret; 28 | } 29 | 30 | public void setAppSecret(String appSecret) { 31 | this.appSecret = appSecret; 32 | } 33 | 34 | public String getBucket() { 35 | return bucket; 36 | } 37 | 38 | public void setBucket(String bucket) { 39 | this.bucket = bucket; 40 | } 41 | 42 | public String getEndPoint() { 43 | return endPoint; 44 | } 45 | 46 | public void setEndPoint(String endPoint) { 47 | this.endPoint = endPoint; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "AliyunAuto{" + 53 | "appKey='" + appKey + '\'' + 54 | ", appSecret='" + appSecret + '\'' + 55 | ", bucket='" + bucket + '\'' + 56 | ", endPoint='" + endPoint + '\'' + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/ApiInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.lang.Nullable; 4 | import org.springframework.web.servlet.HandlerInterceptor; 5 | import org.springframework.web.servlet.ModelAndView; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | public class ApiInterceptor implements HandlerInterceptor { 11 | 12 | @Override 13 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 14 | System.out.println("进入拦截器"); 15 | return true; 16 | } 17 | 18 | @Override 19 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { 20 | 21 | } 22 | 23 | @Override 24 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/AuthorizeIn.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import javax.validation.constraints.NotBlank; 4 | 5 | public class AuthorizeIn { 6 | 7 | @NotBlank(message = "缺少response_type参数") 8 | private String responseType; 9 | @NotBlank(message = "缺少client_id参数") 10 | private String ClientId; 11 | 12 | private String state; 13 | 14 | @NotBlank(message = "缺少redirect_uri参数") 15 | private String redirectUri; 16 | 17 | public String getResponseType() { 18 | return responseType; 19 | } 20 | 21 | public void setResponseType(String responseType) { 22 | this.responseType = responseType; 23 | } 24 | 25 | public String getClientId() { 26 | return ClientId; 27 | } 28 | 29 | public void setClientId(String clientId) { 30 | ClientId = clientId; 31 | } 32 | 33 | public String getState() { 34 | return state; 35 | } 36 | 37 | public void setState(String state) { 38 | this.state = state; 39 | } 40 | 41 | public String getRedirectUri() { 42 | return redirectUri; 43 | } 44 | 45 | public void setRedirectUri(String redirectUri) { 46 | this.redirectUri = redirectUri; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | public class DemoApplication extends SpringBootServletInitializer { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DemoApplication.class,args); 13 | } 14 | 15 | @Override 16 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 17 | return application.sources(DemoApplication.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import com.lynn.version.ApiVersion; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.util.Assert; 7 | import org.springframework.validation.BindingResult; 8 | import org.springframework.validation.FieldError; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import javax.validation.Valid; 14 | import java.util.List; 15 | 16 | @RestController 17 | @RequestMapping("{version}") 18 | @ApiVersion(1) 19 | public class HelloController { 20 | 21 | @Value("${server.port}") 22 | String port; 23 | @Autowired 24 | private Aliyun aliyun; 25 | @RequestMapping("/hello") 26 | public String home(String name) { 27 | return "hi "+name+",i am from port:" +port+aliyun; 28 | } 29 | 30 | @RequestMapping("authorize") 31 | public void authorize(@Valid AuthorizeIn authorize, BindingResult result){ 32 | if(result.hasFieldErrors()){ 33 | List errorList = result.getFieldErrors(); 34 | //通过断言抛出参数不合法的异常 35 | errorList.stream().forEach(item -> Assert.isTrue(false,item.getDefaultMessage())); 36 | } 37 | } 38 | 39 | @ExceptionHandler 40 | public String doError(Exception ex) throws Exception{ 41 | ex.printStackTrace(); 42 | return ex.getMessage(); 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/controller/PageController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class PageController { 8 | 9 | @RequestMapping("index.html") 10 | public String index(){ 11 | return "index"; 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/version/ApiVersion.java: -------------------------------------------------------------------------------- 1 | package com.lynn.version; 2 | 3 | import org.springframework.web.bind.annotation.Mapping; 4 | 5 | import java.lang.annotation.*; 6 | 7 | @Target({ElementType.METHOD,ElementType.TYPE}) 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Documented 10 | @Mapping 11 | public @interface ApiVersion { 12 | 13 | /** 14 | * 标识版本号 15 | * @return 16 | */ 17 | int value(); 18 | } 19 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/version/ApiVersionCondition.java: -------------------------------------------------------------------------------- 1 | package com.lynn.version; 2 | 3 | import org.springframework.web.servlet.mvc.condition.RequestCondition; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class ApiVersionCondition implements RequestCondition { 10 | 11 | // 路径中版本的前缀, 这里用 /v[1-9]/的形式 12 | private final static Pattern VERSION_PREFIX_PATTERN = Pattern.compile("v(\\d+)/"); 13 | 14 | private int apiVersion; 15 | 16 | public ApiVersionCondition(int apiVersion){ 17 | this.apiVersion = apiVersion; 18 | } 19 | 20 | @Override 21 | public ApiVersionCondition combine(ApiVersionCondition other) { 22 | // 采用最后定义优先原则,则方法上的定义覆盖类上面的定义 23 | return new ApiVersionCondition(other.getApiVersion()); 24 | } 25 | 26 | @Override 27 | public ApiVersionCondition getMatchingCondition(HttpServletRequest request) { 28 | Matcher m = VERSION_PREFIX_PATTERN.matcher(request.getRequestURI()); 29 | if(m.find()){ 30 | Integer version = Integer.valueOf(m.group(1)); 31 | if(version >= this.apiVersion) 32 | { 33 | return this; 34 | } 35 | } 36 | return null; 37 | } 38 | 39 | @Override 40 | public int compareTo(ApiVersionCondition other, HttpServletRequest request) { 41 | // 优先匹配最新的版本号 42 | return other.getApiVersion() - this.apiVersion; 43 | } 44 | 45 | public int getApiVersion() { 46 | return apiVersion; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /第02课/demo/src/main/java/com/lynn/version/CustomRequestMappingHandlerMapping.java: -------------------------------------------------------------------------------- 1 | package com.lynn.version; 2 | 3 | import org.springframework.core.annotation.AnnotationUtils; 4 | import org.springframework.web.servlet.mvc.condition.RequestCondition; 5 | import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | public class CustomRequestMappingHandlerMapping extends 10 | RequestMappingHandlerMapping{ 11 | 12 | @Override 13 | protected RequestCondition getCustomTypeCondition(Class handlerType) { 14 | ApiVersion apiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class); 15 | return createCondition(apiVersion); 16 | } 17 | 18 | @Override 19 | protected RequestCondition getCustomMethodCondition(Method method) { 20 | ApiVersion apiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class); 21 | return createCondition(apiVersion); 22 | } 23 | 24 | private RequestCondition createCondition(ApiVersion apiVersion) { 25 | return apiVersion == null ? null : new ApiVersionCondition(apiVersion.value()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第02课/demo/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /第02课/demo/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 -------------------------------------------------------------------------------- /第02课/demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | servlet: 3 | context-path: /api 4 | tomcat: 5 | max-threads: 1000 6 | min-spare-threads: 50 7 | # basedir: /data/tmp 8 | connection-timeout: 5000 9 | spring: 10 | profiles: 11 | active: dev 12 | http: 13 | multipart: 14 | max-file-fize: -1 15 | oss: 16 | appKey: 1 17 | appSecret: 1 18 | bucket: lynn 19 | endPoint: https://www.aliyun.com -------------------------------------------------------------------------------- /第02课/demo/src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Hello World!

8 | 9 | -------------------------------------------------------------------------------- /第02课/demo/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.AliyunAuto; 4 | import com.lynn.DemoApplication; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = DemoApplication.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private AliyunAuto aliyun; 17 | 18 | @Test 19 | public void test(){ 20 | System.out.println(aliyun); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第02课/demo/target/classes/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /第02课/demo/target/classes/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 -------------------------------------------------------------------------------- /第02课/demo/target/classes/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | servlet: 3 | context-path: /api 4 | tomcat: 5 | max-threads: 1000 6 | min-spare-threads: 50 7 | # basedir: /data/tmp 8 | connection-timeout: 5000 9 | spring: 10 | profiles: 11 | active: dev 12 | http: 13 | multipart: 14 | maxFileSize: -1 15 | oss: 16 | appKey: 1 17 | appSecret: 1 18 | bucket: lynn 19 | endPoint: https://www.aliyun.com -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/Aliyun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/Aliyun$1.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/Aliyun$Builder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/Aliyun$Builder.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/Aliyun.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/Aliyun.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/AliyunAuto.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/AliyunAuto.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/ApiInterceptor.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/ApiInterceptor.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/AuthorizeIn.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/AuthorizeIn.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/DemoApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/DemoApplication.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/HelloController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/HelloController.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/WebConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/WebConfig.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/WebExceptionAspect.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/WebExceptionAspect.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/controller/PageController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/controller/PageController.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/version/ApiVersion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/version/ApiVersion.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/version/ApiVersionCondition.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/version/ApiVersionCondition.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/com/lynn/version/CustomRequestMappingHandlerMapping.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/classes/com/lynn/version/CustomRequestMappingHandlerMapping.class -------------------------------------------------------------------------------- /第02课/demo/target/classes/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Hello World!

8 | 9 | -------------------------------------------------------------------------------- /第02课/demo/target/test-classes/com/lynn/test/TestDB.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lynnlovemin/SpringCloudLesson/d4042a9a6e1b5904ae4902d85c3112a96d694db6/第02课/demo/target/test-classes/com/lynn/test/TestDB.class -------------------------------------------------------------------------------- /第03课/demo/src/main/java/com/lynn/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication 9 | public class DemoApplication extends SpringBootServletInitializer { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DemoApplication.class,args); 13 | } 14 | 15 | @Override 16 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 17 | return application.sources(DemoApplication.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第03课/demo/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /第03课/demo/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8082 -------------------------------------------------------------------------------- /第03课/demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | servlet: 3 | context-path: /api 4 | tomcat: 5 | max-threads: 1000 6 | min-spare-threads: 50 7 | # basedir: /data/tmp 8 | connection-timeout: 5000 9 | spring: 10 | profiles: 11 | active: dev -------------------------------------------------------------------------------- /第04课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第04课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringCloudApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第04课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: true 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第04课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | 13 | pom 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 2.1.3.RELEASE 19 | 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-dependencies 26 | Greenwich.RELEASE 27 | pom 28 | import 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /第05课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | -------------------------------------------------------------------------------- /第05课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第05课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @Value("${server.port}") 11 | private int port; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return "Hello World!,端口:"+port; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第05课/springcloud/eurekaclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8762 7 | spring: 8 | application: 9 | name: eurekaclient -------------------------------------------------------------------------------- /第05课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第05课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringCloudApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第05课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第05课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | 14 | pom 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 2.1.3.RELEASE 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-dependencies 27 | Greenwich.RELEASE 28 | pom 29 | import 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /第06课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | -------------------------------------------------------------------------------- /第06课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第06课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @Value("${server.port}") 11 | private int port; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return "Hello World!,端口:"+port; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第06课/springcloud/eurekaclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8762 7 | spring: 8 | application: 9 | name: eurekaclient -------------------------------------------------------------------------------- /第06课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第06课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @SpringCloudApplication 9 | @EnableEurekaServer 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | } -------------------------------------------------------------------------------- /第06课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第06课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-gateway 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-webflux 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix 30 | 31 | 32 | -------------------------------------------------------------------------------- /第06课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiGlobalFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.io.buffer.DataBuffer; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ServerWebExchange; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Component 18 | public class ApiGlobalFilter implements GlobalFilter { 19 | 20 | @Override 21 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 22 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 23 | if (StringUtils.isBlank(token)) { 24 | ServerHttpResponse response = exchange.getResponse(); 25 | Map message = new HashMap<>(); 26 | message.put("status", -1); 27 | message.put("data", "鉴权失败"); 28 | byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); 29 | DataBuffer buffer = response.bufferFactory().wrap(bits); 30 | response.setStatusCode(HttpStatus.UNAUTHORIZED); 31 | response.getHeaders().add("Content-Type", "text/json;charset=UTF-8"); 32 | return response.writeWith(Mono.just(buffer)); 33 | } 34 | return chain.filter(exchange); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第06课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第06课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: gateway 6 | cloud: 7 | gateway: 8 | discovery: 9 | locator: 10 | enabled: true 11 | logging: 12 | level: 13 | org.springframework.cloud.gateway: trace 14 | org.springframework.http.server.reactive: debug 15 | org.springframework.web.reactive: debug 16 | reactor.ipc.netty: debug 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第06课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | 15 | pom 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-parent 20 | 2.1.3.RELEASE 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-dependencies 28 | Greenwich.RELEASE 29 | pom 30 | import 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /第07课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | -------------------------------------------------------------------------------- /第07课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第07课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @Value("${server.port}") 11 | private int port; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return "Hello World!,端口:"+port; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第07课/springcloud/eurekaclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8763 7 | spring: 8 | application: 9 | name: eurekaclient -------------------------------------------------------------------------------- /第07课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第07课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @SpringCloudApplication 9 | @EnableEurekaServer 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | } -------------------------------------------------------------------------------- /第07课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第07课/springcloud/feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-openfeign 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | -------------------------------------------------------------------------------- /第07课/springcloud/feign/src/main/java/com/lynn/feign/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | @FeignClient(value = "eurekaclient") 8 | public interface ApiService { 9 | 10 | @RequestMapping(value = "/index",method = RequestMethod.GET) 11 | String index(); 12 | } 13 | -------------------------------------------------------------------------------- /第07课/springcloud/feign/src/main/java/com/lynn/feign/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @SpringCloudApplication 9 | @EnableFeignClients 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /第07课/springcloud/feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8081 7 | spring: 8 | application: 9 | name: feign -------------------------------------------------------------------------------- /第07课/springcloud/feign/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.feign.ApiService; 4 | import com.lynn.feign.Application; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = Application.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private ApiService apiService; 17 | 18 | @Test 19 | public void test(){ 20 | try { 21 | System.out.println(apiService.index()); 22 | }catch (Exception e){ 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第07课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-gateway 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-webflux 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix 30 | 31 | 32 | -------------------------------------------------------------------------------- /第07课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiGlobalFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.io.buffer.DataBuffer; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ServerWebExchange; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Component 18 | public class ApiGlobalFilter implements GlobalFilter { 19 | 20 | @Override 21 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 22 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 23 | if (StringUtils.isBlank(token)) { 24 | ServerHttpResponse response = exchange.getResponse(); 25 | Map message = new HashMap<>(); 26 | message.put("status", -1); 27 | message.put("data", "鉴权失败"); 28 | byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); 29 | DataBuffer buffer = response.bufferFactory().wrap(bits); 30 | response.setStatusCode(HttpStatus.UNAUTHORIZED); 31 | response.getHeaders().add("Content-Type", "text/json;charset=UTF-8"); 32 | return response.writeWith(Mono.just(buffer)); 33 | } 34 | return chain.filter(exchange); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第07课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第07课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: gateway 6 | cloud: 7 | gateway: 8 | discovery: 9 | locator: 10 | enabled: true 11 | logging: 12 | level: 13 | org.springframework.cloud.gateway: trace 14 | org.springframework.http.server.reactive: debug 15 | org.springframework.web.reactive: debug 16 | reactor.ipc.netty: debug 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第07课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | feign 15 | 16 | pom 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.1.3.RELEASE 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-dependencies 29 | Greenwich.RELEASE 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /第08课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | -------------------------------------------------------------------------------- /第08课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第08课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @Value("${server.port}") 11 | private int port; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return "Hello World!,端口:"+port; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第08课/springcloud/eurekaclient/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8763 7 | spring: 8 | application: 9 | name: eurekaclient -------------------------------------------------------------------------------- /第08课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第08课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.SpringCloudApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @SpringCloudApplication 9 | @EnableEurekaServer 10 | public class Application { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | } -------------------------------------------------------------------------------- /第08课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第08课/springcloud/feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-openfeign 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-netflix-hystrix-dashboard 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | test 43 | 44 | 45 | -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/main/java/com/lynn/feign/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ApiController { 9 | 10 | @Autowired 11 | private ApiService apiService; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return apiService.index(); 16 | } 17 | } -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/main/java/com/lynn/feign/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | @FeignClient(value = "eurekaclient",fallback = ApiServiceError.class) 8 | public interface ApiService { 9 | 10 | @RequestMapping(value = "/index",method = RequestMethod.GET) 11 | String index(); 12 | } 13 | -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/main/java/com/lynn/feign/ApiServiceError.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class ApiServiceError implements ApiService { 7 | 8 | @Override 9 | public String index() { 10 | return "服务发生故障!"; 11 | } 12 | } -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/main/java/com/lynn/feign/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | 4 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 7 | import org.springframework.cloud.client.SpringCloudApplication; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.Bean; 11 | 12 | @SpringCloudApplication 13 | @EnableFeignClients 14 | @EnableHystrixDashboard 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | @Bean 22 | public ServletRegistrationBean getServlet(){ 23 | HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 24 | ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet ); 25 | registrationBean.setLoadOnStartup(1); 26 | registrationBean.addUrlMappings("/hystrix.stream"); 27 | registrationBean.setName("HystrixMetricsStreamServlet"); 28 | return registrationBean; 29 | } 30 | 31 | 32 | } -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8081 7 | spring: 8 | application: 9 | name: feign 10 | #开启熔断器 11 | feign: 12 | hystrix: 13 | enabled: true -------------------------------------------------------------------------------- /第08课/springcloud/feign/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.feign.ApiService; 4 | import com.lynn.feign.Application; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = Application.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private ApiService apiService; 17 | 18 | @Test 19 | public void test(){ 20 | try { 21 | System.out.println(apiService.index()); 22 | }catch (Exception e){ 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第08课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-gateway 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-webflux 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix 30 | 31 | 32 | -------------------------------------------------------------------------------- /第08课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiGlobalFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.io.buffer.DataBuffer; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ServerWebExchange; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Component 18 | public class ApiGlobalFilter implements GlobalFilter { 19 | 20 | @Override 21 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 22 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 23 | if (StringUtils.isBlank(token)) { 24 | ServerHttpResponse response = exchange.getResponse(); 25 | Map message = new HashMap<>(); 26 | message.put("status", -1); 27 | message.put("data", "鉴权失败"); 28 | byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); 29 | DataBuffer buffer = response.bufferFactory().wrap(bits); 30 | response.setStatusCode(HttpStatus.UNAUTHORIZED); 31 | response.getHeaders().add("Content-Type", "text/json;charset=UTF-8"); 32 | return response.writeWith(Mono.just(buffer)); 33 | } 34 | return chain.filter(exchange); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第08课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第08课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: gateway 6 | cloud: 7 | gateway: 8 | discovery: 9 | locator: 10 | enabled: true 11 | logging: 12 | level: 13 | org.springframework.cloud.gateway: trace 14 | org.springframework.http.server.reactive: debug 15 | org.springframework.web.reactive: debug 16 | reactor.ipc.netty: debug 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第08课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | feign 15 | 16 | pom 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-parent 21 | 2.1.3.RELEASE 22 | 23 | 24 | 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-dependencies 29 | Greenwich.RELEASE 30 | pom 31 | import 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /第09课/ config/eurekaclient.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8764 3 | spring: 4 | application: 5 | name: eurekaclient 6 | rabbitmq: 7 | host: localhost 8 | port: 5672 9 | username: guest 10 | password: guest 11 | zipkin: 12 | base-url: http://localhost:9411 13 | sender: 14 | type: web 15 | sleuth: 16 | sampler: 17 | probability : 1 18 | management: 19 | endpoints: 20 | web: 21 | exposure: 22 | include: refresh,health,info,bus-refresh 23 | -------------------------------------------------------------------------------- /第09课/springcloud/config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | config 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-config-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-eureka-client 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | -------------------------------------------------------------------------------- /第09课/springcloud/config/src/main/java/com/lynn/config/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringCloudApplication 8 | @EnableConfigServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class,args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /第09课/springcloud/config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: config 6 | profiles: 7 | active: dev 8 | cloud: 9 | config: 10 | server: 11 | git: 12 | uri: https://github.com/lynnlovemin/SpringCloudLesson.git #配置git仓库地址 13 | searchPaths: 第09课/config #配置仓库路径 14 | username: lynnlovemin #访问git仓库的用户名 15 | password: ****** #访问git仓库的用户密码 16 | label: master #配置仓库的分支 17 | rabbitmq: 18 | host: 127.0.0.1 19 | port: 5672 20 | username: guest 21 | password: guest 22 | virtualHost: / 23 | publisherConfirms: true 24 | eureka: 25 | client: 26 | serviceUrl: 27 | defaultZone: http://localhost:8761/eureka/ 28 | management: 29 | endpoints: 30 | web: 31 | exposure: 32 | include: refresh,health,info,bus-refresh -------------------------------------------------------------------------------- /第09课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-config 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-bus-amqp 38 | 39 | 40 | -------------------------------------------------------------------------------- /第09课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第09课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RefreshScope 10 | public class HelloController { 11 | 12 | @Value("${server.port}") 13 | private int port; 14 | 15 | @RequestMapping("index") 16 | public String index(){ 17 | return "Hello World!,端口:"+port; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第09课/springcloud/eurekaclient/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: eurekaclient 5 | label: master 6 | discovery: 7 | enabled: true 8 | serviceId: config 9 | eureka: 10 | client: 11 | service-url: 12 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第09课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第09课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringCloudApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第09课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第09课/springcloud/feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-openfeign 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-netflix-hystrix-dashboard 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | test 43 | 44 | 45 | -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/main/java/com/lynn/feign/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ApiController { 9 | 10 | @Autowired 11 | private ApiService apiService; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return apiService.index(); 16 | } 17 | } -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/main/java/com/lynn/feign/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | @FeignClient(value = "eurekaclient",fallback = ApiServiceError.class) 8 | public interface ApiService { 9 | 10 | @RequestMapping(value = "/index",method = RequestMethod.GET) 11 | String index(); 12 | } 13 | -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/main/java/com/lynn/feign/ApiServiceError.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class ApiServiceError implements ApiService { 7 | 8 | @Override 9 | public String index() { 10 | return "服务发生故障!"; 11 | } 12 | } -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/main/java/com/lynn/feign/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | 4 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 7 | import org.springframework.cloud.client.SpringCloudApplication; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.Bean; 11 | 12 | @SpringCloudApplication 13 | @EnableFeignClients 14 | @EnableHystrixDashboard 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | @Bean 22 | public ServletRegistrationBean getServlet(){ 23 | HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 24 | ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet ); 25 | registrationBean.setLoadOnStartup(1); 26 | registrationBean.addUrlMappings("/hystrix.stream"); 27 | registrationBean.setName("HystrixMetricsStreamServlet"); 28 | return registrationBean; 29 | } 30 | 31 | 32 | } -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8081 7 | spring: 8 | application: 9 | name: feign 10 | #开启熔断器 11 | feign: 12 | hystrix: 13 | enabled: true -------------------------------------------------------------------------------- /第09课/springcloud/feign/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.feign.ApiService; 4 | import com.lynn.feign.Application; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = Application.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private ApiService apiService; 17 | 18 | @Test 19 | public void test(){ 20 | try { 21 | System.out.println(apiService.index()); 22 | }catch (Exception e){ 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第09课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-gateway 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-webflux 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix 30 | 31 | 32 | -------------------------------------------------------------------------------- /第09课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiGlobalFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.io.buffer.DataBuffer; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ServerWebExchange; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Component 18 | public class ApiGlobalFilter implements GlobalFilter { 19 | 20 | @Override 21 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 22 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 23 | if (StringUtils.isBlank(token)) { 24 | ServerHttpResponse response = exchange.getResponse(); 25 | Map message = new HashMap<>(); 26 | message.put("status", -1); 27 | message.put("data", "鉴权失败"); 28 | byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); 29 | DataBuffer buffer = response.bufferFactory().wrap(bits); 30 | response.setStatusCode(HttpStatus.UNAUTHORIZED); 31 | response.getHeaders().add("Content-Type", "text/json;charset=UTF-8"); 32 | return response.writeWith(Mono.just(buffer)); 33 | } 34 | return chain.filter(exchange); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第09课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第09课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: gateway 6 | cloud: 7 | gateway: 8 | discovery: 9 | locator: 10 | enabled: true 11 | logging: 12 | level: 13 | org.springframework.cloud.gateway: trace 14 | org.springframework.http.server.reactive: debug 15 | org.springframework.web.reactive: debug 16 | reactor.ipc.netty: debug 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第09课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | feign 15 | config 16 | 17 | pom 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-parent 22 | 2.1.3.RELEASE 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-dependencies 30 | Greenwich.RELEASE 31 | pom 32 | import 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /第10课/springcloud/config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | config 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-config-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-eureka-client 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | -------------------------------------------------------------------------------- /第10课/springcloud/config/src/main/java/com/lynn/config/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @SpringCloudApplication 8 | @EnableConfigServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class,args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /第10课/springcloud/config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: config 6 | profiles: 7 | active: dev 8 | cloud: 9 | config: 10 | server: 11 | git: 12 | uri: https://github.com/lynnlovemin/SpringCloudLesson.git #配置git仓库地址 13 | searchPaths: 第09课/config #配置仓库路径 14 | username: lynnlovemin #访问git仓库的用户名 15 | password: 1qaz,2wsx,3edc. #访问git仓库的用户密码 16 | label: master #配置仓库的分支 17 | rabbitmq: 18 | host: 127.0.0.1 19 | port: 5672 20 | username: guest 21 | password: guest 22 | virtualHost: / 23 | publisherConfirms: true 24 | eureka: 25 | client: 26 | serviceUrl: 27 | defaultZone: http://localhost:8761/eureka/ 28 | management: 29 | endpoints: 30 | web: 31 | exposure: 32 | include: refresh,health,info,bus-refresh,bus-trace -------------------------------------------------------------------------------- /第10课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-config 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-starter-bus-amqp 38 | 39 | 40 | -------------------------------------------------------------------------------- /第10课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /第10课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RefreshScope 10 | public class HelloController { 11 | 12 | @Value("${server.port}") 13 | private int port; 14 | 15 | @RequestMapping("index") 16 | public String index(){ 17 | return "Hello World!,端口:"+port; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第10课/springcloud/eurekaclient/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | cloud: 3 | config: 4 | name: eurekaclient 5 | label: master 6 | discovery: 7 | enabled: true 8 | serviceId: config 9 | rabbitmq: 10 | host: 127.0.0.1 11 | port: 5672 12 | username: guest 13 | password: guest 14 | virtualHost: / 15 | publisherConfirms: true 16 | eureka: 17 | client: 18 | service-url: 19 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第10课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-server 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-netflix-hystrix 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-eureka-client 26 | 27 | 28 | -------------------------------------------------------------------------------- /第10课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringCloudApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第10课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | application: 5 | name: eurekaserver 6 | profiles: 7 | active: dev 8 | cloud: 9 | inetutils: 10 | preferred-networks: 127.0.0.1 11 | client: 12 | ip-address: 127.0.0.1 13 | eureka: 14 | server: 15 | peer-node-read-timeout-ms: 3000 16 | enable-self-preservation: true 17 | instance: 18 | prefer-ip-address: false 19 | instance-id: ${spring.cloud.client.ip-address}:${server.port} 20 | client: 21 | registerWithEureka: true 22 | fetchRegistry: false 23 | healthcheck: 24 | enabled: true 25 | serviceUrl: 26 | defaultZone: http://127.0.0.1:8761/eureka/ -------------------------------------------------------------------------------- /第10课/springcloud/feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-openfeign 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-hystrix 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-netflix-hystrix-dashboard 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-actuator 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter-test 42 | test 43 | 44 | 45 | -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/main/java/com/lynn/feign/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ApiController { 9 | 10 | @Autowired 11 | private ApiService apiService; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return apiService.index(); 16 | } 17 | } -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/main/java/com/lynn/feign/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | @FeignClient(value = "eurekaclient",fallback = ApiServiceError.class) 8 | public interface ApiService { 9 | 10 | @RequestMapping(value = "/index",method = RequestMethod.GET) 11 | String index(); 12 | } 13 | -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/main/java/com/lynn/feign/ApiServiceError.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class ApiServiceError implements ApiService { 7 | 8 | @Override 9 | public String index() { 10 | return "服务发生故障!"; 11 | } 12 | } -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/main/java/com/lynn/feign/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | 4 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 7 | import org.springframework.cloud.client.SpringCloudApplication; 8 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 9 | import org.springframework.cloud.openfeign.EnableFeignClients; 10 | import org.springframework.context.annotation.Bean; 11 | 12 | @SpringCloudApplication 13 | @EnableFeignClients 14 | @EnableHystrixDashboard 15 | public class Application { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(Application.class, args); 19 | } 20 | 21 | @Bean 22 | public ServletRegistrationBean getServlet(){ 23 | HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet(); 24 | ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet ); 25 | registrationBean.setLoadOnStartup(1); 26 | registrationBean.addUrlMappings("/hystrix.stream"); 27 | registrationBean.setName("HystrixMetricsStreamServlet"); 28 | return registrationBean; 29 | } 30 | 31 | 32 | } -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8081 7 | spring: 8 | application: 9 | name: feign 10 | #开启熔断器 11 | feign: 12 | hystrix: 13 | enabled: true -------------------------------------------------------------------------------- /第10课/springcloud/feign/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.feign.ApiService; 4 | import com.lynn.feign.Application; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = Application.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private ApiService apiService; 17 | 18 | @Test 19 | public void test(){ 20 | try { 21 | System.out.println(apiService.index()); 22 | }catch (Exception e){ 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第10课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-netflix-eureka-client 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-gateway 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-webflux 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-netflix-hystrix 30 | 31 | 32 | -------------------------------------------------------------------------------- /第10课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiGlobalFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.io.buffer.DataBuffer; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.server.reactive.ServerHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.server.ServerWebExchange; 11 | import reactor.core.publisher.Mono; 12 | 13 | import java.nio.charset.StandardCharsets; 14 | import java.util.HashMap; 15 | import java.util.Map; 16 | 17 | @Component 18 | public class ApiGlobalFilter implements GlobalFilter { 19 | 20 | @Override 21 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 22 | String token = exchange.getRequest().getQueryParams().getFirst("token"); 23 | if (StringUtils.isBlank(token)) { 24 | ServerHttpResponse response = exchange.getResponse(); 25 | Map message = new HashMap<>(); 26 | message.put("status", -1); 27 | message.put("data", "鉴权失败"); 28 | byte[] bits = message.toString().getBytes(StandardCharsets.UTF_8); 29 | DataBuffer buffer = response.bufferFactory().wrap(bits); 30 | response.setStatusCode(HttpStatus.UNAUTHORIZED); 31 | response.getHeaders().add("Content-Type", "text/json;charset=UTF-8"); 32 | return response.writeWith(Mono.just(buffer)); 33 | } 34 | return chain.filter(exchange); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /第10课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.cloud.client.SpringCloudApplication; 5 | 6 | @SpringCloudApplication 7 | public class Application { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第10课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: gateway 6 | cloud: 7 | gateway: 8 | discovery: 9 | locator: 10 | enabled: true 11 | logging: 12 | level: 13 | org.springframework.cloud.gateway: trace 14 | org.springframework.http.server.reactive: debug 15 | org.springframework.web.reactive: debug 16 | reactor.ipc.netty: debug 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /第10课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | feign 15 | config 16 | 17 | pom 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-parent 22 | 2.1.3.RELEASE 23 | 24 | 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-bus-amqp 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-dependencies 36 | Greenwich.RELEASE 37 | pom 38 | import 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /第11课/springcloud/config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | config 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-config-server 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-bus-amqp 26 | 27 | 28 | -------------------------------------------------------------------------------- /第11课/springcloud/config/src/main/java/com/lynn/config/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableConfigServer 11 | public class Application { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class,args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /第11课/springcloud/config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | spring: 4 | application: 5 | name: config 6 | profiles: 7 | active: dev 8 | cloud: 9 | bus: 10 | trace: 11 | enable: true 12 | config: 13 | server: 14 | git: 15 | uri: https://github.com/lynnlovemin/SpringCloudLesson.git #配置git仓库地址 16 | searchPaths: 第09课/config #配置仓库路径 17 | username: lynnlovemin #访问git仓库的用户名 18 | password: ****** #访问git仓库的用户密码 19 | label: master #配置仓库的分支 20 | rabbitmq: 21 | host: localhost 22 | port: 5672 23 | username: guest 24 | password: guest 25 | eureka: 26 | instance: 27 | hostname: ${spring.cloud.client.ipAddress} 28 | instanceId: ${spring.cloud.client.ipAddress}:${server.port} 29 | client: 30 | serviceUrl: 31 | defaultZone: http://localhost:8761/eureka/ 32 | management: 33 | security: 34 | enabled: false 35 | -------------------------------------------------------------------------------- /第11课/springcloud/eurekaclient/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaclient 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-config 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-bus-amqp 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-sleuth-stream 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-sleuth-zipkin 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-stream-binder-rabbit 38 | 39 | 40 | -------------------------------------------------------------------------------- /第11课/springcloud/eurekaclient/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第11课/springcloud/eurekaclient/src/main/java/com/lynn/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @RefreshScope 10 | public class HelloController { 11 | 12 | @Value("${server.port}") 13 | private int port; 14 | 15 | @RequestMapping("index") 16 | public String index(){ 17 | return "Hello World!,端口:"+port; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /第11课/springcloud/eurekaclient/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: eurekaclient 4 | profiles: 5 | active: dev 6 | cloud: 7 | config: 8 | profile: dev #指定配置环境,配置文件如果是多环境则取名类似:config-dev.yml 9 | name: eurekaclient #指定配置文件名字(多个配置文件以英文逗号隔开) 10 | label: master #git仓库分支名 11 | discovery: 12 | enabled: true 13 | serviceId: config #连接的配置中心名字(applicaiton.name) -------------------------------------------------------------------------------- /第11课/springcloud/eurekaserver/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | eurekaserver 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka-server 18 | 19 | 20 | -------------------------------------------------------------------------------- /第11课/springcloud/eurekaserver/src/main/java/com/lynn/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class Application { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Application.class, args); 13 | } 14 | } -------------------------------------------------------------------------------- /第11课/springcloud/eurekaserver/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | spring: 4 | profiles: 5 | active: dev 6 | eureka: 7 | server: 8 | enable-self-preservation: false 9 | instance: 10 | preferIpAddress: true 11 | hostname: ${spring.cloud.client.ipAddress} 12 | instanceId: ${spring.cloud.client.ipAddress}:${server.port} 13 | client: 14 | registerWithEureka: false 15 | fetchRegistry: false 16 | serviceUrl: 17 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /第11课/springcloud/feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | feign 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-feign 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-hystrix 26 | 27 | 28 | org.springframework.cloud 29 | spring-cloud-starter-hystrix-dashboard 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-actuator 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/main/java/com/lynn/feign/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class ApiController { 9 | 10 | @Autowired 11 | private ApiService apiService; 12 | 13 | @RequestMapping("index") 14 | public String index(){ 15 | return apiService.index(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/main/java/com/lynn/feign/ApiService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.cloud.netflix.feign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | 7 | @FeignClient(value = "eurekaclient",fallback = ApiServiceError.class) 8 | public interface ApiService { 9 | 10 | @RequestMapping(value = "/index",method = RequestMethod.GET) 11 | String index(); 12 | } 13 | -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/main/java/com/lynn/feign/ApiServiceError.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | @Component 6 | public class ApiServiceError implements ApiService { 7 | 8 | @Override 9 | public String index() { 10 | return "服务发生故障!"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/main/java/com/lynn/feign/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.feign; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.netflix.feign.EnableFeignClients; 9 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 10 | 11 | @SpringBootApplication 12 | @EnableEurekaClient 13 | @EnableFeignClients 14 | @EnableHystrixDashboard 15 | @EnableCircuitBreaker 16 | public class Application { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(Application.class, args); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8081 7 | spring: 8 | application: 9 | name: feign 10 | feign: 11 | hystrix: 12 | enabled: true -------------------------------------------------------------------------------- /第11课/springcloud/feign/src/test/java/com/lynn/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.test; 2 | 3 | import com.lynn.feign.ApiService; 4 | import com.lynn.feign.Application; 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 10 | 11 | @SpringBootTest(classes = Application.class) 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | public class TestDB { 14 | 15 | @Autowired 16 | private ApiService apiService; 17 | 18 | @Test 19 | public void test(){ 20 | try { 21 | System.out.println(apiService.index()); 22 | }catch (Exception e){ 23 | e.printStackTrace(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第11课/springcloud/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | 14 | 15 | 16 | org.springframework.cloud 17 | spring-cloud-starter-eureka 18 | 19 | 20 | org.springframework.cloud 21 | spring-cloud-starter-zuul 22 | 23 | 24 | -------------------------------------------------------------------------------- /第11课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import org.springframework.cloud.netflix.zuul.filters.route.ZuulFallbackProvider; 4 | import org.springframework.http.HttpHeaders; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.client.ClientHttpResponse; 8 | import org.springframework.stereotype.Component; 9 | 10 | import java.io.ByteArrayInputStream; 11 | import java.io.IOException; 12 | import java.io.InputStream; 13 | 14 | /** 15 | * 错误拦截 16 | * 17 | * @author liyi 18 | * @create 2018-01-19 16:57 19 | **/ 20 | @Component 21 | public class ApiFallbackProvider implements ZuulFallbackProvider{ 22 | 23 | @Override 24 | public String getRoute() { 25 | return "eurekaclient"; 26 | } 27 | 28 | @Override 29 | public ClientHttpResponse fallbackResponse() { 30 | return new ClientHttpResponse() { 31 | @Override 32 | public HttpStatus getStatusCode() throws IOException { 33 | return HttpStatus.OK; 34 | } 35 | 36 | @Override 37 | public int getRawStatusCode() throws IOException { 38 | return 200; 39 | } 40 | 41 | @Override 42 | public String getStatusText() throws IOException { 43 | return "{code:0,message:\"服务器异常!\"}"; 44 | } 45 | 46 | @Override 47 | public void close() { 48 | 49 | } 50 | 51 | @Override 52 | public InputStream getBody() throws IOException { 53 | return new ByteArrayInputStream(getStatusText().getBytes()); 54 | } 55 | 56 | @Override 57 | public HttpHeaders getHeaders() { 58 | HttpHeaders headers = new HttpHeaders(); 59 | headers.setContentType(MediaType.APPLICATION_JSON); 60 | return headers; 61 | } 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /第11课/springcloud/gateway/src/main/java/com/lynn/gateway/ApiFilter.java: -------------------------------------------------------------------------------- 1 | package com.lynn.gateway; 2 | 3 | import com.netflix.zuul.ZuulFilter; 4 | import com.netflix.zuul.context.RequestContext; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | @Component 10 | public class ApiFilter extends ZuulFilter { 11 | 12 | @Override 13 | public String filterType() { 14 | return "pre"; 15 | } 16 | 17 | @Override 18 | public int filterOrder() { 19 | return 0; 20 | } 21 | 22 | @Override 23 | public boolean shouldFilter() { 24 | return true; 25 | } 26 | 27 | @Override 28 | public Object run() { 29 | //这里写校验代码 30 | RequestContext context = RequestContext.getCurrentContext(); 31 | HttpServletRequest request = context.getRequest(); 32 | String token = request.getParameter("token"); 33 | if(!"12345".equals(token)){ 34 | context.setSendZuulResponse(false); 35 | context.setResponseStatusCode(401); 36 | try { 37 | context.getResponse().getWriter().write("token is invalid."); 38 | }catch (Exception e){} 39 | } 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /第11课/springcloud/gateway/src/main/java/com/lynn/gateway/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.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 | import org.springframework.cloud.netflix.zuul.EnableZuulServer; 8 | 9 | @SpringBootApplication 10 | @EnableEurekaClient 11 | @EnableZuulProxy 12 | public class Application { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(Application.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /第11课/springcloud/gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: http://localhost:8761/eureka/ 5 | server: 6 | port: 8080 7 | spring: 8 | application: 9 | name: gateway 10 | zuul: 11 | routes: 12 | api: 13 | path: /api/** 14 | serviceId: eurekaclient 15 | -------------------------------------------------------------------------------- /第11课/springcloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.lynn 8 | springcloud 9 | 1.0-SNAPSHOT 10 | 11 | eurekaserver 12 | eurekaclient 13 | gateway 14 | feign 15 | config 16 | zipkin 17 | 18 | pom 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-parent 23 | 1.5.9.RELEASE 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-dependencies 31 | Dalston.SR5 32 | pom 33 | import 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /第11课/springcloud/zipkin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springcloud 7 | com.lynn 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | zipkin 13 | 服务链路追踪 14 | 15 | 16 | 17 | io.zipkin.java 18 | zipkin-autoconfigure-ui 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-sleuth-zipkin-stream 23 | 24 | 25 | org.springframework.cloud 26 | spring-cloud-starter-sleuth 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-stream-binder-rabbit 31 | 32 | 33 | io.zipkin.java 34 | zipkin-storage-mysql 35 | 2.4.9 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-jdbc 40 | 41 | 42 | mysql 43 | mysql-connector-java 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /第11课/springcloud/zipkin/src/main/java/com/lynn/zipkin/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.sleuth.zipkin.stream.EnableZipkinStreamServer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Primary; 8 | import zipkin.server.EnableZipkinServer; 9 | import zipkin.storage.mysql.MySQLStorage; 10 | 11 | import javax.sql.DataSource; 12 | 13 | @SpringBootApplication 14 | //@EnableZipkinServer 15 | @EnableZipkinStreamServer 16 | public class Application { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(Application.class,args); 20 | } 21 | 22 | @Bean 23 | @Primary 24 | public MySQLStorage mySQLStorage(DataSource datasource) { 25 | return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第11课/springcloud/zipkin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9411 3 | spring: 4 | rabbitmq: 5 | host: localhost 6 | port: 5672 7 | username: guest 8 | password: guest 9 | datasource: 10 | url: jdbc:mysql://localhost:3306/zipkin?autoReconnect=true 11 | username: root 12 | password: 1qaz2wsx 13 | driverClassName: com.mysql.jdbc.Driver 14 | zipkin: 15 | storage: 16 | type: mysql -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class Application { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class,args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | import com.lynn.demo.zk.DistributedLock; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @RequestMapping("index") 11 | public String index()throws Exception{ 12 | DistributedLock lock = new DistributedLock("localhost:2181","lock"); 13 | lock.lock(); 14 | //共享资源 15 | if(lock != null){ 16 | System.out.println("执行方法"); 17 | Thread.sleep(5000); 18 | lock.unlock(); 19 | } 20 | return "hello world!"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/Lock.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | /** 4 | * 全局锁,包括锁的名称 5 | */ 6 | public class Lock { 7 | private String name; 8 | private String value; 9 | 10 | public Lock(String name, String value) { 11 | this.name = name; 12 | this.value = value; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public String getValue() { 20 | return value; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/lock/AquiredLockWorker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 获取锁后需要处理的逻辑 5 | */ 6 | public interface AquiredLockWorker { 7 | T invokeAfterLockAquire() throws Exception; 8 | } 9 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/lock/DistributedLocker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 获取锁管理类 5 | */ 6 | public interface DistributedLocker { 7 | 8 | /** 9 | * 获取锁 10 | * @param resourceName 锁的名称 11 | * @param worker 获取锁后的处理类 12 | * @param 13 | * @return 处理完具体的业务逻辑要返回的数据 14 | * @throws UnableToAquireLockException 15 | * @throws Exception 16 | */ 17 | T lock(String resourceName, AquiredLockWorker worker) throws UnableToAquireLockException, Exception; 18 | 19 | T lock(String resourceName, AquiredLockWorker worker, int lockTime) throws UnableToAquireLockException, Exception; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/lock/RedisLocker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | import org.redisson.api.RLock; 4 | import org.redisson.api.RedissonClient; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | @Component 11 | public class RedisLocker implements DistributedLocker{ 12 | 13 | private final static String LOCKER_PREFIX = "lock:"; 14 | 15 | @Autowired 16 | RedissonConnector redissonConnector; 17 | @Override 18 | public T lock(String resourceName, AquiredLockWorker worker) throws InterruptedException, UnableToAquireLockException, Exception { 19 | 20 | return lock(resourceName, worker, 100); 21 | } 22 | 23 | @Override 24 | public T lock(String resourceName, AquiredLockWorker worker, int lockTime) throws UnableToAquireLockException, Exception { 25 | RedissonClient redisson= redissonConnector.getClient(); 26 | RLock lock = redisson.getLock(LOCKER_PREFIX + resourceName); 27 | // Wait for 100 seconds seconds and automatically unlock it after lockTime seconds 28 | boolean success = lock.tryLock(100, lockTime, TimeUnit.SECONDS); 29 | if (success) { 30 | try { 31 | return worker.invokeAfterLockAquire(); 32 | } finally { 33 | lock.unlock(); 34 | } 35 | } 36 | throw new UnableToAquireLockException(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/lock/RedissonConnector.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | import org.redisson.Redisson; 4 | import org.redisson.api.RedissonClient; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.PostConstruct; 8 | 9 | /** 10 | * 获取RedissonClient连接类 11 | */ 12 | @Component 13 | public class RedissonConnector { 14 | RedissonClient redisson; 15 | @PostConstruct 16 | public void init(){ 17 | redisson = Redisson.create(); 18 | } 19 | 20 | public RedissonClient getClient(){ 21 | return redisson; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /第12课/demo/src/main/java/com/lynn/demo/lock/UnableToAquireLockException.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 异常类 5 | */ 6 | public class UnableToAquireLockException extends RuntimeException { 7 | 8 | public UnableToAquireLockException() { 9 | } 10 | 11 | public UnableToAquireLockException(String message) { 12 | super(message); 13 | } 14 | 15 | public UnableToAquireLockException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第12课/demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | redis: 5 | host: localhost 6 | port: 6379 -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/Application.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | public class Application { 9 | 10 | public static void main(String[] args) { 11 | SpringApplication.run(Application.class,args); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/HelloController.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | import com.lynn.demo.zk.DistributedLock; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @RequestMapping("index") 11 | public String index()throws Exception{ 12 | DistributedLock lock = new DistributedLock("localhost:2181","lock"); 13 | lock.lock(); 14 | //共享资源 15 | if(lock != null){ 16 | System.out.println("执行方法"); 17 | Thread.sleep(5000); 18 | lock.unlock(); 19 | } 20 | return "hello world!"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/Lock.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo; 2 | 3 | /** 4 | * 全局锁,包括锁的名称 5 | */ 6 | public class Lock { 7 | private String name; 8 | private String value; 9 | 10 | public Lock(String name, String value) { 11 | this.name = name; 12 | this.value = value; 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public String getValue() { 20 | return value; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | public class User implements Serializable { 6 | 7 | private String name; 8 | 9 | private int age; 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | 15 | public void setName(String name) { 16 | this.name = name; 17 | } 18 | 19 | public int getAge() { 20 | return age; 21 | } 22 | 23 | public void setAge(int age) { 24 | this.age = age; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/lock/AquiredLockWorker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 获取锁后需要处理的逻辑 5 | */ 6 | public interface AquiredLockWorker { 7 | T invokeAfterLockAquire() throws Exception; 8 | } 9 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/lock/DistributedLocker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 获取锁管理类 5 | */ 6 | public interface DistributedLocker { 7 | 8 | /** 9 | * 获取锁 10 | * @param resourceName 锁的名称 11 | * @param worker 获取锁后的处理类 12 | * @param 13 | * @return 处理完具体的业务逻辑要返回的数据 14 | * @throws UnableToAquireLockException 15 | * @throws Exception 16 | */ 17 | T lock(String resourceName, AquiredLockWorker worker) throws UnableToAquireLockException, Exception; 18 | 19 | T lock(String resourceName, AquiredLockWorker worker, int lockTime) throws UnableToAquireLockException, Exception; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/lock/RedisLocker.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | import org.redisson.api.RLock; 4 | import org.redisson.api.RedissonClient; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | @Component 11 | public class RedisLocker implements DistributedLocker{ 12 | 13 | private final static String LOCKER_PREFIX = "lock:"; 14 | 15 | @Autowired 16 | RedissonConnector redissonConnector; 17 | @Override 18 | public T lock(String resourceName, AquiredLockWorker worker) throws InterruptedException, UnableToAquireLockException, Exception { 19 | 20 | return lock(resourceName, worker, 100); 21 | } 22 | 23 | @Override 24 | public T lock(String resourceName, AquiredLockWorker worker, int lockTime) throws UnableToAquireLockException, Exception { 25 | RedissonClient redisson= redissonConnector.getClient(); 26 | RLock lock = redisson.getLock(LOCKER_PREFIX + resourceName); 27 | // Wait for 100 seconds seconds and automatically unlock it after lockTime seconds 28 | boolean success = lock.tryLock(100, lockTime, TimeUnit.SECONDS); 29 | if (success) { 30 | try { 31 | return worker.invokeAfterLockAquire(); 32 | } finally { 33 | lock.unlock(); 34 | } 35 | } 36 | throw new UnableToAquireLockException(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/lock/RedissonConnector.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | import org.redisson.Redisson; 4 | import org.redisson.api.RedissonClient; 5 | import org.redisson.config.Config; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | /** 12 | * 获取RedissonClient连接类 13 | */ 14 | @Component 15 | public class RedissonConnector { 16 | 17 | @Value("${spring.redis.host}") 18 | private String host; 19 | @Value("${spring.redis.port}") 20 | private String port; 21 | // @Value("${spring.redis.password}") 22 | // private String password; 23 | 24 | RedissonClient redisson; 25 | @PostConstruct 26 | public void init(){ 27 | Config config = new Config(); 28 | config.useSingleServer().setAddress("redis://"+host+":"+port); 29 | // redisson = Redisson.create(config); 30 | } 31 | 32 | public RedissonClient getClient(){ 33 | return redisson; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/lock/UnableToAquireLockException.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.lock; 2 | 3 | /** 4 | * 异常类 5 | */ 6 | public class UnableToAquireLockException extends RuntimeException { 7 | 8 | public UnableToAquireLockException() { 9 | } 10 | 11 | public UnableToAquireLockException(String message) { 12 | super(message); 13 | } 14 | 15 | public UnableToAquireLockException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.service; 2 | 3 | import com.lynn.demo.entity.User; 4 | import com.lynn.demo.test01.UserMapper1; 5 | import com.lynn.demo.test02.UserMapper2; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | @Service 11 | public class UserService { 12 | 13 | @Autowired 14 | private UserMapper1 userMapper1; 15 | @Autowired 16 | private UserMapper2 userMapper2; 17 | 18 | @Transactional 19 | public void addUser(User user)throws Exception{ 20 | userMapper1.addUser(user.getName(),user.getAge()); 21 | String bb = null; 22 | if(bb.equals("aa")){ 23 | System.out.println("test"); 24 | } 25 | userMapper2.addUser(user.getName(),user.getAge()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/test01/UserMapper1.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.test01; 2 | 3 | import org.apache.ibatis.annotations.Insert; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | @Mapper 8 | public interface UserMapper1 { 9 | 10 | @Insert("insert into test_user(name,age) values(#{name},#{age})") 11 | void addUser(@Param("name")String name,@Param("age") int age); 12 | } 13 | -------------------------------------------------------------------------------- /第13课/demo/src/main/java/com/lynn/demo/test02/UserMapper2.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.test02; 2 | 3 | import org.apache.ibatis.annotations.Insert; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | @Mapper 8 | public interface UserMapper2 { 9 | 10 | @Insert("insert into test_user(name,age) values(#{name},#{age})") 11 | void addUser(@Param("name") String name,@Param("age") int age); 12 | } 13 | -------------------------------------------------------------------------------- /第13课/demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | redis: 5 | host: 127.0.0.1 6 | port: 6379 7 | mysql: 8 | datasource: 9 | test1: 10 | url: jdbc:mysql://localhost:3306/test01?useUnicode=true&characterEncoding=utf-8 11 | username: root 12 | password: 1qaz2wsx 13 | minPoolSize: 3 14 | maxPoolSize: 25 15 | maxLifetime: 20000 16 | borrowConnectionTimeout: 30 17 | loginTimeout: 30 18 | maintenanceInterval: 60 19 | maxIdleTime: 60 20 | testQuery: select 1 21 | test2: 22 | url: jdbc:mysql://localhost:3306/test02?useUnicode=true&characterEncoding=utf-8 23 | username: root 24 | password: 1qaz2wsx 25 | minPoolSize: 3 26 | maxPoolSize: 25 27 | maxLifetime: 20000 28 | borrowConnectionTimeout: 30 29 | loginTimeout: 30 30 | maintenanceInterval: 60 31 | maxIdleTime: 60 32 | testQuery: select 1 -------------------------------------------------------------------------------- /第13课/demo/src/test/java/com/lynn/demo/test/TestDB.java: -------------------------------------------------------------------------------- 1 | package com.lynn.demo.test; 2 | 3 | import com.lynn.demo.Application; 4 | import com.lynn.demo.entity.User; 5 | import com.lynn.demo.service.UserService; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 11 | 12 | @RunWith(SpringJUnit4ClassRunner.class) 13 | @SpringBootTest(classes = Application.class) 14 | public class TestDB { 15 | 16 | @Autowired 17 | private UserService userService; 18 | 19 | @Test 20 | public void test(){ 21 | User user = new User(); 22 | user.setName("lynn"); 23 | user.setAge(10); 24 | try { 25 | userService.addUser(user); 26 | }catch (Exception e){ 27 | e.printStackTrace(); 28 | } 29 | } 30 | } 31 | --------------------------------------------------------------------------------