├── .gitignore ├── .gradle ├── 5.4.1 │ ├── executionHistory │ │ ├── executionHistory.bin │ │ └── executionHistory.lock │ ├── fileChanges │ │ └── last-build.bin │ ├── fileHashes │ │ ├── fileHashes.bin │ │ └── fileHashes.lock │ └── gc.properties ├── buildOutputCleanup │ ├── buildOutputCleanup.lock │ ├── cache.properties │ └── outputFiles.bin ├── vcs-1 │ └── gc.properties ├── vcsWorkingDirs │ └── gc.properties ├── workspace-id.txt └── workspace-id.txt.lock ├── .idea ├── .gitignore ├── .name ├── GrepConsole.xml ├── artifacts │ ├── Gradle___com_fly___FlyCloud_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___FlyCloud_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___lib_common_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___lib_common_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_admin_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_admin_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_blog_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_blog_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_config_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_config_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_eureka_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_eureka_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_gateway_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_gateway_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_log_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_log_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_monitor_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_monitor_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_news_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_news_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_uaa_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_uaa_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_user_1_0_SNAPSHOT_war.xml │ ├── Gradle___com_fly___module_user_1_0_SNAPSHOT_war__exploded_.xml │ ├── Gradle___com_fly___module_zipkin_1_0_SNAPSHOT_war.xml │ └── Gradle___com_fly___module_zipkin_1_0_SNAPSHOT_war__exploded_.xml ├── compiler.xml ├── encodings.xml ├── gradle.xml ├── httpRequests │ └── http-requests-log.http ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib_common ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── fly │ └── common │ ├── annotation │ └── SysLogger.java │ ├── dto │ └── RespDTO.java │ └── exception │ ├── CommonException.java │ └── ErrorCode.java ├── module_admin ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── admin │ │ └── AdminServiceApplication.java │ └── resources │ ├── bootstrap.yml │ └── logback-spring.xml ├── module_blog ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── blog │ │ ├── BlogServiceApplication.java │ │ ├── aop │ │ └── SysLoggerAspect.java │ │ ├── client │ │ ├── UserServiceClient.java │ │ └── hystrix │ │ │ └── UserServiceHystrix.java │ │ ├── config │ │ ├── GlobalMethodSecurityConfiguration.java │ │ ├── JwtConfiguration.java │ │ ├── RabbitConfig.java │ │ ├── ResourceServerConfiguration.java │ │ └── SwaggerConfig.java │ │ ├── dao │ │ └── BlogDao.java │ │ ├── dto │ │ └── BlogDetailDTO.java │ │ ├── entity │ │ ├── Blog.java │ │ ├── SysLog.java │ │ └── User.java │ │ ├── exception │ │ └── CommonExceptionHandler.java │ │ ├── service │ │ ├── BlogService.java │ │ └── LoggerService.java │ │ ├── util │ │ ├── HttpUtils.java │ │ └── UserUtils.java │ │ └── web │ │ └── BlogController.java │ └── resources │ ├── bootstrap.yml │ └── public.cert ├── module_config ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── config │ │ └── ConfigServerApplication.java │ └── resources │ ├── application.yml │ └── shared │ ├── admin-service-pro.yml │ ├── application.yml │ ├── blog-service-pro.yml │ ├── gateway-service-pro.yml │ ├── logger-service-pro.yml │ ├── monitor-service-pro.yml │ ├── news-service-pro.yml │ ├── uaa-service-pro.yml │ ├── user-service-pro.yml │ └── zipkin-service-pro.yml ├── module_eureka ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── eureka │ │ └── EurekaServerApplication.java │ └── resources │ └── application.yml ├── module_gateway ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── gateway │ │ └── GatewayServiceApplication.java │ └── resources │ └── bootstrap.yml ├── module_log ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── log │ │ ├── LogServiceApplication.java │ │ ├── config │ │ └── RabbitConfig.java │ │ ├── dao │ │ └── SysLogDAO.java │ │ ├── entity │ │ └── SysLog.java │ │ ├── rabbit │ │ ├── Receiver.java │ │ ├── Sender.java │ │ └── User.java │ │ └── service │ │ └── SysLogService.java │ └── resources │ └── bootstrap.yml ├── module_monitor ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── monitor │ │ └── MonitorServiceApplication.java │ └── resources │ └── bootstrap.yml ├── module_news ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── news │ │ ├── NewsServiceApplication.java │ │ ├── aop │ │ └── SysLoggerAspect.java │ │ ├── client │ │ ├── UserServiceClient.java │ │ └── hystrix │ │ │ └── UserServiceHystrix.java │ │ ├── config │ │ ├── GlobalMethodSecurityConfiguration.java │ │ ├── JwtConfiguration.java │ │ ├── RabbitConfig.java │ │ ├── ResourceServerConfiguration.java │ │ └── SwaggerConfig.java │ │ ├── dao │ │ ├── NewsDetailDao.java │ │ └── NewsTypeDao.java │ │ ├── entity │ │ ├── NewsDetail.java │ │ ├── NewsType.java │ │ ├── SysLog.java │ │ └── User.java │ │ ├── exception │ │ └── CommonExceptionHandler.java │ │ ├── service │ │ ├── LoggerService.java │ │ ├── NewsDetailService.java │ │ └── NewsTypeService.java │ │ ├── util │ │ ├── HttpUtils.java │ │ └── UserUtils.java │ │ └── web │ │ ├── NewsDetailController.java │ │ └── NewsTypeController.java │ └── resources │ ├── bootstrap.yml │ └── public.cert ├── module_uaa ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── uaa │ │ ├── UaaServiceApplication.java │ │ ├── config │ │ ├── MyPasswordEncoder.java │ │ ├── OAuth2Config.java │ │ └── WebSecurityConfig.java │ │ ├── dao │ │ └── UserDao.java │ │ ├── entity │ │ ├── Role.java │ │ └── User.java │ │ └── service │ │ └── UserServiceDetail.java │ └── resources │ ├── bootstrap.yml │ ├── fly-jwt.jks │ └── logback-spring.xml ├── module_user ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── user │ │ ├── UserServiceApplication.java │ │ ├── aop │ │ └── SysLoggerAspect.java │ │ ├── client │ │ ├── AuthServiceClient.java │ │ └── hystrix │ │ │ └── AuthServiceHystrix.java │ │ ├── config │ │ ├── GlobalMethodSecurityConfiguration.java │ │ ├── JwtConfiguration.java │ │ ├── RabbitConfig.java │ │ ├── ResourceServerConfiguration.java │ │ └── SwaggerConfig.java │ │ ├── dao │ │ └── UserDao.java │ │ ├── dto │ │ └── LoginDTO.java │ │ ├── entity │ │ ├── JWT.java │ │ ├── SysLog.java │ │ └── User.java │ │ ├── exception │ │ └── CommonExceptionHandler.java │ │ ├── service │ │ ├── LoggerService.java │ │ └── UserService.java │ │ ├── util │ │ ├── BPwdEncoderUtils.java │ │ ├── HttpUtils.java │ │ └── UserUtils.java │ │ └── web │ │ └── UserController.java │ └── resources │ ├── bootstrap.yml │ └── public.cert ├── module_zipkin ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── fly │ │ └── zipkin │ │ └── ZipkinServiceApplication.java │ └── resources │ └── bootstrap.yml ├── settings.gradle └── sql ├── sys-blog.sql ├── sys-log.sql ├── sys-news.sql ├── sys-news_news_detail.sql ├── sys-news_news_type.sql └── sys-user.sql /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | */build 16 | */out 17 | /logs 18 | -------------------------------------------------------------------------------- /.gradle/5.4.1/executionHistory/executionHistory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/5.4.1/executionHistory/executionHistory.bin -------------------------------------------------------------------------------- /.gradle/5.4.1/executionHistory/executionHistory.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/5.4.1/executionHistory/executionHistory.lock -------------------------------------------------------------------------------- /.gradle/5.4.1/fileChanges/last-build.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gradle/5.4.1/fileHashes/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/5.4.1/fileHashes/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/5.4.1/fileHashes/fileHashes.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/5.4.1/fileHashes/fileHashes.lock -------------------------------------------------------------------------------- /.gradle/5.4.1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/5.4.1/gc.properties -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/buildOutputCleanup.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/buildOutputCleanup/buildOutputCleanup.lock -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/cache.properties: -------------------------------------------------------------------------------- 1 | #Sun Jun 16 09:01:51 CST 2019 2 | gradle.version=5.4.1 3 | -------------------------------------------------------------------------------- /.gradle/buildOutputCleanup/outputFiles.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/buildOutputCleanup/outputFiles.bin -------------------------------------------------------------------------------- /.gradle/vcs-1/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/vcs-1/gc.properties -------------------------------------------------------------------------------- /.gradle/vcsWorkingDirs/gc.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/vcsWorkingDirs/gc.properties -------------------------------------------------------------------------------- /.gradle/workspace-id.txt: -------------------------------------------------------------------------------- 1 | w752pdfyvnfybofk6opwj4akuy -------------------------------------------------------------------------------- /.gradle/workspace-id.txt.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/.gradle/workspace-id.txt.lock -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Editor-based HTTP Client requests 2 | /httpRequests/ 3 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | FlyCloud -------------------------------------------------------------------------------- /.idea/GrepConsole.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 56 | 57 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___FlyCloud_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___FlyCloud_1_0_SNAPSHOT_war__exploded_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/build/libs/exploded/FlyCloud-1.0-SNAPSHOT.war 4 | 5 | 6 | TWFuaWZlc3QtVmVyc2lvbjogMS4wDQoNCg== 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___lib_common_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/lib_common/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_admin_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_admin/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_blog_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_blog/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_config_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_config/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_eureka_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_eureka/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_gateway_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_gateway/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_log_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_log/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_monitor_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_monitor/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_news_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_news/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_uaa_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_uaa/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_user_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_user/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/artifacts/Gradle___com_fly___module_zipkin_1_0_SNAPSHOT_war.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/module_zipkin/build/libs 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 33 | 34 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | 39 | 40 | 44 | 45 | 49 | 50 | 54 | 55 | 59 | 60 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlyCloud 2 | FlyClould 微服务实战项目框架,在该框架中,包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,对于后台服务框架的搭建有很大的参考价值,大家可以参考甚至稍加修改可以直接应用于自己的实际的项目开发中 3 | csdn地址:[https://blog.csdn.net/geduo_83/article/details/87866018](https://blog.csdn.net/geduo_83/article/details/87866018) 4 | 欢迎点赞加星,评论打call、加群:810970432 5 | 6 | 在该框架中包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,对于后台服务框架的搭建有很大的参考价值,大家可以参考甚至稍加修改可以直接应用于自己的实际的项目开发中。 7 | 8 | ### 更新日志: 9 | 10 | ### [FlyCloud 3.0.0](https://github.com/mxdldev/spring-cloud-flycloud/releases) 2020-03-23 11 | 为了满足广大开发者的便于测试、便于部署需求,对FlyCloud进行了单一结构体改造,并将其部署在了外网上,接口文档如下:[http://106.12.61.238:8080/swagger-ui.html](http://106.12.61.238:8080/swagger-ui.html) 12 | * spring boot + security + oauth2 单一结构体改造 13 | * 将所有的访问接口开放在外网上 14 | 15 | ### [FlyCloud 2.2.0](https://github.com/mxdldev/spring-cloud-flycloud/releases) 2020-03-09 16 | * springboot 升级为2.0.5 17 | 18 | ### [FlyCloud 2.1.0](https://github.com/mxdldev/spring-cloud-flycloud/releases) 2019-07-01 19 | * 相关bug修改 20 | * 代码优化 21 | 22 | ### [FlyCloud 2.0.0](https://github.com/mxdldev/spring-cloud-flycloud/releases) 2019-06-08 23 | * 业务组件module_news添加 24 | 25 | ### [FlyCloud 1.0.0](https://github.com/mxdldev/spring-cloud-flycloud/releases) 2019-02-28 26 | 初始版本: 27 | * 1.配置组件:注册中心、配置中心、授权中心 28 | * 2.监控组件:聚合监控、熔断监控、路由监控 29 | * 3.其他组件:网关服务、日志服务、公共服务 30 | * 4.业务组件:用户组件,博客组件 31 | 32 | ### 开发环境: 33 | 在该框架中,包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,运行所需要软件如下: 34 | * 开发IDE:IDEA 35 | https://www.jetbrains.com/idea/download/#section=windows 36 | * 数据库:mysql5.7 37 | https://dev.mysql.com/downloads/mysql/ 38 | * 组件通信rabbitmq 39 | http://www.rabbitmq.com/download.html 40 | * Erlang环境 41 | http://www.erlang.org/downloads Erlang环境 42 | http://www.cnerlang.com/resource/182.html 43 | 该项目没有采用Maven进行项目构建,Maven通过xml进行依赖管理,导致整个配置文件太过臃肿,另外灵活性也不是很强,所以我采用Gradle进行项目构建和依赖管理,在FlyTour项目中我们见证了Gradle的强大,通过简单的一些配置就可以轻松的实现组件化的功能。该项目共有11个Moudle工程。其中10个位微服务工程,这10个微服务工程构成了一个完整的微服务系统,微服务系统包含了8个基础服务,提供了一整套微服务治理功能,他们分别是配置中心module_config、注册中心module_eureka、认证授权中心module_uaa、Turbine聚合监控服务module_monitor、链路追踪服务module_zipken、聚合监控服务module_admin、路由网关服务module_gateway、日志服务module_log。另外还包含了两个资源服务:用户服务module_user和blog服务module_blog,另外还有一个common的Moudle,为资源服务提供一些一本的工具类。 44 | ### 工程架构图: 45 |
![](https://img-blog.csdnimg.cn/2019061017280996.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9tZW54aW5kaWFvbG9uZy5ibG9nLmNzZG4ubmV0,size_16,color_FFFFFF,t_70) 46 |
下面对11个Moudle工程分别进行介绍: 47 | * 1.注册中心:module_eureka 48 | 在这个系统中,所有的服务都向注册中心module_eureka进行服务注册。能方便的查看每个服务的服务状况、服务是否可用,以及每个服务都有哪些服务实例 49 | 工作流程: 50 |
![](https://img-blog.csdnimg.cn/20190222130826167.png) 51 | * 2.配置中心:module_config 52 | 配置中心所有服务的配置文件由 config-server 管理,特别说明为了简单起见本框架中配置数据都放在本地并没有从git仓库远程获取 53 | 架构图: 54 |
![](https://img-blog.csdnimg.cn/20190222132525638.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 55 | * 3.网关服务:module_gateway 56 | 网关服务使用的是 Zuul 组件, Zuul 组件可以实现智能路由、负载均衡的功能 gateway-service 作为 个边界服务,对外统一暴露 API 接口,其他的服务 API 接口只提供给内部服务调用,不提供给外界直接调用,这就很方便实现统鉴权、安全验证的功能 57 | 通过路由网关实现负载均衡: 58 |
![](https://img-blog.csdnimg.cn/20190222134903810.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 59 | * 4.链路追踪服务:module_zipkin 60 | 它可以查看每个请求在微服务系统中的链路关系 61 | * 5.聚合监控服务:module_admin 62 | 提供了非常强大的服务监控功能,可以查看每个向注册中心注册服务的健康状态, 日志、注册时间等 63 | * 6.Turbine聚合监控服务:module_monitor 64 | 它聚合了 module_user和module_blog的Hystrix Dashboard ,可以查看这两个服务熔断器的监控状况 65 | * 7.认证授权服务:module_uaa 66 | Spring Cloud 0Auth2 由这个服务统一授权并返回Token。其他的应用服务例如module_user和module_blog作为资源服务 API 接口资源受保护的,需要验证Token并鉴后才能访问,我采用的0Auth2+JWT安全认证,需要生成私钥用于加密,公钥用于解密 67 | 生成私钥命令: 68 | ``` 69 | keytool -genkeypair -alias fly-jwt -validity 36500 -keyalg RSA -dname "CN=jwt,OU=jwt,O=jwt,L=haidian,S=beijing,C=CH" -keypass fly123 -keystore fly-jwt.jks -storepass fly123 70 | ``` 71 | 生成公钥命令: 72 | ``` 73 | keytool -list -rfc --keystore fly-jwt.jks | openssl x509 -inform pem -pubkey 74 | ``` 75 | JWT认证流程: 76 |
![](https://img-blog.csdnimg.cn/20190222140807479.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 77 | * 8.用户服务:module_user 78 | 作为资源服务,对外暴露用户的API接口资源 79 | * 9.blog服务:module_blog 80 | 作为资源服务,对外暴露blog的API接口资源 81 | * 10.日志服务:module_log 82 | 作为日志服务, module_user和module_blog服务通过RabbitMQ向module_log发送业务操作日志的消息,最后统一保存在数据库,由它统一持久化操作日志 83 | 日志服务架构图: 84 |
![](https://img-blog.csdnimg.cn/20190222142641298.png) 85 | ### 功能演示: 86 | 依次启动 module_eureka, module_config,module_zipkin及其他的微服务,等整个微服务系统完全启动之后,在览器上访问 即:http://localhost:8761,即就是Eureka 可以查看服务注册的情况 87 | ![](https://img-blog.csdnimg.cn/20190222112508530.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 88 | API 接口文档采用 Swagger2 框架生成在线文档, module_user 工程和 module_blog工程集成了Swagger2 ,集成Swagger2 只需要引入依赖,并做相关的配置,然后在具体的 Controller上写注解,就可以实现 Swagger2的在线文档功能在浏览器输入http://localhost:8762/swagger-ui.html 查看user服务的api文档 89 | ![](https://img-blog.csdnimg.cn/20190222112530157.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 90 | 在浏览器输入http://localhost:8763/swagger-ui.html 查看blog服务的api文档  91 | ![](https://img-blog.csdnimg.cn/20190222112530157.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 92 | ![](https://img-blog.csdnimg.cn/201902221125490.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 93 |  在浏览器上访问 http://localhost :9998 展示了 admin-service 登录界面,admin-service 作为 个综合监控的服务,需要对访问者进行身份认证才能访问它的主页,登录用户名为 dmin 密码为 123456 94 | ![](https://img-blog.csdnimg.cn/20190222112614615.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 95 | 这是登录成功后进入的首页面:  96 | ![](https://img-blog.csdnimg.cn/20190222112628215.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 97 | 点击TURBINE,这是user服务和blog服务的熔断器监控页面 98 | ![](https://img-blog.csdnimg.cn/20190222112644214.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 99 | 在浏览器上访问 http://localhost :9411查看服务之间相互调用的链路追踪 100 | ![](https://img-blog.csdnimg.cn/20190222112657972.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dlZHVvXzgz,size_16,color_FFFFFF,t_70) 101 | 好了,截止到现在整个项目就全部介绍完了,本项目可以直接拿来应用,进行项目开发,本框架代码量较大,所以我就不贴源代码了 102 | ### 问题反馈 103 | 在使用中有任何问题,请在下方留言,或加入Android、Java开发技术交流群 104 | QQ群:810970432 105 | email:geduo_83@163.com 106 | ![](https://img-blog.csdnimg.cn/20190126213618911.png) 107 | ### 关于作者 108 | ``` 109 | var mxdl = { 110 | name : "门心叼龙", 111 | blog : "https://menxindiaolong.blog.csdn.net" 112 | } 113 | ``` 114 | ### License 115 | ``` 116 | Copyright (C) menxindiaolong, FlyCloud Framework Open Source Project 117 | 118 | Licensed under the Apache License, Version 2.0 (the "License"); 119 | you may not use this file except in compliance with the License. 120 | You may obtain a copy of the License at 121 | 122 | http://www.apache.org/licenses/LICENSE-2.0 123 | 124 | Unless required by applicable law or agreed to in writing, software 125 | distributed under the License is distributed on an "AS IS" BASIS, 126 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 127 | See the License for the specific language governing permissions and 128 | limitations under the License. 129 | ``` 130 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 5 | maven { url "https://oss.sonatype.org/content/groups/public/" } 6 | maven { url "https://repo.spring.io/libs-milestone/" } 7 | jcenter() 8 | mavenCentral() 9 | } 10 | dependencies { 11 | 12 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 13 | //classpath "se.transmode.gradle:gradle-docker:${transmodeGradleDockerVersion}" 14 | } 15 | } 16 | allprojects { 17 | apply plugin: 'war' 18 | apply plugin: 'java' 19 | apply plugin: 'org.springframework.boot' 20 | apply plugin: 'idea' 21 | apply plugin: 'io.spring.dependency-management' 22 | 23 | group = 'com.fly' 24 | version = '1.0-SNAPSHOT' 25 | sourceCompatibility = 1.8 26 | 27 | repositories { 28 | mavenLocal() 29 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/" } 30 | maven { url "https://oss.sonatype.org/content/groups/public/" } 31 | maven { url "https://repo.spring.io/libs-milestone/" } 32 | jcenter() 33 | mavenCentral() 34 | 35 | google() 36 | maven { url 'https://jitpack.io' } 37 | } 38 | 39 | dependencies { 40 | testCompile "org.springframework.boot:spring-boot-starter-test" 41 | } 42 | 43 | dependencyManagement { 44 | imports { 45 | mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" 46 | } 47 | } 48 | //这里一定得要。在多模块下,不然编译失败,因为不会把信赖模块给打包。 49 | jar { 50 | enabled = true 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | springBootVersion=2.0.5.RELEASE 2 | springCloudVersion=Finchley.SR1 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /lib_common/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 3 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix-dashboard' 4 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix' 5 | compile 'org.springframework.cloud:spring-cloud-starter-openfeign' 6 | 7 | compile 'org.springframework.cloud:spring-cloud-starter-config' 8 | compile 'org.springframework.boot:spring-boot-starter-web' 9 | compile 'org.springframework.boot:spring-boot-starter-actuator' 10 | 11 | compile 'org.springframework.cloud:spring-cloud-starter-zipkin' 12 | compile 'io.springfox:springfox-swagger2:2.7.0' 13 | compile 'io.springfox:springfox-swagger-ui:2.7.0' 14 | compile 'mysql:mysql-connector-java' 15 | compile 'org.springframework.boot:spring-boot-starter-data-jpa' 16 | compile 'org.springframework.cloud:spring-cloud-starter-oauth2' 17 | compile 'org.springframework.boot:spring-boot-starter-amqp' 18 | compile 'com.alibaba:fastjson:1.2.31' 19 | } 20 | -------------------------------------------------------------------------------- /lib_common/src/main/java/com/fly/common/annotation/SysLogger.java: -------------------------------------------------------------------------------- 1 | package com.fly.common.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | @Target(ElementType.METHOD) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | public @interface SysLogger { 16 | String value() default ""; 17 | } 18 | -------------------------------------------------------------------------------- /lib_common/src/main/java/com/fly/common/dto/RespDTO.java: -------------------------------------------------------------------------------- 1 | package com.fly.common.dto; 2 | 3 | import java.io.Serializable; 4 | /** 5 | * Description:
6 | * Author:    mxdl
7 | * Date:     2019/2/19
8 | * Version:   V1.0.0
9 | * Update:    
10 | */ 11 | public class RespDTO implements Serializable{ 12 | 13 | 14 | public int code = 0; 15 | public String error = ""; 16 | public T data; 17 | 18 | public static RespDTO onSuc(Object data) { 19 | RespDTO resp = new RespDTO(); 20 | resp.data = data; 21 | return resp; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "RespDTO{" + 27 | "code=" + code + 28 | ", error='" + error + '\'' + 29 | ", data=" + data + 30 | '}'; 31 | } 32 | 33 | public void setCode(int code) { 34 | this.code = code; 35 | } 36 | 37 | public void setError(String error) { 38 | this.error = error; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib_common/src/main/java/com/fly/common/exception/CommonException.java: -------------------------------------------------------------------------------- 1 | package com.fly.common.exception; 2 | 3 | /** 4 | * Description:
5 | * Author:    mxdl
6 | * Date:     2019/2/19
7 | * Version:   V1.0.0
8 | * Update:    
9 | */ 10 | public class CommonException extends RuntimeException { 11 | 12 | private ErrorCode errorCode; 13 | 14 | public CommonException(ErrorCode errorCode) { 15 | super(errorCode.getMsg()); 16 | this.errorCode = errorCode; 17 | } 18 | 19 | public CommonException(ErrorCode errorCode, String msg) { 20 | super(msg); 21 | this.errorCode = errorCode; 22 | } 23 | 24 | public ErrorCode getErrorCode() { 25 | return errorCode; 26 | } 27 | 28 | 29 | public int getCode() { 30 | return errorCode.getCode(); 31 | } 32 | 33 | public String getMsg() { 34 | return errorCode.getMsg(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /lib_common/src/main/java/com/fly/common/exception/ErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.fly.common.exception; 2 | 3 | /** 4 | * Description: <通用错误码>
5 | * Author:    mxdl
6 | * Date:     2019/2/19
7 | * Version:   V1.0.0
8 | * Update:    
9 | */ 10 | public enum ErrorCode { 11 | 12 | OK(0, ""), 13 | FAIL(-1, "操作失败"), 14 | RPC_ERROR(-2,"远程调度失败"), 15 | USER_NOT_FOUND(1000,"用户不存在"), 16 | USER_PASSWORD_ERROR(1001,"密码错误"), 17 | GET_TOKEN_FAIL(1002,"获取token失败"), 18 | TOKEN_IS_NOT_MATCH_USER(1003,"请使用自己的token进行接口请求"), 19 | 20 | BLOG_IS_NOT_EXIST(2001,"该内容不存在"); 21 | private int code; 22 | private String msg; 23 | 24 | 25 | ErrorCode(int code, String msg) { 26 | this.code = code; 27 | this.msg = msg; 28 | } 29 | 30 | 31 | public int getCode() { 32 | return code; 33 | } 34 | 35 | public String getMsg() { 36 | return msg; 37 | } 38 | 39 | public static ErrorCode codeOf(int code) { 40 | for (ErrorCode state : values()) { 41 | if (state.getCode() == code) { 42 | return state; 43 | } 44 | } 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /module_admin/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-starter-config' 3 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-turbine' 4 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix-dashboard' 5 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix' 6 | 7 | compile 'org.springframework.boot:spring-boot-starter-actuator' 8 | compile 'org.springframework.boot:spring-boot-starter-security' 9 | 10 | compile 'de.codecentric:spring-boot-admin-starter-server:2.0.0' 11 | compile 'de.codecentric:spring-boot-admin-server-ui:2.0.0' 12 | // compile 'de.codecentric:spring-boot-admin-server-ui-turbine:1.5.7' 13 | // compile 'de.codecentric:spring-boot-admin-server-ui-hystrix:1.5.7' 14 | // compile 'de.codecentric:spring-boot-admin-server-ui-login:1.5.0' 15 | // compile 'de.codecentric:spring-boot-admin-server-ui-activiti:1.5.0' 16 | 17 | compile 'org.jolokia:jolokia-core' 18 | } 19 | jar { 20 | manifest { 21 | attributes 'Main-Class': 'com.fly.admin.AdminServiceApplication' 22 | } 23 | } -------------------------------------------------------------------------------- /module_admin/src/main/java/com/fly/admin/AdminServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.admin; 2 | 3 | import de.codecentric.boot.admin.server.config.EnableAdminServer; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 9 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 10 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 13 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 14 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 15 | 16 | 17 | 18 | 19 | /** 20 | * Description:
21 | * Author:    mxdl
22 | * Date:     2019/2/19
23 | * Version:   V1.0.0
24 | * Update:    
25 | */ 26 | @SpringBootApplication 27 | @EnableTurbine 28 | @EnableHystrixDashboard 29 | @EnableHystrix 30 | @EnableAdminServer 31 | public class AdminServiceApplication { 32 | 33 | public static void main(String[] args) { 34 | SpringApplication.run(AdminServiceApplication.class, args); 35 | } 36 | 37 | @Configuration 38 | public static class SecurityConfig extends WebSecurityConfigurerAdapter { 39 | @Override 40 | protected void configure(HttpSecurity http) throws Exception { 41 | // Page with login form is served as /login.html and does a POST on /login 42 | http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll(); 43 | // The UI does a POST on /logout on logout 44 | http.logout().logoutUrl("/logout"); 45 | // The ui currently doesn't support csrf 46 | http.csrf().disable(); 47 | 48 | // Requests for the login page and the static assets are allowed 49 | http.authorizeRequests() 50 | .antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**") 51 | .permitAll(); 52 | // ... and any other request needs to be authorized 53 | http.authorizeRequests().antMatchers("/**").authenticated(); 54 | 55 | // Enable so that the clients can authenticate via HTTP basic for registering 56 | http.httpBasic(); 57 | } 58 | } 59 | 60 | @Autowired 61 | public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 62 | auth 63 | .inMemoryAuthentication() 64 | .withUser("admin").password("123456").roles("USER"); 65 | } 66 | // end::configuration-spring-security[] 67 | } 68 | -------------------------------------------------------------------------------- /module_admin/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: admin-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /module_admin/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /module_blog/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':lib_common') 3 | } 4 | jar { 5 | manifest { 6 | attributes 'Main-Class': 'com.fly.blog.BlogServiceApplication' 7 | } 8 | } -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/BlogServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * Description: <>
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @SpringBootApplication 18 | @EnableEurekaClient 19 | @EnableFeignClients 20 | @EnableHystrixDashboard 21 | @EnableHystrix 22 | public class BlogServiceApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(BlogServiceApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/aop/SysLoggerAspect.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.aop; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.blog.entity.SysLog; 5 | import com.fly.blog.util.HttpUtils; 6 | import com.fly.blog.util.UserUtils; 7 | import com.fly.blog.service.LoggerService; 8 | import com.fly.common.annotation.SysLogger; 9 | import org.apache.commons.lang.StringUtils; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Before; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.MethodSignature; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Component; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.Date; 20 | 21 | /** 22 | * Description: <>
23 | * Author:    mxdl
24 | * Date:     2019/2/19
25 | * Version:   V1.0.0
26 | * Update:    
27 | */ 28 | @Aspect 29 | @Component 30 | public class SysLoggerAspect { 31 | @Autowired 32 | private LoggerService loggerService; 33 | 34 | @Pointcut("@annotation(com.fly.common.annotation.SysLogger)") 35 | public void loggerPointCut() { 36 | 37 | } 38 | 39 | @Before("loggerPointCut()") 40 | public void saveSysLog(JoinPoint joinPoint) { 41 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 42 | Method method = signature.getMethod(); 43 | 44 | SysLog sysLog = new SysLog(); 45 | SysLogger sysLogger = method.getAnnotation(SysLogger.class); 46 | if (sysLogger != null) { 47 | //注解上的描述 48 | sysLog.setOperation(sysLogger.value()); 49 | } 50 | //请求的方法名 51 | String className = joinPoint.getTarget().getClass().getName(); 52 | String methodName = signature.getName(); 53 | sysLog.setMethod(className + "." + methodName + "()"); 54 | //请求的参数 55 | Object[] args = joinPoint.getArgs(); 56 | String params = ""; 57 | for (Object o : args) { 58 | params += JSON.toJSONString(o); 59 | } 60 | if (!StringUtils.isEmpty(params)) { 61 | sysLog.setParams(params); 62 | } 63 | //设置IP地址 64 | sysLog.setIp(HttpUtils.getIpAddress()); 65 | //用户名 66 | String username = UserUtils.getCurrentPrinciple(); 67 | if (!StringUtils.isEmpty(username)) { 68 | sysLog.setUsername(username); 69 | } 70 | sysLog.setCreateDate(new Date()); 71 | //保存系统日志 72 | loggerService.log(sysLog); 73 | } 74 | 75 | } 76 | 77 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/client/UserServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.client; 2 | 3 | import com.fly.blog.entity.User; 4 | import com.fly.blog.client.hystrix.UserServiceHystrix; 5 | import com.fly.common.dto.RespDTO; 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestHeader; 10 | 11 | 12 | 13 | /** 14 | * Description:
15 | * Author:    mxdl
16 | * Date:     2019/2/19
17 | * Version:   V1.0.0
18 | * Update:    
19 | */ 20 | @FeignClient(value = "user-service",fallback = UserServiceHystrix.class ) 21 | public interface UserServiceClient { 22 | 23 | @PostMapping(value = "/user/{username}") 24 | RespDTO getUser(@RequestHeader(value = "Authorization") String token, @PathVariable("username") String username); 25 | } 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/client/hystrix/UserServiceHystrix.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.client.hystrix; 2 | 3 | import com.fly.blog.client.UserServiceClient; 4 | import com.fly.blog.entity.User; 5 | import com.fly.common.dto.RespDTO; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @Component 16 | public class UserServiceHystrix implements UserServiceClient { 17 | 18 | @Override 19 | public RespDTO getUser(String token, String username) { 20 | System.out.println(token); 21 | System.out.println(username); 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/config/GlobalMethodSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @Configuration 14 | @EnableGlobalMethodSecurity(prePostEnabled = true) 15 | public class GlobalMethodSecurityConfiguration { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/config/JwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.core.io.Resource; 9 | import org.springframework.security.oauth2.provider.token.TokenStore; 10 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 11 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 12 | import org.springframework.util.FileCopyUtils; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * Description:
18 | * Author:    mxdl
19 | * Date:     2019/2/19
20 | * Version:   V1.0.0
21 | * Update:    
22 | */ 23 | @Configuration 24 | public class JwtConfiguration { 25 | @Autowired 26 | JwtAccessTokenConverter jwtAccessTokenConverter; 27 | 28 | @Bean 29 | @Qualifier("tokenStore") 30 | public TokenStore tokenStore() { 31 | 32 | System.out.println("Created JwtTokenStore"); 33 | return new JwtTokenStore(jwtAccessTokenConverter); 34 | } 35 | 36 | @Bean 37 | protected JwtAccessTokenConverter jwtTokenEnhancer() { 38 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 39 | Resource resource = new ClassPathResource("public.cert"); 40 | String publicKey ; 41 | try { 42 | publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | converter.setVerifierKey(publicKey); 47 | return converter; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/config/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.config; 2 | 3 | 4 | import org.springframework.amqp.core.Binding; 5 | import org.springframework.amqp.core.BindingBuilder; 6 | import org.springframework.amqp.core.Queue; 7 | import org.springframework.amqp.core.TopicExchange; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @Configuration 19 | public class RabbitConfig { 20 | 21 | 22 | public final static String queueName = "spring-boot"; 23 | 24 | @Bean 25 | Queue queue() { 26 | return new Queue(queueName, false); 27 | } 28 | 29 | @Bean 30 | TopicExchange exchange() { 31 | return new TopicExchange("spring-boot-exchange"); 32 | } 33 | 34 | @Bean 35 | Binding binding(Queue queue, TopicExchange exchange) { 36 | return BindingBuilder.bind(queue).to(exchange).with(queueName); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/config/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 9 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 10 | import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; 11 | import org.springframework.security.oauth2.provider.token.TokenStore; 12 | 13 | /** 14 | * Description:
15 | * Author:    mxdl
16 | * Date:     2019/2/19
17 | * Version:   V1.0.0
18 | * Update:    
19 | */ 20 | @Configuration 21 | @EnableResourceServer 22 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter{ 23 | Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class); 24 | 25 | @Override 26 | public void configure(HttpSecurity http) throws Exception { 27 | http 28 | .csrf().disable() 29 | .authorizeRequests() 30 | .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*").permitAll() 31 | .antMatchers("/**").authenticated(); 32 | // .antMatchers("/**").permitAll(); 33 | } 34 | 35 | 36 | @Override 37 | public void configure(ResourceServerSecurityConfigurer resources) throws Exception { 38 | log.info("Configuring ResourceServerSecurityConfigurer "); 39 | resources.resourceId("user-service").tokenStore(tokenStore); 40 | } 41 | 42 | @Autowired 43 | TokenStore tokenStore; 44 | } 45 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.ParameterBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.schema.ModelRef; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Parameter; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * Description:
21 | * Author:    mxdl
22 | * Date:     2019/2/19
23 | * Version:   V1.0.0
24 | * Update:    
25 | */ 26 | @Configuration 27 | @EnableSwagger2 28 | public class SwaggerConfig { 29 | /** 30 | * 全局参数 31 | * 32 | * @return 33 | */ 34 | private List parameter() { 35 | List params = new ArrayList<>(); 36 | params.add(new ParameterBuilder().name("Authorization") 37 | .description("Authorization Bearer token") 38 | .modelRef(new ModelRef("string")) 39 | .parameterType("header") 40 | .required(false).build()); 41 | return params; 42 | } 43 | 44 | @Bean 45 | public Docket sysApi() { 46 | return new Docket(DocumentationType.SWAGGER_2) 47 | .apiInfo(apiInfo()) 48 | .select() 49 | .apis(RequestHandlerSelectors.basePackage("com.fly")) 50 | .paths(PathSelectors.any()) 51 | .build().globalOperationParameters(parameter()); 52 | } 53 | 54 | private ApiInfo apiInfo() { 55 | return new ApiInfoBuilder() 56 | .title(" blog-service api ") 57 | .description("blog-service 微服务") 58 | .termsOfServiceUrl("") 59 | .version("1.0") 60 | .build(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/dao/BlogDao.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.dao; 2 | 3 | import com.fly.blog.entity.Blog; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | public interface BlogDao extends JpaRepository { 16 | 17 | List findByUsername(String username); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/dto/BlogDetailDTO.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.dto; 2 | 3 | import com.fly.blog.entity.Blog; 4 | import com.fly.blog.entity.User; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | public class BlogDetailDTO { 14 | private Blog blog; 15 | private User user; 16 | 17 | public Blog getBlog() { 18 | return blog; 19 | } 20 | 21 | public void setBlog(Blog blog) { 22 | this.blog = blog; 23 | } 24 | 25 | public User getUser() { 26 | return user; 27 | } 28 | 29 | public void setUser(User user) { 30 | this.user = user; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/entity/Blog.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.entity; 2 | 3 | import java.io.Serializable; 4 | import javax.persistence.*; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @Entity 14 | public class Blog implements Serializable { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | 19 | @Column(nullable = false) 20 | private String username; 21 | 22 | @Column 23 | private String title; 24 | 25 | @Column 26 | private String suject; 27 | 28 | 29 | public Blog() { 30 | } 31 | 32 | public Long getId() { 33 | return id; 34 | } 35 | 36 | public void setId(Long id) { 37 | this.id = id; 38 | } 39 | 40 | public String getUsername() { 41 | return username; 42 | } 43 | 44 | public void setUsername(String username) { 45 | this.username = username; 46 | } 47 | 48 | public String getTitle() { 49 | return title; 50 | } 51 | 52 | public void setTitle(String title) { 53 | this.title = title; 54 | } 55 | 56 | public String getSuject() { 57 | return suject; 58 | } 59 | 60 | public void setSuject(String suject) { 61 | this.suject = suject; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/entity/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | public class SysLog { 13 | 14 | private Long id; 15 | //用户名 16 | private String username; 17 | //用户操作 18 | private String operation; 19 | //请求方法 20 | private String method; 21 | //请求参数 22 | private String params; 23 | //IP地址 24 | private String ip; 25 | //创建时间 26 | private Date createDate; 27 | 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | 37 | public String getUsername() { 38 | return username; 39 | } 40 | 41 | public void setUsername(String username) { 42 | this.username = username; 43 | } 44 | 45 | public String getOperation() { 46 | return operation; 47 | } 48 | 49 | public void setOperation(String operation) { 50 | this.operation = operation; 51 | } 52 | 53 | public String getMethod() { 54 | return method; 55 | } 56 | 57 | public void setMethod(String method) { 58 | this.method = method; 59 | } 60 | 61 | public String getParams() { 62 | return params; 63 | } 64 | 65 | public void setParams(String params) { 66 | this.params = params; 67 | } 68 | 69 | public String getIp() { 70 | return ip; 71 | } 72 | 73 | public void setIp(String ip) { 74 | this.ip = ip; 75 | } 76 | 77 | public Date getCreateDate() { 78 | return createDate; 79 | } 80 | 81 | public void setCreateDate(Date createDate) { 82 | this.createDate = createDate; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.entity; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | public class User { 16 | 17 | private Long id; 18 | private String username; 19 | private String password; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getUsername() { 30 | return username; 31 | } 32 | 33 | public void setUsername(String username) { 34 | this.username = username; 35 | } 36 | 37 | public String getPassword() { 38 | return password; 39 | } 40 | 41 | public void setPassword(String password) { 42 | this.password = password; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/exception/CommonExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.exception; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.common.exception.CommonException; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @ControllerAdvice 19 | @ResponseBody 20 | public class CommonExceptionHandler { 21 | 22 | @ExceptionHandler(CommonException.class) 23 | public ResponseEntity handleException(Exception e) { 24 | RespDTO resp = new RespDTO(); 25 | CommonException taiChiException = (CommonException) e; 26 | resp.code = taiChiException.getCode(); 27 | resp.error = e.getMessage(); 28 | return new ResponseEntity(resp, HttpStatus.OK); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/service/BlogService.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.service; 2 | 3 | 4 | import com.fly.blog.client.UserServiceClient; 5 | import com.fly.blog.dao.BlogDao; 6 | import com.fly.blog.dto.BlogDetailDTO; 7 | import com.fly.blog.entity.Blog; 8 | import com.fly.blog.entity.User; 9 | import com.fly.blog.util.UserUtils; 10 | import com.fly.common.dto.RespDTO; 11 | import com.fly.common.exception.CommonException; 12 | import com.fly.common.exception.ErrorCode; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * Description:
20 | * Author:    mxdl
21 | * Date:     2019/2/19
22 | * Version:   V1.0.0
23 | * Update:    
24 | */ 25 | @Service 26 | public class BlogService { 27 | 28 | @Autowired 29 | BlogDao blogDao; 30 | 31 | @Autowired 32 | UserServiceClient userServiceClient; 33 | 34 | public Blog postBlog(Blog blog) { 35 | return blogDao.save(blog); 36 | } 37 | 38 | public List findBlogs(String username) { 39 | return blogDao.findByUsername(username); 40 | } 41 | 42 | 43 | public BlogDetailDTO findBlogDetail(Long id) { 44 | Blog blog = blogDao.findById(id).get(); 45 | if (null == blog) { 46 | throw new CommonException(ErrorCode.BLOG_IS_NOT_EXIST); 47 | } 48 | RespDTO respDTO = userServiceClient.getUser(UserUtils.getCurrentToken(), blog.getUsername()); 49 | if (respDTO==null) { 50 | throw new CommonException(ErrorCode.RPC_ERROR); 51 | } 52 | BlogDetailDTO blogDetailDTO = new BlogDetailDTO(); 53 | blogDetailDTO.setBlog(blog); 54 | blogDetailDTO.setUser(respDTO.data); 55 | return blogDetailDTO; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/service/LoggerService.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.service; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.blog.config.RabbitConfig; 5 | import com.fly.blog.entity.SysLog; 6 | import org.springframework.amqp.core.AmqpTemplate; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @Service 18 | public class LoggerService { 19 | 20 | @Autowired 21 | private AmqpTemplate rabbitTemplate; 22 | 23 | public void log(SysLog sysLog){ 24 | rabbitTemplate.convertAndSend(RabbitConfig.queueName, JSON.toJSONString(sysLog)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.util; 2 | 3 | 4 | import org.springframework.web.context.request.RequestContextHolder; 5 | import org.springframework.web.context.request.ServletRequestAttributes; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.util.Enumeration; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Description: <>
14 | * Author:    mxdl
15 | * Date:     2019/2/19
16 | * Version:   V1.0.0
17 | * Update:    
18 | */ 19 | public class HttpUtils { 20 | 21 | 22 | /** 23 | * 尝试获取当前请求的HttpServletRequest实例 24 | * 25 | * @return HttpServletRequest 26 | */ 27 | public static HttpServletRequest getHttpServletRequest() { 28 | try { 29 | return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 30 | } catch (Exception e) { 31 | return null; 32 | } 33 | } 34 | 35 | 36 | public static Map getHeaders(HttpServletRequest request) { 37 | Map map = new LinkedHashMap<>(); 38 | Enumeration enumeration = request.getHeaderNames(); 39 | while (enumeration.hasMoreElements()) { 40 | String key = enumeration.nextElement(); 41 | String value = request.getHeader(key); 42 | map.put(key, value); 43 | } 44 | return map; 45 | } 46 | 47 | /** 48 | * 获取请求客户端的真实ip地址 49 | * 50 | * @param request 请求对象 51 | * @return ip地址 52 | */ 53 | public static String getIpAddress(HttpServletRequest request) { 54 | 55 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 56 | String ip = request.getHeader("X-Forwarded-For"); 57 | 58 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 59 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 60 | ip = request.getHeader("Proxy-Client-IP"); 61 | } 62 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 63 | ip = request.getHeader("WL-Proxy-Client-IP"); 64 | } 65 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 66 | ip = request.getHeader("HTTP_CLIENT_IP"); 67 | } 68 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 69 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 70 | } 71 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 72 | ip = request.getRemoteAddr(); 73 | } 74 | } else if (ip.length() > 15) { 75 | String[] ips = ip.split(","); 76 | for (int index = 0; index < ips.length; index++) { 77 | String strIp = (String) ips[index]; 78 | if (!("unknown".equalsIgnoreCase(strIp))) { 79 | ip = strIp; 80 | break; 81 | } 82 | } 83 | } 84 | return ip; 85 | } 86 | 87 | /** 88 | * 获取请求客户端的真实ip地址 89 | * 90 | * @param 91 | * @return ip地址 92 | */ 93 | public static String getIpAddress() { 94 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 95 | return getIpAddress(getHttpServletRequest()); 96 | } 97 | 98 | 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/util/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.util; 2 | 3 | 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Description: <>
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | public class UserUtils { 18 | 19 | private static final String AUTHORIZATION = "authorization"; 20 | 21 | /** 22 | * 获取当前请求的token 23 | * 24 | * @return 25 | */ 26 | public static String getCurrentToken() { 27 | return HttpUtils.getHeaders(HttpUtils.getHttpServletRequest()).get(AUTHORIZATION); 28 | } 29 | 30 | /** 31 | * 获取当前请求的用户Id 32 | * 33 | * @return 34 | */ 35 | public static String getCurrentPrinciple() { 36 | return (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 37 | } 38 | 39 | /** 40 | * 判读当前token用户是否为接口所需的参数username 41 | * 42 | * @param username 43 | * @return 44 | */ 45 | public static boolean isMyself(String username) { 46 | return username.equals(getCurrentPrinciple()); 47 | } 48 | 49 | /** 50 | * 获取当前请求Authentication 51 | * 52 | * @return 53 | */ 54 | public static Authentication getCurrentAuthentication() { 55 | return SecurityContextHolder.getContext().getAuthentication(); 56 | } 57 | 58 | /** 59 | * 获取当前请求的权限信息 60 | * 61 | * @return 62 | */ 63 | public static List getCurrentAuthorities() { 64 | return (List) SecurityContextHolder.getContext().getAuthentication().getAuthorities(); 65 | } 66 | 67 | /** 68 | * @param role 69 | * @return 70 | */ 71 | public static boolean hasRole(String role) { 72 | if (!role.startsWith("ROLE_")) { 73 | role = "ROLE_" + role; 74 | } 75 | boolean hasRole = false; 76 | List list = getCurrentAuthorities(); 77 | for (SimpleGrantedAuthority s : list) { 78 | if (role.equals(s.getAuthority())) { 79 | hasRole = true; 80 | break; 81 | } 82 | } 83 | return hasRole; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /module_blog/src/main/java/com/fly/blog/web/BlogController.java: -------------------------------------------------------------------------------- 1 | package com.fly.blog.web; 2 | 3 | import com.fly.blog.entity.Blog; 4 | import com.fly.blog.util.UserUtils; 5 | import com.fly.blog.service.BlogService; 6 | import com.fly.common.annotation.SysLogger; 7 | import com.fly.common.dto.RespDTO; 8 | import com.fly.common.exception.CommonException; 9 | import com.fly.common.exception.ErrorCode; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.access.prepost.PreAuthorize; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Description: <>
19 | * Author:    mxdl
20 | * Date:     2019/2/19
21 | * Version:   V1.0.0
22 | * Update:    
23 | */ 24 | @RestController 25 | @RequestMapping("/blog") 26 | public class BlogController { 27 | 28 | @Autowired 29 | BlogService blogService; 30 | 31 | @ApiOperation(value = "发布博客", notes = "发布博客") 32 | @PreAuthorize("hasRole('USER')") 33 | @PostMapping("") 34 | @SysLogger("postBlog") 35 | public RespDTO postBlog(@RequestBody Blog blog){ 36 | //字段判读省略 37 | Blog blog1= blogService.postBlog(blog); 38 | return RespDTO.onSuc(blog1); 39 | } 40 | 41 | @ApiOperation(value = "根据用户id获取所有的blog", notes = "根据用户id获取所有的blog") 42 | @PreAuthorize("hasAuthority('ROLE_USER')") 43 | @GetMapping("/{username}") 44 | @SysLogger("getBlogs") 45 | public RespDTO getBlogs(@PathVariable String username){ 46 | //字段判读省略 47 | if(UserUtils.isMyself(username)) { 48 | List blogs = blogService.findBlogs(username); 49 | return RespDTO.onSuc(blogs); 50 | }else { 51 | throw new CommonException(ErrorCode.TOKEN_IS_NOT_MATCH_USER); 52 | } 53 | } 54 | 55 | @ApiOperation(value = "获取博文的详细信息", notes = "获取博文的详细信息") 56 | @PreAuthorize("hasAuthority('ROLE_USER')") 57 | @GetMapping("/{id}/detail") 58 | @SysLogger("getBlogDetail") 59 | public RespDTO getBlogDetail(@PathVariable Long id){ 60 | return RespDTO.onSuc(blogService.findBlogDetail(id)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /module_blog/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: blog-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | # zipkin: 11 | # base-url: http://localhost:9411 12 | # 13 | # datasource: 14 | # driver-class-name: com.mysql.jdbc.Driver 15 | # url: jdbc:mysql://localhost:3306/sys_blog?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 16 | # username: root 17 | # password: 123456 18 | # jpa: 19 | # hibernate: 20 | # ddl-auto: update 21 | # show-sql: true 22 | # 23 | # rabbitmq: 24 | # host: localhost 25 | # port: 5672 26 | # username: guest 27 | # password: guest 28 | # publisher-confirms: true 29 | # virtual-host: / -------------------------------------------------------------------------------- /module_blog/src/main/resources/public.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3FtAe8QQmu3k/Jalrx24 3 | rKfOQ+vtji4kwu/wubWKN87BZDyv4tau3VJ1Ub9JpsEFMi0csoZmuUNEEWx+lNOf 4 | i9QWoKNQgQ8nUWkmqiVc1BvAsrBUkuvx1zDKHYkwZ4i45aRnDcBthsTaI4PbsweD 5 | YPhW3N06YBIkZVLLMmc+IHFX+Bnmd6DcWlFU/eAeM8/6TGUhR2BoSV0zBrPR85XW 6 | E0/ZVA8XdYOdf6RvAwms0NkAvEwjHV8O7x/7Uq4+i7+YK5vrZEzVUD2TVCgDpTbJ 7 | 55Qb5BKICtIbi5F2mI2DmQ7zwGAH1tFvDmVDS9ZQy+nfy8aQ5MJ+Lutmi0IjQdHX 8 | 5QIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /module_config/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-config-server' 3 | compile 'org.springframework.cloud:spring-cloud-starter-bus-amqp' 4 | compile 'org.springframework.boot:spring-boot-starter-actuator' 5 | compile 'org.springframework.boot:spring-boot-starter-aop' 6 | compile 'org.springframework.retry:spring-retry' 7 | } 8 | jar { 9 | manifest { 10 | attributes 'Main-Class': 'com.fly.config.ConfigServerApplication' 11 | } 12 | } -------------------------------------------------------------------------------- /module_config/src/main/java/com/fly/config/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @SpringBootApplication 14 | @EnableConfigServer 15 | public class ConfigServerApplication { 16 | public static void main(String[] args) { 17 | SpringApplication.run(ConfigServerApplication.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /module_config/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # ---native 2 | spring: 3 | cloud: 4 | config: 5 | server: 6 | native: 7 | search-locations: classpath:/shared 8 | profiles: 9 | active: native 10 | application: 11 | name: config-server 12 | 13 | # port 14 | server: 15 | port: 8769 16 | 17 | management: 18 | security: 19 | enabled: false 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/admin-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9998 3 | security: 4 | user: 5 | name: admin 6 | password: 123456 7 | management: 8 | security: 9 | enabled: false 10 | 11 | spring: 12 | boot: 13 | admin: 14 | routes: 15 | endpoints: env,metrics,dump,jolokia,info,configprops,trace,logfile,refresh,flyway,liquibase,heapdump,loggers,auditevents,hystrix.stream,activiti 16 | turbine: 17 | clusters: default 18 | location: monitor-service 19 | 20 | eureka: 21 | instance: 22 | metadata-map: 23 | user.name: admin 24 | user.password: 123456 25 | 26 | logging: 27 | file: "logs/admin-service-pro.log" -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/application.yml: -------------------------------------------------------------------------------- 1 | #logging: 2 | # level: 3 | # org.springframework.security: INFO 4 | 5 | #hystrix: 6 | # command: 7 | # default: 8 | # execution: 9 | # isolation: 10 | # thread: 11 | # timeoutInMilliseconds: 10000 12 | 13 | eureka: 14 | client: 15 | serviceUrl: 16 | defaultZone: http://localhost:8761/eureka/ 17 | 18 | #endpoints: 19 | # health: 20 | # sensitive: false 21 | # enabled: true 22 | # actuator: 23 | # enabled: true 24 | # sensitive: false 25 | # beans: 26 | # sensitive: false 27 | # enabled: true 28 | 29 | 30 | management: 31 | security: 32 | enabled: false 33 | # 34 | feign: 35 | hystrix: 36 | enabled: false 37 | ##### Feign 配置 38 | #feign: 39 | # # 是否开启断路器(熔断器) 40 | # hystrix: 41 | # enabled: true 42 | # client: 43 | # config: 44 | # default: 45 | # connect-timeout: 20000 46 | # read-timeout: 20000 47 | # 48 | -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/blog-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8763 3 | 4 | spring: 5 | zipkin: 6 | base-url: http://localhost:9411 7 | 8 | datasource: 9 | driver-class-name: com.mysql.jdbc.Driver 10 | url: jdbc:mysql://localhost:3306/sys-blog?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 11 | username: root 12 | password: gxfc2012 13 | jpa: 14 | hibernate: 15 | ddl-auto: update 16 | show-sql: true 17 | 18 | rabbitmq: 19 | host: localhost 20 | port: 5672 21 | username: guest 22 | password: guest 23 | publisher-confirms: true 24 | virtual-host: / -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/gateway-service-pro.yml: -------------------------------------------------------------------------------- 1 | hystrix: 2 | threadpool.default.coreSize: "20" 3 | threadpool.default.maxQueueSize: "500000" 4 | threadpool.default.keepAliveTimeMinutes: "2" 5 | threadpool.default.queueSizeRejectionThreshold: "500000" 6 | command: 7 | default: 8 | fallback.isolation.semaphore.maxConcurrentRequests: "20" 9 | execution: 10 | timeout: 11 | enabled: "false" 12 | isolation: 13 | strategy: "THREAD" 14 | thread: 15 | timeoutInMilliseconds: "30000" 16 | 17 | ribbon: 18 | eager-load: 19 | enabled: true 20 | clients: user-service,news-service 21 | 22 | ReadTimeout: 20000 23 | ConnectTimeout: 20000 24 | 25 | zuul: 26 | ribbon: 27 | eager-load: 28 | enabled: true 29 | 30 | host: 31 | connect-timeout-millis: 20000 32 | socket-timeout-millis: 20000 33 | 34 | routes: 35 | user-service: 36 | path: /userapi/** 37 | serviceId: user-service 38 | sensitiveHeaders: 39 | 40 | news-service: 41 | path: /newsapi/** 42 | serviceId: news-service 43 | sensitiveHeaders: 44 | 45 | blog-service: 46 | path: /blogapi/** 47 | serviceId: blog-service 48 | sensitiveHeaders: 49 | 50 | server: 51 | port: 5000 52 | 53 | -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/logger-service-pro.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | datasource: 3 | driver-class-name: com.mysql.jdbc.Driver 4 | url: jdbc:mysql://localhost:3306/sys-log?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 5 | username: root 6 | password: gxfc2012 7 | jpa: 8 | hibernate: 9 | ddl-auto: update 10 | show-sql: true 11 | 12 | rabbitmq: 13 | host: localhost 14 | port: 5672 15 | username: guest 16 | password: guest 17 | publisher-confirms: true 18 | virtual-host: / 19 | 20 | server: 21 | port: 9997 -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/monitor-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8766 3 | security.basic.enabled: false 4 | turbine: 5 | aggregator: 6 | clusterConfig: default 7 | appConfig: user-service,news-service,blog-service 8 | clusterNameExpression: new String("default") 9 | 10 | management: 11 | security: 12 | enabled: false -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/news-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8767 3 | 4 | spring: 5 | zipkin: 6 | base-url: http://localhost:9411 7 | 8 | datasource: 9 | driver-class-name: com.mysql.jdbc.Driver 10 | url: jdbc:mysql://localhost:3306/sys-news?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 11 | username: root 12 | password: gxfc2012 13 | jpa: 14 | hibernate: 15 | ddl-auto: update 16 | show-sql: true 17 | 18 | rabbitmq: 19 | host: localhost 20 | port: 5672 21 | username: guest 22 | password: guest 23 | publisher-confirms: true 24 | virtual-host: / -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/uaa-service-pro.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | 3 | datasource: 4 | driver-class-name: com.mysql.jdbc.Driver 5 | url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 6 | username: root 7 | password: gxfc2012 8 | jpa: 9 | hibernate: 10 | ddl-auto: update 11 | show-sql: true 12 | server: 13 | port: 9999 14 | -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/user-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8762 3 | 4 | 5 | spring: 6 | zipkin: 7 | base-url: http://localhost:9411 8 | 9 | # rabbitmq: 10 | # host: localhost 11 | # port: 5672 12 | datasource: 13 | driver-class-name: com.mysql.jdbc.Driver 14 | url: jdbc:mysql://localhost:3306/sys-user?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 15 | username: root 16 | password: gxfc2012 17 | jpa: 18 | hibernate: 19 | ddl-auto: update 20 | show-sql: true 21 | 22 | rabbitmq: 23 | host: localhost 24 | port: 5672 25 | username: guest 26 | password: guest 27 | publisher-confirms: true 28 | virtual-host: / 29 | 30 | foo: foo version 1 -------------------------------------------------------------------------------- /module_config/src/main/resources/shared/zipkin-service-pro.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9411 -------------------------------------------------------------------------------- /module_eureka/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | //compile 'org.springframework.cloud:spring-cloud-starter-eureka-server' 3 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' 4 | } 5 | jar { 6 | manifest { 7 | attributes 'Main-Class': 'com.fly.eureka.EurekaServerApplication' 8 | } 9 | } -------------------------------------------------------------------------------- /module_eureka/src/main/java/com/fly/eureka/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.eureka; 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 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @SpringBootApplication 16 | @EnableEurekaServer 17 | public class EurekaServerApplication{ 18 | public static void main(String[] args) { 19 | SpringApplication.run(EurekaServerApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /module_eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | eureka: 4 | client: 5 | register-with-eureka: false 6 | fetch-registry: false 7 | serviceUrl: 8 | defaultZone: http://localhost:${server.port}/eureka/ -------------------------------------------------------------------------------- /module_gateway/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-zuul' 3 | compile 'org.springframework.cloud:spring-cloud-starter-config' 4 | compile 'org.springframework.cloud:spring-cloud-starter' 5 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 6 | } 7 | jar { 8 | manifest { 9 | attributes 'Main-Class': 'com.fly.gateway.GatewayServiceApplication' 10 | } 11 | } -------------------------------------------------------------------------------- /module_gateway/src/main/java/com/fly/gateway/GatewayServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @SpringBootApplication 16 | @EnableZuulProxy 17 | @EnableEurekaClient 18 | public class GatewayServiceApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(GatewayServiceApplication.class, args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /module_gateway/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: gateway-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /module_log/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 3 | compile 'org.springframework.cloud:spring-cloud-starter-config' 4 | compile 'org.springframework.boot:spring-boot-starter-actuator' 5 | compile 'org.springframework.boot:spring-boot-starter-data-jpa' 6 | compile 'org.springframework.boot:spring-boot-starter-amqp' 7 | compile 'mysql:mysql-connector-java' 8 | compile 'com.alibaba:fastjson:1.2.31' 9 | } 10 | jar { 11 | manifest { 12 | attributes 'Main-Class': 'com.fly.log.LogServiceApplication' 13 | } 14 | } -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/LogServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.log; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @SpringBootApplication 14 | @EnableEurekaClient 15 | public class LogServiceApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(LogServiceApplication.class, args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/config/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.config; 2 | 3 | 4 | import com.fly.log.rabbit.Receiver; 5 | import org.springframework.amqp.core.Binding; 6 | import org.springframework.amqp.core.BindingBuilder; 7 | import org.springframework.amqp.core.Queue; 8 | import org.springframework.amqp.core.TopicExchange; 9 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; 10 | import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; 11 | import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; 12 | import org.springframework.boot.SpringApplication; 13 | import org.springframework.boot.autoconfigure.SpringBootApplication; 14 | import org.springframework.context.annotation.Bean; 15 | import org.springframework.context.annotation.Configuration; 16 | 17 | /** 18 | * Description:
19 | * Author:    mxdl
20 | * Date:     2019/2/19
21 | * Version:   V1.0.0
22 | * Update:    
23 | */ 24 | @Configuration 25 | public class RabbitConfig { 26 | 27 | 28 | public final static String queueName = "spring-boot"; 29 | 30 | @Bean 31 | Queue queue() { 32 | return new Queue(queueName, false); 33 | } 34 | 35 | @Bean 36 | TopicExchange exchange() { 37 | return new TopicExchange("spring-boot-exchange"); 38 | } 39 | 40 | @Bean 41 | Binding binding(Queue queue, TopicExchange exchange) { 42 | return BindingBuilder.bind(queue).to(exchange).with(queueName); 43 | } 44 | 45 | @Bean 46 | SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, 47 | MessageListenerAdapter listenerAdapter) { 48 | SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); 49 | container.setConnectionFactory(connectionFactory); 50 | container.setQueueNames(queueName); 51 | container.setMessageListener(listenerAdapter); 52 | return container; 53 | } 54 | 55 | @Bean 56 | MessageListenerAdapter listenerAdapter(Receiver receiver) { 57 | return new MessageListenerAdapter(receiver, "receiveMessage"); 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/dao/SysLogDAO.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.dao; 2 | 3 | import com.fly.log.entity.SysLog; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | public interface SysLogDAO extends JpaRepository { 14 | } 15 | -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/entity/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.entity; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | import java.util.Date; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | @Entity 15 | public class SysLog implements Serializable { 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | //用户名 20 | @Column 21 | private String username; 22 | //用户操作 23 | @Column 24 | private String operation; 25 | //请求方法 26 | @Column 27 | private String method; 28 | //请求参数 29 | @Column 30 | private String params; 31 | //IP地址 32 | @Column 33 | private String ip; 34 | //创建时间 35 | @Column 36 | private Date createDate; 37 | public SysLog() { 38 | } 39 | public Long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(Long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getUsername() { 48 | return username; 49 | } 50 | 51 | public void setUsername(String username) { 52 | this.username = username; 53 | } 54 | 55 | public String getOperation() { 56 | return operation; 57 | } 58 | 59 | public void setOperation(String operation) { 60 | this.operation = operation; 61 | } 62 | 63 | public String getMethod() { 64 | return method; 65 | } 66 | 67 | public void setMethod(String method) { 68 | this.method = method; 69 | } 70 | 71 | public String getParams() { 72 | return params; 73 | } 74 | 75 | public void setParams(String params) { 76 | this.params = params; 77 | } 78 | 79 | public String getIp() { 80 | return ip; 81 | } 82 | 83 | public void setIp(String ip) { 84 | this.ip = ip; 85 | } 86 | 87 | public Date getCreateDate() { 88 | return createDate; 89 | } 90 | 91 | public void setCreateDate(Date createDate) { 92 | this.createDate = createDate; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/rabbit/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.rabbit; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.log.entity.SysLog; 5 | import com.fly.log.service.SysLogService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.concurrent.CountDownLatch; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @Component 19 | public class Receiver { 20 | 21 | private CountDownLatch latch = new CountDownLatch(1); 22 | 23 | @Autowired 24 | SysLogService sysLogService; 25 | public void receiveMessage(String message) { 26 | System.out.println("Received <" + message + ">"); 27 | SysLog sysLog= JSON.parseObject(message,SysLog.class); 28 | sysLogService.saveLogger(sysLog); 29 | latch.countDown(); 30 | } 31 | 32 | 33 | } -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/rabbit/Sender.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.rabbit; 2 | 3 | import com.fly.log.config.RabbitConfig; 4 | import org.springframework.amqp.core.AmqpTemplate; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @Component 18 | public class Sender { 19 | 20 | @Autowired 21 | private AmqpTemplate rabbitTemplate; 22 | 23 | public void send() { 24 | String context = "hello " + new Date(); 25 | System.out.println("Sender : " + context); 26 | rabbitTemplate.convertAndSend(RabbitConfig.queueName, "Hello from RabbitMQ!"); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/rabbit/User.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.rabbit; 2 | 3 | /** 4 | * Description:
5 | * Author:    mxdl
6 | * Date:     2019/2/19
7 | * Version:   V1.0.0
8 | * Update:    
9 | */ 10 | public class User { 11 | private String username; 12 | private String password; 13 | 14 | 15 | public User(String username, String password) { 16 | this.username = username; 17 | this.password = password; 18 | } 19 | 20 | public String getUsername() { 21 | return username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username; 26 | } 27 | 28 | public String getPassword() { 29 | return password; 30 | } 31 | 32 | public void setPassword(String password) { 33 | this.password = password; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "User{" + 39 | "username='" + username + '\'' + 40 | ", password='" + password + '\'' + 41 | '}'; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /module_log/src/main/java/com/fly/log/service/SysLogService.java: -------------------------------------------------------------------------------- 1 | package com.fly.log.service; 2 | 3 | import com.fly.log.entity.SysLog; 4 | import com.fly.log.dao.SysLogDAO; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * Description: <>
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @Service 16 | public class SysLogService { 17 | 18 | @Autowired 19 | SysLogDAO sysLogDAO; 20 | 21 | public void saveLogger(SysLog sysLog){ 22 | System.out.println("MYTAG:Logger saveLogger start..."); 23 | sysLogDAO.save(sysLog); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /module_log/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: logger-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | 11 | # datasource: 12 | # driver-class-name: com.mysql.jdbc.Driver 13 | # url: jdbc:mysql://localhost:3306/sys-log?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 14 | # username: root 15 | # password: 123456 16 | # jpa: 17 | # hibernate: 18 | # ddl-auto: update 19 | # show-sql: true 20 | # 21 | # rabbitmq: 22 | # host: localhost 23 | # port: 5672 24 | # username: guest 25 | # password: guest 26 | # publisher-confirms: true 27 | # virtual-host: / -------------------------------------------------------------------------------- /module_monitor/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.boot:spring-boot-starter-actuator' 3 | compile 'org.springframework.cloud:spring-cloud-starter-config' 4 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-turbine' 5 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix-dashboard' 6 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-hystrix' 7 | } 8 | jar { 9 | manifest { 10 | attributes 'Main-Class': 'com.fly.monitor.MonitorServiceApplication' 11 | } 12 | } -------------------------------------------------------------------------------- /module_monitor/src/main/java/com/fly/monitor/MonitorServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.monitor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 6 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 7 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 8 | 9 | /** 10 | * Description:
11 | * Author:    mxdl
12 | * Date:     2019/2/19
13 | * Version:   V1.0.0
14 | * Update:    
15 | */ 16 | @SpringBootApplication 17 | @EnableTurbine 18 | @EnableHystrixDashboard 19 | @EnableHystrix 20 | public class MonitorServiceApplication { 21 | 22 | public static void main(String[] args) { 23 | SpringApplication.run(MonitorServiceApplication.class, args); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /module_monitor/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: monitor-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro -------------------------------------------------------------------------------- /module_news/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':lib_common') 3 | } 4 | jar { 5 | manifest { 6 | attributes 'Main-Class': 'com.fly.news.NewsServiceApplication' 7 | } 8 | } -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/NewsServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.news; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * Description: <>
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @SpringBootApplication 18 | @EnableEurekaClient 19 | @EnableFeignClients 20 | @EnableHystrixDashboard 21 | @EnableHystrix 22 | public class NewsServiceApplication { 23 | public static void main(String[] args) { 24 | SpringApplication.run(NewsServiceApplication.class, args); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/aop/SysLoggerAspect.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.aop; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.common.annotation.SysLogger; 5 | import com.fly.news.entity.SysLog; 6 | import com.fly.news.service.LoggerService; 7 | import com.fly.news.util.HttpUtils; 8 | import com.fly.news.util.UserUtils; 9 | import org.apache.commons.lang.StringUtils; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Before; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.MethodSignature; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Component; 17 | import java.lang.reflect.Method; 18 | import java.util.Date; 19 | 20 | /** 21 | * Description: <>
22 | * Author:    mxdl
23 | * Date:     2019/2/19
24 | * Version:   V1.0.0
25 | * Update:    
26 | */ 27 | @Aspect 28 | @Component 29 | public class SysLoggerAspect { 30 | @Autowired 31 | private LoggerService loggerService; 32 | 33 | @Pointcut("@annotation(com.fly.common.annotation.SysLogger)") 34 | public void loggerPointCut() { 35 | 36 | } 37 | 38 | @Before("loggerPointCut()") 39 | public void saveSysLog(JoinPoint joinPoint) { 40 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 41 | Method method = signature.getMethod(); 42 | 43 | SysLog sysLog = new SysLog(); 44 | SysLogger sysLogger = method.getAnnotation(SysLogger.class); 45 | if (sysLogger != null) { 46 | //注解上的描述 47 | sysLog.setOperation(sysLogger.value()); 48 | } 49 | //请求的方法名 50 | String className = joinPoint.getTarget().getClass().getName(); 51 | String methodName = signature.getName(); 52 | sysLog.setMethod(className + "." + methodName + "()"); 53 | //请求的参数 54 | Object[] args = joinPoint.getArgs(); 55 | String params = ""; 56 | for (Object o : args) { 57 | params += JSON.toJSONString(o); 58 | } 59 | if (!StringUtils.isEmpty(params)) { 60 | sysLog.setParams(params); 61 | } 62 | //设置IP地址 63 | sysLog.setIp(HttpUtils.getIpAddress()); 64 | //用户名 65 | String username = UserUtils.getCurrentPrinciple(); 66 | if (!StringUtils.isEmpty(username)) { 67 | sysLog.setUsername(username); 68 | } 69 | sysLog.setCreateDate(new Date()); 70 | //保存系统日志 71 | loggerService.log(sysLog); 72 | } 73 | 74 | } 75 | 76 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/client/UserServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.client; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.news.client.hystrix.UserServiceHystrix; 5 | import com.fly.news.entity.User; 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestHeader; 10 | 11 | 12 | /** 13 | * Description:
14 | * Author:    mxdl
15 | * Date:     2019/2/19
16 | * Version:   V1.0.0
17 | * Update:    
18 | */ 19 | @FeignClient(value = "user-service",fallback = UserServiceHystrix.class ) 20 | public interface UserServiceClient { 21 | 22 | @PostMapping(value = "/user/{username}") 23 | RespDTO getUser(@RequestHeader(value = "Authorization") String token, @PathVariable("username") String username); 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/client/hystrix/UserServiceHystrix.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.client.hystrix; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.news.client.UserServiceClient; 5 | import com.fly.news.entity.User; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @Component 16 | public class UserServiceHystrix implements UserServiceClient { 17 | 18 | @Override 19 | public RespDTO getUser(String token, String username) { 20 | System.out.println(token); 21 | System.out.println(username); 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/config/GlobalMethodSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @Configuration 14 | @EnableGlobalMethodSecurity(prePostEnabled = true) 15 | public class GlobalMethodSecurityConfiguration { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/config/JwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.core.io.Resource; 9 | import org.springframework.security.oauth2.provider.token.TokenStore; 10 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 11 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 12 | import org.springframework.util.FileCopyUtils; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * Description:
18 | * Author:    mxdl
19 | * Date:     2019/2/19
20 | * Version:   V1.0.0
21 | * Update:    
22 | */ 23 | @Configuration 24 | public class JwtConfiguration { 25 | @Autowired 26 | JwtAccessTokenConverter jwtAccessTokenConverter; 27 | 28 | @Bean 29 | @Qualifier("tokenStore") 30 | public TokenStore tokenStore() { 31 | 32 | System.out.println("Created JwtTokenStore"); 33 | return new JwtTokenStore(jwtAccessTokenConverter); 34 | } 35 | 36 | @Bean 37 | protected JwtAccessTokenConverter jwtTokenEnhancer() { 38 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 39 | Resource resource = new ClassPathResource("public.cert"); 40 | String publicKey ; 41 | try { 42 | publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | converter.setVerifierKey(publicKey); 47 | return converter; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/config/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.config; 2 | 3 | 4 | import org.springframework.amqp.core.Binding; 5 | import org.springframework.amqp.core.BindingBuilder; 6 | import org.springframework.amqp.core.Queue; 7 | import org.springframework.amqp.core.TopicExchange; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @Configuration 19 | public class RabbitConfig { 20 | 21 | 22 | public final static String queueName = "spring-boot"; 23 | 24 | @Bean 25 | Queue queue() { 26 | return new Queue(queueName, false); 27 | } 28 | 29 | @Bean 30 | TopicExchange exchange() { 31 | return new TopicExchange("spring-boot-exchange"); 32 | } 33 | 34 | @Bean 35 | Binding binding(Queue queue, TopicExchange exchange) { 36 | return BindingBuilder.bind(queue).to(exchange).with(queueName); 37 | } 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/config/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 9 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 10 | import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; 11 | import org.springframework.security.oauth2.provider.token.TokenStore; 12 | 13 | /** 14 | * Description:
15 | * Author:    mxdl
16 | * Date:     2019/2/19
17 | * Version:   V1.0.0
18 | * Update:    
19 | */ 20 | @Configuration 21 | @EnableResourceServer 22 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter{ 23 | Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class); 24 | 25 | @Override 26 | public void configure(HttpSecurity http) throws Exception { 27 | http 28 | .csrf().disable() 29 | .authorizeRequests() 30 | .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*").permitAll() 31 | .antMatchers("/**").authenticated(); 32 | // .antMatchers("/**").permitAll(); 33 | } 34 | 35 | 36 | @Override 37 | public void configure(ResourceServerSecurityConfigurer resources) throws Exception { 38 | log.info("Configuring ResourceServerSecurityConfigurer "); 39 | resources.resourceId("news-service").tokenStore(tokenStore); 40 | } 41 | 42 | @Autowired 43 | TokenStore tokenStore; 44 | } 45 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.ParameterBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.schema.ModelRef; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Parameter; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | 20 | /** 21 | * Description:
22 | * Author:    mxdl
23 | * Date:     2019/2/19
24 | * Version:   V1.0.0
25 | * Update:    
26 | */ 27 | @Configuration 28 | @EnableSwagger2 29 | public class SwaggerConfig { 30 | /** 31 | * 全局参数 32 | * 33 | * @return 34 | */ 35 | private List parameter() { 36 | List params = new ArrayList<>(); 37 | params.add(new ParameterBuilder().name("Authorization") 38 | .description("Authorization Bearer token") 39 | .modelRef(new ModelRef("string")) 40 | .parameterType("header") 41 | .required(false).build()); 42 | return params; 43 | } 44 | 45 | @Bean 46 | public Docket sysApi() { 47 | return new Docket(DocumentationType.SWAGGER_2) 48 | .apiInfo(apiInfo()) 49 | .select() 50 | .apis(RequestHandlerSelectors.basePackage("com.fly")) 51 | .paths(PathSelectors.any()) 52 | .build().globalOperationParameters(parameter()); 53 | } 54 | 55 | private ApiInfo apiInfo() { 56 | return new ApiInfoBuilder() 57 | .title(" news-service api ") 58 | .description("news-service 微服务") 59 | .termsOfServiceUrl("") 60 | .contact("fly") 61 | .version("1.0") 62 | .build(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/dao/NewsDetailDao.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.dao; 2 | 3 | import com.fly.news.entity.NewsDetail; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/6/11
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | public interface NewsDetailDao extends JpaRepository{ 16 | List findByTypeid(int typeid); 17 | } -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/dao/NewsTypeDao.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.dao; 2 | 3 | 4 | import com.fly.news.entity.NewsType; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | public interface NewsTypeDao extends JpaRepository { 15 | } 16 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/entity/NewsDetail.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import org.springframework.data.annotation.CreatedDate; 5 | 6 | import javax.persistence.*; 7 | import java.util.Date; 8 | 9 | /** 10 | * Description:
11 | * Author:    mxdl
12 | * Date:     2019/6/11
13 | * Version:   V1.0.0
14 | * Update:    
15 | */ 16 | @Entity 17 | @Table(name = "news_detail") 18 | public class NewsDetail { 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.IDENTITY) 21 | @Column(name = "id") 22 | private Long id; 23 | 24 | @Column(name = "typeid") 25 | private int typeid; 26 | 27 | @Column(name = "title") 28 | private String title; 29 | 30 | @Column(name = "content") 31 | private String content; 32 | 33 | @CreatedDate 34 | @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") 35 | @Column(name = "addtime", updatable = false, nullable = false) 36 | private Date addtime; 37 | 38 | public Long getId() { 39 | return id; 40 | } 41 | 42 | public void setId(Long id) { 43 | this.id = id; 44 | } 45 | 46 | public int getTypeid() { 47 | return typeid; 48 | } 49 | 50 | public void setTypeid(int typeid) { 51 | this.typeid = typeid; 52 | } 53 | 54 | public String getTitle() { 55 | return title; 56 | } 57 | 58 | public void setTitle(String title) { 59 | this.title = title; 60 | } 61 | 62 | public String getContent() { 63 | return content; 64 | } 65 | 66 | public void setContent(String content) { 67 | this.content = content; 68 | } 69 | 70 | public Date getAddtime() { 71 | return addtime; 72 | } 73 | 74 | public void setAddtime(Date addtime) { 75 | this.addtime = addtime; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/entity/NewsType.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import org.springframework.data.annotation.CreatedDate; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.Date; 9 | 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/6/11
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @Entity 18 | @Table(name = "news_type") 19 | public class NewsType implements Serializable { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | @Column(name = "id") 23 | private Long id; 24 | 25 | @Column(name = "typename", nullable = false) 26 | private String typename; 27 | 28 | public NewsType() { 29 | } 30 | 31 | /** 32 | * 创建时间 33 | */ 34 | @CreatedDate 35 | @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss") 36 | @Column(name = "addtime", updatable = false, nullable = true) 37 | private Date addtime; 38 | 39 | public Long getId() { 40 | return id; 41 | } 42 | 43 | public void setId(Long id) { 44 | this.id = id; 45 | } 46 | 47 | public String getTypename() { 48 | return typename; 49 | } 50 | 51 | public void setTypename(String typename) { 52 | this.typename = typename; 53 | } 54 | 55 | public Date getAddtime() { 56 | return addtime; 57 | } 58 | 59 | public void setAddtime(Date addtime) { 60 | this.addtime = addtime; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/entity/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | public class SysLog { 13 | 14 | private Long id; 15 | //用户名 16 | private String username; 17 | //用户操作 18 | private String operation; 19 | //请求方法 20 | private String method; 21 | //请求参数 22 | private String params; 23 | //IP地址 24 | private String ip; 25 | //创建时间 26 | private Date createDate; 27 | 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | 37 | public String getUsername() { 38 | return username; 39 | } 40 | 41 | public void setUsername(String username) { 42 | this.username = username; 43 | } 44 | 45 | public String getOperation() { 46 | return operation; 47 | } 48 | 49 | public void setOperation(String operation) { 50 | this.operation = operation; 51 | } 52 | 53 | public String getMethod() { 54 | return method; 55 | } 56 | 57 | public void setMethod(String method) { 58 | this.method = method; 59 | } 60 | 61 | public String getParams() { 62 | return params; 63 | } 64 | 65 | public void setParams(String params) { 66 | this.params = params; 67 | } 68 | 69 | public String getIp() { 70 | return ip; 71 | } 72 | 73 | public void setIp(String ip) { 74 | this.ip = ip; 75 | } 76 | 77 | public Date getCreateDate() { 78 | return createDate; 79 | } 80 | 81 | public void setCreateDate(Date createDate) { 82 | this.createDate = createDate; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.entity; 2 | 3 | /** 4 | * Description:
5 | * Author:    mxdl
6 | * Date:     2019/2/19
7 | * Version:   V1.0.0
8 | * Update:    
9 | */ 10 | public class User { 11 | 12 | private Long id; 13 | private String username; 14 | private String password; 15 | 16 | public Long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(Long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getUsername() { 25 | return username; 26 | } 27 | 28 | public void setUsername(String username) { 29 | this.username = username; 30 | } 31 | 32 | public String getPassword() { 33 | return password; 34 | } 35 | 36 | public void setPassword(String password) { 37 | this.password = password; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/exception/CommonExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.exception; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.common.exception.CommonException; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @ControllerAdvice 19 | @ResponseBody 20 | public class CommonExceptionHandler { 21 | 22 | @ExceptionHandler(CommonException.class) 23 | public ResponseEntity handleException(Exception e) { 24 | RespDTO resp = new RespDTO(); 25 | CommonException taiChiException = (CommonException) e; 26 | resp.code = taiChiException.getCode(); 27 | resp.error = e.getMessage(); 28 | return new ResponseEntity(resp, HttpStatus.OK); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/service/LoggerService.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.service; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.news.config.RabbitConfig; 5 | import com.fly.news.entity.SysLog; 6 | import org.springframework.amqp.core.AmqpTemplate; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @Service 18 | public class LoggerService { 19 | 20 | @Autowired 21 | private AmqpTemplate rabbitTemplate; 22 | 23 | public void log(SysLog sysLog){ 24 | rabbitTemplate.convertAndSend(RabbitConfig.queueName, JSON.toJSONString(sysLog)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/service/NewsDetailService.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.service; 2 | 3 | 4 | import com.fly.news.dao.NewsDetailDao; 5 | import com.fly.news.dao.NewsTypeDao; 6 | import com.fly.news.entity.NewsDetail; 7 | import com.fly.news.entity.NewsType; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * Description:
15 | * Author:    mxdl
16 | * Date:     2019/2/19
17 | * Version:   V1.0.0
18 | * Update:    
19 | */ 20 | @Service 21 | public class NewsDetailService { 22 | 23 | @Autowired 24 | NewsDetailDao newsDetailDao; 25 | 26 | public NewsDetail saveNewsDetail(NewsDetail newsDetail) { 27 | return newsDetailDao.save(newsDetail); 28 | } 29 | 30 | public void deleteNewsDetail(long id) { 31 | newsDetailDao.deleteById(id); 32 | } 33 | public NewsDetail findNewsDetailById(long id) { 34 | return newsDetailDao.findById(id).get(); 35 | } 36 | public List findListByTypeid(int typeid) { 37 | return newsDetailDao.findByTypeid(typeid); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/service/NewsTypeService.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.service; 2 | import com.fly.news.dao.NewsTypeDao; 3 | import com.fly.news.entity.NewsType; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Service; 6 | import java.util.List; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @Service 16 | public class NewsTypeService { 17 | 18 | @Autowired 19 | NewsTypeDao newsTypeDao; 20 | 21 | //@Autowired 22 | //UserServiceClient userServiceClient; 23 | 24 | public NewsType saveNewsType(NewsType newstype) { 25 | return newsTypeDao.save(newstype); 26 | } 27 | 28 | public void deleteBlog(long id) { 29 | newsTypeDao.deleteById(id); 30 | } 31 | 32 | public List findListNewsType(){ 33 | return newsTypeDao.findAll(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.util; 2 | 3 | 4 | import org.springframework.web.context.request.RequestContextHolder; 5 | import org.springframework.web.context.request.ServletRequestAttributes; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.util.Enumeration; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Description: <>
14 | * Author:    mxdl
15 | * Date:     2019/2/19
16 | * Version:   V1.0.0
17 | * Update:    
18 | */ 19 | public class HttpUtils { 20 | 21 | 22 | /** 23 | * 尝试获取当前请求的HttpServletRequest实例 24 | * 25 | * @return HttpServletRequest 26 | */ 27 | public static HttpServletRequest getHttpServletRequest() { 28 | try { 29 | return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 30 | } catch (Exception e) { 31 | return null; 32 | } 33 | } 34 | 35 | 36 | public static Map getHeaders(HttpServletRequest request) { 37 | Map map = new LinkedHashMap<>(); 38 | Enumeration enumeration = request.getHeaderNames(); 39 | while (enumeration.hasMoreElements()) { 40 | String key = enumeration.nextElement(); 41 | String value = request.getHeader(key); 42 | map.put(key, value); 43 | } 44 | return map; 45 | } 46 | 47 | /** 48 | * 获取请求客户端的真实ip地址 49 | * 50 | * @param request 请求对象 51 | * @return ip地址 52 | */ 53 | public static String getIpAddress(HttpServletRequest request) { 54 | 55 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 56 | String ip = request.getHeader("X-Forwarded-For"); 57 | 58 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 59 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 60 | ip = request.getHeader("Proxy-Client-IP"); 61 | } 62 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 63 | ip = request.getHeader("WL-Proxy-Client-IP"); 64 | } 65 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 66 | ip = request.getHeader("HTTP_CLIENT_IP"); 67 | } 68 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 69 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 70 | } 71 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 72 | ip = request.getRemoteAddr(); 73 | } 74 | } else if (ip.length() > 15) { 75 | String[] ips = ip.split(","); 76 | for (int index = 0; index < ips.length; index++) { 77 | String strIp = (String) ips[index]; 78 | if (!("unknown".equalsIgnoreCase(strIp))) { 79 | ip = strIp; 80 | break; 81 | } 82 | } 83 | } 84 | return ip; 85 | } 86 | 87 | /** 88 | * 获取请求客户端的真实ip地址 89 | * 90 | * @param 91 | * @return ip地址 92 | */ 93 | public static String getIpAddress() { 94 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 95 | return getIpAddress(getHttpServletRequest()); 96 | } 97 | 98 | 99 | 100 | 101 | } 102 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/util/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.util; 2 | 3 | 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Description: <>
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | public class UserUtils { 18 | 19 | private static final String AUTHORIZATION = "authorization"; 20 | 21 | /** 22 | * 获取当前请求的token 23 | * 24 | * @return 25 | */ 26 | public static String getCurrentToken() { 27 | return HttpUtils.getHeaders(HttpUtils.getHttpServletRequest()).get(AUTHORIZATION); 28 | } 29 | 30 | /** 31 | * 获取当前请求的用户Id 32 | * 33 | * @return 34 | */ 35 | public static String getCurrentPrinciple() { 36 | return (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 37 | } 38 | 39 | /** 40 | * 判读当前token用户是否为接口所需的参数username 41 | * 42 | * @param username 43 | * @return 44 | */ 45 | public static boolean isMyself(String username) { 46 | return username.equals(getCurrentPrinciple()); 47 | } 48 | 49 | /** 50 | * 获取当前请求Authentication 51 | * 52 | * @return 53 | */ 54 | public static Authentication getCurrentAuthentication() { 55 | return SecurityContextHolder.getContext().getAuthentication(); 56 | } 57 | 58 | /** 59 | * 获取当前请求的权限信息 60 | * 61 | * @return 62 | */ 63 | public static List getCurrentAuthorities() { 64 | return (List) SecurityContextHolder.getContext().getAuthentication().getAuthorities(); 65 | } 66 | 67 | /** 68 | * @param role 69 | * @return 70 | */ 71 | public static boolean hasRole(String role) { 72 | if (!role.startsWith("ROLE_")) { 73 | role = "ROLE_" + role; 74 | } 75 | boolean hasRole = false; 76 | List list = getCurrentAuthorities(); 77 | for (SimpleGrantedAuthority s : list) { 78 | if (role.equals(s.getAuthority())) { 79 | hasRole = true; 80 | break; 81 | } 82 | } 83 | return hasRole; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/web/NewsDetailController.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.web; 2 | 3 | import com.fly.common.annotation.SysLogger; 4 | import com.fly.common.dto.RespDTO; 5 | import com.fly.news.entity.NewsDetail; 6 | import com.fly.news.service.NewsDetailService; 7 | import io.swagger.annotations.ApiOperation; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.access.prepost.PreAuthorize; 10 | import org.springframework.web.bind.annotation.*; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Description: <>
16 | * Author:    mxdl
17 | * Date:     2019/2/19
18 | * Version:   V1.0.0
19 | * Update:    
20 | */ 21 | @RestController 22 | @RequestMapping("/newsdetail") 23 | public class NewsDetailController { 24 | 25 | @Autowired 26 | NewsDetailService newsDetailService; 27 | 28 | @ApiOperation(value = "添加新闻详情", notes = "添加新闻详情") 29 | @PreAuthorize("hasRole('USER')") 30 | @PostMapping("/save") 31 | @SysLogger("addNewsDetail") 32 | public RespDTO saveNewsDetail(@RequestBody NewsDetail newsDetail){ 33 | NewsDetail newsDetail1 = newsDetailService.saveNewsDetail(newsDetail); 34 | return RespDTO.onSuc(newsDetail1); 35 | } 36 | 37 | @ApiOperation(value = "获取指定类型的新闻列表", notes = "获取指定类型的新闻列表") 38 | @PreAuthorize("hasAuthority('ROLE_USER')") 39 | @PostMapping("/query/all") 40 | @SysLogger("getListNewsDetail") 41 | public RespDTO getListNewsDetail(int typid){ 42 | List newsDetails = newsDetailService.findListByTypeid(typid); 43 | return RespDTO.onSuc(newsDetails); 44 | } 45 | 46 | @ApiOperation(value = "根据id查询新闻详情", notes = "根据id查询新闻详情") 47 | @PreAuthorize("hasAuthority('ROLE_USER')") 48 | @GetMapping("/{id}/detail") 49 | @SysLogger("queryNewsDetail") 50 | public RespDTO getNewsDetail(@PathVariable Long id){ 51 | return RespDTO.onSuc(newsDetailService.findNewsDetailById(id)); 52 | } 53 | 54 | @ApiOperation(value = "根据id删除新闻详情", notes = "根据id删除新闻详情") 55 | @PreAuthorize("hasAuthority('ROLE_USER')") 56 | @GetMapping("/{id}/delete") 57 | @SysLogger("deleteNewsDetail") 58 | public RespDTO deleteNewsDetail(@PathVariable Long id){ 59 | RespDTO respDTO = new RespDTO(); 60 | try { 61 | newsDetailService.deleteNewsDetail(id); 62 | respDTO.setError("删除成功"); 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | respDTO.setCode(1); 66 | respDTO.setError("删除失败"); 67 | } 68 | return respDTO; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /module_news/src/main/java/com/fly/news/web/NewsTypeController.java: -------------------------------------------------------------------------------- 1 | package com.fly.news.web; 2 | 3 | import com.fly.common.annotation.SysLogger; 4 | import com.fly.common.dto.RespDTO; 5 | import com.fly.common.exception.CommonException; 6 | import com.fly.common.exception.ErrorCode; 7 | import com.fly.news.entity.NewsType; 8 | import com.fly.news.service.NewsTypeService; 9 | import com.fly.news.util.UserUtils; 10 | import io.swagger.annotations.ApiOperation; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.access.prepost.PreAuthorize; 13 | import org.springframework.web.bind.annotation.*; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * Description: <>
19 | * Author:    mxdl
20 | * Date:     2019/2/19
21 | * Version:   V1.0.0
22 | * Update:    
23 | */ 24 | @RestController 25 | @RequestMapping("/newstype") 26 | public class NewsTypeController { 27 | 28 | @Autowired 29 | NewsTypeService newsTypeService; 30 | 31 | @ApiOperation(value = "添加新闻类型", notes = "添加新闻类型") 32 | @PreAuthorize("hasRole('USER')") 33 | @PostMapping("/save") 34 | @SysLogger("addNewsType") 35 | public RespDTO saveNewsType(@RequestBody NewsType newsType){ 36 | NewsType newsType1 = newsTypeService.saveNewsType(newsType); 37 | return RespDTO.onSuc(newsType1); 38 | } 39 | 40 | @ApiOperation(value = "获取所有的新闻类型", notes = "获取所有的新闻类型") 41 | @PreAuthorize("hasAuthority('ROLE_USER')") 42 | @PostMapping("/query/all") 43 | @SysLogger("getListNewsType") 44 | public RespDTO getListNewsType(){ 45 | List newsTypes = newsTypeService.findListNewsType(); 46 | return RespDTO.onSuc(newsTypes); 47 | } 48 | 49 | @ApiOperation(value = "根据id删除新闻类型", notes = "根据id删除新闻类型") 50 | @PreAuthorize("hasAuthority('ROLE_USER')") 51 | @GetMapping("/{id}/delete") 52 | @SysLogger("deleteNewsType") 53 | public RespDTO deleteNewsType(@PathVariable Long id){ 54 | RespDTO respDTO = new RespDTO(); 55 | try { 56 | newsTypeService.deleteBlog(id); 57 | respDTO.setError("删除成功"); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | respDTO.setCode(1); 61 | respDTO.setError("删除失败"); 62 | } 63 | return respDTO; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /module_news/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: news-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | # zipkin: 11 | # base-url: http://localhost:9411 12 | # 13 | # datasource: 14 | # driver-class-name: com.mysql.jdbc.Driver 15 | # url: jdbc:mysql://localhost:3306/sys_blog?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8 16 | # username: root 17 | # password: 123456 18 | # jpa: 19 | # hibernate: 20 | # ddl-auto: update 21 | # show-sql: true 22 | # 23 | # rabbitmq: 24 | # host: localhost 25 | # port: 5672 26 | # username: guest 27 | # password: guest 28 | # publisher-confirms: true 29 | # virtual-host: / -------------------------------------------------------------------------------- /module_news/src/main/resources/public.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3FtAe8QQmu3k/Jalrx24 3 | rKfOQ+vtji4kwu/wubWKN87BZDyv4tau3VJ1Ub9JpsEFMi0csoZmuUNEEWx+lNOf 4 | i9QWoKNQgQ8nUWkmqiVc1BvAsrBUkuvx1zDKHYkwZ4i45aRnDcBthsTaI4PbsweD 5 | YPhW3N06YBIkZVLLMmc+IHFX+Bnmd6DcWlFU/eAeM8/6TGUhR2BoSV0zBrPR85XW 6 | E0/ZVA8XdYOdf6RvAwms0NkAvEwjHV8O7x/7Uq4+i7+YK5vrZEzVUD2TVCgDpTbJ 7 | 55Qb5BKICtIbi5F2mI2DmQ7zwGAH1tFvDmVDS9ZQy+nfy8aQ5MJ+Lutmi0IjQdHX 8 | 5QIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /module_uaa/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.boot:spring-boot-starter-web' 3 | compile 'org.springframework.boot:spring-boot-starter-data-jpa' 4 | compile 'org.springframework.boot:spring-boot-starter-actuator' 5 | compile 'org.springframework.cloud:spring-cloud-starter-config' 6 | compile 'org.springframework.cloud:spring-cloud-starter-oauth2' 7 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 8 | compile 'mysql:mysql-connector-java' 9 | } 10 | jar { 11 | manifest { 12 | attributes 'Main-Class': 'com.fly.uaa.UaaServiceApplication' 13 | } 14 | } -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/UaaServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | @SpringBootApplication 15 | @EnableEurekaClient 16 | public class UaaServiceApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(UaaServiceApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/config/MyPasswordEncoder.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.config; 2 | 3 | import org.springframework.security.crypto.password.PasswordEncoder; 4 | 5 | public class MyPasswordEncoder implements PasswordEncoder { 6 | @Override 7 | public String encode(CharSequence charSequence) { 8 | return charSequence.toString(); 9 | } 10 | 11 | @Override 12 | public boolean matches(CharSequence charSequence, String s) { 13 | return s.equals(charSequence.toString()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/config/OAuth2Config.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.http.HttpMethod; 9 | import org.springframework.security.authentication.AuthenticationManager; 10 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 11 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 12 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 13 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 14 | import org.springframework.security.oauth2.provider.token.TokenStore; 15 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 16 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 17 | import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory; 18 | 19 | /** 20 | * Description:
21 | * Author:    mxdl
22 | * Date:     2019/2/19
23 | * Version:   V1.0.0
24 | * Update:    
25 | */ 26 | @Configuration 27 | @EnableAuthorizationServer 28 | public class OAuth2Config extends AuthorizationServerConfigurerAdapter { 29 | @Override 30 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 31 | clients.inMemory() 32 | .withClient("uaa-service") 33 | .secret("{noop}123456") 34 | .scopes("service") 35 | .autoApprove(true) 36 | .authorizedGrantTypes("implicit","refresh_token", "password", "authorization_code") 37 | .accessTokenValiditySeconds(24*3600);//24小时过期 38 | } 39 | 40 | @Override 41 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 42 | endpoints 43 | .tokenStore(tokenStore()) 44 | .tokenEnhancer(jwtTokenEnhancer()) 45 | .allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST) 46 | .authenticationManager(authenticationManager); 47 | } 48 | 49 | @Autowired 50 | @Qualifier("authenticationManagerBean") 51 | private AuthenticationManager authenticationManager; 52 | 53 | @Bean 54 | public TokenStore tokenStore() { 55 | return new JwtTokenStore(jwtTokenEnhancer()); 56 | } 57 | 58 | @Bean 59 | protected JwtAccessTokenConverter jwtTokenEnhancer() { 60 | KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource("fly-jwt.jks"), "fly123".toCharArray()); 61 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 62 | converter.setKeyPair(keyStoreKeyFactory.getKeyPair("fly-jwt")); 63 | return converter; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.config; 2 | 3 | 4 | import com.fly.uaa.service.UserServiceDetail; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.authentication.AuthenticationManager; 9 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 10 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 | import org.springframework.security.core.AuthenticationException; 13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 | import org.springframework.security.web.AuthenticationEntryPoint; 15 | 16 | import javax.servlet.ServletException; 17 | import javax.servlet.http.HttpServletRequest; 18 | import javax.servlet.http.HttpServletResponse; 19 | import java.io.IOException; 20 | 21 | /** 22 | * Description:
23 | * Author:    mxdl
24 | * Date:     2019/2/19
25 | * Version:   V1.0.0
26 | * Update:    
27 | */ 28 | @Configuration 29 | class WebSecurityConfig extends WebSecurityConfigurerAdapter { 30 | 31 | @Override 32 | @Bean 33 | public AuthenticationManager authenticationManagerBean() throws Exception { 34 | return super.authenticationManagerBean(); 35 | } 36 | 37 | @Override 38 | protected void configure(HttpSecurity http) throws Exception { 39 | //CSRF:因为不再依赖于Cookie,所以你就不需要考虑对CSRF(跨站请求伪造)的防范。 40 | http 41 | .csrf().disable() 42 | .exceptionHandling() 43 | // .authenticationEntryPoint((request, response, authException) -> response.sendError(HttpServletResponse.SC_UNAUTHORIZED)) 44 | .authenticationEntryPoint(new AuthenticationEntryPoint() { 45 | @Override 46 | public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { 47 | httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); 48 | } 49 | }) 50 | .and() 51 | .authorizeRequests() 52 | .antMatchers("/**").authenticated() 53 | .and() 54 | .httpBasic(); 55 | } 56 | 57 | @Autowired 58 | UserServiceDetail userServiceDetail; 59 | @Override 60 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 61 | auth.userDetailsService(userServiceDetail) 62 | .passwordEncoder(new BCryptPasswordEncoder()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.dao; 2 | 3 | 4 | import com.fly.uaa.entity.User; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | public interface UserDao extends JpaRepository { 15 | 16 | User findByUsername(String username); 17 | } 18 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.entity; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | 5 | import javax.persistence.*; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | @Entity 15 | public class Role implements GrantedAuthority { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.IDENTITY) 19 | private Long id; 20 | 21 | @Column(nullable = false) 22 | private String name; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | @Override 33 | public String getAuthority() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return name; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.entity; 2 | 3 | import org.springframework.security.core.GrantedAuthority; 4 | import org.springframework.security.core.userdetails.UserDetails; 5 | 6 | import javax.persistence.*; 7 | import java.io.Serializable; 8 | import java.util.Collection; 9 | import java.util.List; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @Entity 19 | public class User implements UserDetails, Serializable { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Long id; 23 | 24 | @Column(nullable = false, unique = true) 25 | private String username; 26 | 27 | @Column 28 | private String password; 29 | 30 | @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) 31 | @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), 32 | inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id")) 33 | private List authorities; 34 | 35 | 36 | public User() { 37 | } 38 | 39 | public Long getId() { 40 | return id; 41 | } 42 | public void setId(Long id) { 43 | this.id = id; 44 | } 45 | 46 | @Override 47 | public Collection getAuthorities() { 48 | return authorities; 49 | } 50 | 51 | public void setAuthorities(List authorities) { 52 | this.authorities = authorities; 53 | } 54 | 55 | @Override 56 | public String getUsername() { 57 | return username; 58 | } 59 | 60 | public void setUsername(String username) { 61 | this.username = username; 62 | } 63 | 64 | @Override 65 | public String getPassword() { 66 | return password; 67 | } 68 | 69 | public void setPassword(String password) { 70 | this.password = password; 71 | } 72 | 73 | @Override 74 | public boolean isAccountNonExpired() { 75 | return true; 76 | } 77 | 78 | @Override 79 | public boolean isAccountNonLocked() { 80 | return true; 81 | } 82 | 83 | @Override 84 | public boolean isCredentialsNonExpired() { 85 | return true; 86 | } 87 | 88 | @Override 89 | public boolean isEnabled() { 90 | return true; 91 | } 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /module_uaa/src/main/java/com/fly/uaa/service/UserServiceDetail.java: -------------------------------------------------------------------------------- 1 | package com.fly.uaa.service; 2 | 3 | 4 | import com.fly.uaa.dao.UserDao; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.stereotype.Service; 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @Service 18 | public class UserServiceDetail implements UserDetailsService { 19 | 20 | @Autowired 21 | private UserDao userRepository; 22 | @Override 23 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 24 | return userRepository.findByUsername(username); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /module_uaa/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: uaa-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | management: 11 | security: 12 | enabled: false 13 | -------------------------------------------------------------------------------- /module_uaa/src/main/resources/fly-jwt.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mxdldev/spring-cloud-flycloud/d5507da91c146661ffdd395d3d15d25ad351a5a2/module_uaa/src/main/resources/fly-jwt.jks -------------------------------------------------------------------------------- /module_uaa/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /module_user/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':lib_common') 3 | } 4 | jar { 5 | manifest { 6 | attributes 'Main-Class': 'com.fly.user.UserServiceApplication' 7 | } 8 | } -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/UserServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.user; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.netflix.hystrix.EnableHystrix; 7 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * Description:
12 | * Author:    mxdl
13 | * Date:     2019/2/19
14 | * Version:   V1.0.0
15 | * Update:    
16 | */ 17 | @SpringBootApplication 18 | @EnableEurekaClient 19 | @EnableFeignClients 20 | @EnableHystrixDashboard 21 | @EnableHystrix 22 | public class UserServiceApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(UserServiceApplication.class, args); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/aop/SysLoggerAspect.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.aop; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.common.annotation.SysLogger; 5 | import com.fly.user.util.HttpUtils; 6 | import com.fly.user.util.UserUtils; 7 | import com.fly.user.entity.SysLog; 8 | import com.fly.user.service.LoggerService; 9 | import org.apache.commons.lang.StringUtils; 10 | import org.aspectj.lang.JoinPoint; 11 | import org.aspectj.lang.annotation.Aspect; 12 | import org.aspectj.lang.annotation.Before; 13 | import org.aspectj.lang.annotation.Pointcut; 14 | import org.aspectj.lang.reflect.MethodSignature; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.stereotype.Component; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | import java.lang.reflect.Method; 20 | import java.util.Date; 21 | 22 | /** 23 | * Description:
24 | * Author:    mxdl
25 | * Date:     2019/2/19
26 | * Version:   V1.0.0
27 | * Update:    
28 | */ 29 | @Aspect 30 | @Component 31 | public class SysLoggerAspect { 32 | @Autowired 33 | private LoggerService loggerService; 34 | 35 | @Pointcut("@annotation(com.fly.common.annotation.SysLogger)") 36 | public void loggerPointCut() { 37 | 38 | } 39 | 40 | @Before("loggerPointCut()") 41 | public void saveSysLog(JoinPoint joinPoint) { 42 | System.out.println("MYTAG:User SysLoggerAspect saveLogger start..."); 43 | MethodSignature signature = (MethodSignature) joinPoint.getSignature(); 44 | Method method = signature.getMethod(); 45 | 46 | SysLog sysLog = new SysLog(); 47 | SysLogger sysLogger = method.getAnnotation(SysLogger.class); 48 | if(sysLogger != null){ 49 | //注解上的描述 50 | sysLog.setOperation(sysLogger.value()); 51 | } 52 | //请求的方法名 53 | String className = joinPoint.getTarget().getClass().getName(); 54 | String methodName = signature.getName(); 55 | sysLog.setMethod(className + "." + methodName + "()"); 56 | //请求的参数 57 | Object[] args = joinPoint.getArgs(); 58 | String params=""; 59 | 60 | for(Object o:args){ 61 | params+= JSON.toJSONString(o); 62 | } 63 | if(!StringUtils.isEmpty(params)) { 64 | sysLog.setParams(params); 65 | } 66 | //设置IP地址 67 | sysLog.setIp(HttpUtils.getIpAddress()); 68 | //用户名 69 | String username = UserUtils.getCurrentPrinciple(); 70 | if(!StringUtils.isEmpty(username)) { 71 | sysLog.setUsername(username); 72 | } 73 | sysLog.setCreateDate(new Date()); 74 | //保存系统日志 75 | loggerService.log(sysLog); 76 | } 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/client/AuthServiceClient.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.client; 2 | 3 | import com.fly.user.client.hystrix.AuthServiceHystrix; 4 | import com.fly.user.entity.JWT; 5 | import org.springframework.cloud.openfeign.FeignClient; 6 | import org.springframework.web.bind.annotation.*; 7 | 8 | 9 | /** 10 | * Description:
11 | * Author:    mxdl
12 | * Date:     2019/2/19
13 | * Version:   V1.0.0
14 | * Update:    
15 | */ 16 | @FeignClient(value = "uaa-service",fallback = AuthServiceHystrix.class ) 17 | public interface AuthServiceClient { 18 | 19 | @PostMapping(value = "/oauth/token") 20 | JWT getToken(@RequestHeader(value = "Authorization") String authorization, @RequestParam("grant_type") String type, 21 | @RequestParam("username") String username, @RequestParam("password") String password); 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/client/hystrix/AuthServiceHystrix.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.client.hystrix; 2 | 3 | 4 | import com.fly.user.client.AuthServiceClient; 5 | import com.fly.user.entity.JWT; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * Description:
10 | * Author:    mxdl
11 | * Date:     2019/2/19
12 | * Version:   V1.0.0
13 | * Update:    
14 | */ 15 | @Component 16 | public class AuthServiceHystrix implements AuthServiceClient { 17 | @Override 18 | public JWT getToken(String authorization, String type, String username, String password) { 19 | System.out.println("--------opps getToken hystrix---------"); 20 | return null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/config/GlobalMethodSecurityConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @Configuration 14 | @EnableGlobalMethodSecurity(prePostEnabled = true) 15 | public class GlobalMethodSecurityConfiguration { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/config/JwtConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.config; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Qualifier; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.io.ClassPathResource; 8 | import org.springframework.core.io.Resource; 9 | import org.springframework.security.oauth2.provider.token.TokenStore; 10 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 11 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 12 | import org.springframework.util.FileCopyUtils; 13 | 14 | import java.io.IOException; 15 | 16 | /** 17 | * Description:
18 | * Author:    mxdl
19 | * Date:     2019/2/19
20 | * Version:   V1.0.0
21 | * Update:    
22 | */ 23 | @Configuration 24 | public class JwtConfiguration { 25 | @Autowired 26 | JwtAccessTokenConverter jwtAccessTokenConverter; 27 | 28 | @Bean 29 | @Qualifier("tokenStore") 30 | public TokenStore tokenStore() { 31 | 32 | System.out.println("Created JwtTokenStore"); 33 | return new JwtTokenStore(jwtAccessTokenConverter); 34 | } 35 | 36 | @Bean 37 | protected JwtAccessTokenConverter jwtTokenEnhancer() { 38 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 39 | Resource resource = new ClassPathResource("public.cert"); 40 | String publicKey ; 41 | try { 42 | publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream())); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | converter.setVerifierKey(publicKey); 47 | return converter; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/config/RabbitConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.config; 2 | 3 | 4 | import org.springframework.amqp.core.Binding; 5 | import org.springframework.amqp.core.BindingBuilder; 6 | import org.springframework.amqp.core.Queue; 7 | import org.springframework.amqp.core.TopicExchange; 8 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; 9 | import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; 10 | import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; 11 | import org.springframework.context.annotation.Bean; 12 | import org.springframework.context.annotation.Configuration; 13 | 14 | /** 15 | * Description:
16 | * Author:    mxdl
17 | * Date:     2019/2/19
18 | * Version:   V1.0.0
19 | * Update:    
20 | */ 21 | @Configuration 22 | public class RabbitConfig { 23 | 24 | 25 | public final static String queueName = "spring-boot"; 26 | 27 | @Bean 28 | Queue queue() { 29 | return new Queue(queueName, false); 30 | } 31 | 32 | @Bean 33 | TopicExchange exchange() { 34 | return new TopicExchange("spring-boot-exchange"); 35 | } 36 | 37 | @Bean 38 | Binding binding(Queue queue, TopicExchange exchange) { 39 | return BindingBuilder.bind(queue).to(exchange).with(queueName); 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/config/ResourceServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.config; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 9 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; 10 | import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer; 11 | import org.springframework.security.oauth2.provider.token.TokenStore; 12 | 13 | /** 14 | * Description:
15 | * Author:    mxdl
16 | * Date:     2019/2/19
17 | * Version:   V1.0.0
18 | * Update:    
19 | */ 20 | @Configuration 21 | @EnableResourceServer 22 | public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter{ 23 | Logger log = LoggerFactory.getLogger(ResourceServerConfiguration.class); 24 | 25 | @Override 26 | public void configure(HttpSecurity http) throws Exception { 27 | http 28 | .csrf().disable() 29 | .authorizeRequests() 30 | .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/hi.*","/user/login.*","/user/registry.*","/user/test.*").permitAll() 31 | .antMatchers("/**").authenticated(); 32 | // .antMatchers("/**").permitAll(); 33 | } 34 | 35 | 36 | @Override 37 | public void configure(ResourceServerSecurityConfigurer resources) throws Exception { 38 | log.info("Configuring ResourceServerSecurityConfigurer "); 39 | resources.resourceId("user-service").tokenStore(tokenStore); 40 | } 41 | 42 | @Autowired 43 | TokenStore tokenStore; 44 | } 45 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.config; 2 | 3 | 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.ParameterBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.schema.ModelRef; 11 | import springfox.documentation.service.ApiInfo; 12 | import springfox.documentation.service.Parameter; 13 | import springfox.documentation.spi.DocumentationType; 14 | import springfox.documentation.spring.web.plugins.Docket; 15 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | 21 | /** 22 | * Description:
23 | * Author:    mxdl
24 | * Date:     2019/2/19
25 | * Version:   V1.0.0
26 | * Update:    
27 | */ 28 | @Configuration 29 | @EnableSwagger2 30 | public class SwaggerConfig { 31 | /** 32 | * 全局参数 33 | * 34 | * @return 35 | */ 36 | private List parameter() { 37 | List params = new ArrayList<>(); 38 | params.add(new ParameterBuilder().name("Authorization") 39 | .description("Authorization Bearer token") 40 | .modelRef(new ModelRef("string")) 41 | .parameterType("header") 42 | .required(false).build()); 43 | return params; 44 | } 45 | 46 | 47 | @Bean 48 | public Docket sysApi() { 49 | return new Docket(DocumentationType.SWAGGER_2) 50 | .apiInfo(apiInfo()) 51 | .select() 52 | .apis(RequestHandlerSelectors.basePackage("com.fly")) 53 | .paths(PathSelectors.any()) 54 | .build().globalOperationParameters(parameter()); 55 | //.securitySchemes(newArrayList(oauth())) 56 | // .securityContexts(newArrayList(securityContext())); 57 | } 58 | 59 | private ApiInfo apiInfo() { 60 | return new ApiInfoBuilder() 61 | .title(" user-service api ") 62 | .description("user-service 微服务") 63 | .termsOfServiceUrl("") 64 | .contact("fly") 65 | .version("1.0") 66 | .build(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.dao; 2 | 3 | 4 | import com.fly.user.entity.User; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | 15 | public interface UserDao extends JpaRepository { 16 | 17 | User findByUsername(String username); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/dto/LoginDTO.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.dto; 2 | 3 | import com.fly.user.entity.User; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | public class LoginDTO { 13 | private User user; 14 | private String token; 15 | 16 | public User getUser() { 17 | return user; 18 | } 19 | 20 | public void setUser(User user) { 21 | this.user = user; 22 | } 23 | 24 | public String getToken() { 25 | return token; 26 | } 27 | 28 | public void setToken(String token) { 29 | this.token = token; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/entity/JWT.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.entity; 2 | 3 | /** 4 | * Description:
5 | * Author:    mxdl
6 | * Date:     2019/2/19
7 | * Version:   V1.0.0
8 | * Update:    
9 | */ 10 | public class JWT { 11 | private String access_token; 12 | private String token_type; 13 | private String refresh_token; 14 | private int expires_in; 15 | private String scope; 16 | private String jti; 17 | 18 | public String getAccess_token() { 19 | return access_token; 20 | } 21 | 22 | public void setAccess_token(String access_token) { 23 | this.access_token = access_token; 24 | } 25 | 26 | public String getToken_type() { 27 | return token_type; 28 | } 29 | 30 | public void setToken_type(String token_type) { 31 | this.token_type = token_type; 32 | } 33 | 34 | public String getRefresh_token() { 35 | return refresh_token; 36 | } 37 | 38 | public void setRefresh_token(String refresh_token) { 39 | this.refresh_token = refresh_token; 40 | } 41 | 42 | public int getExpires_in() { 43 | return expires_in; 44 | } 45 | 46 | public void setExpires_in(int expires_in) { 47 | this.expires_in = expires_in; 48 | } 49 | 50 | public String getScope() { 51 | return scope; 52 | } 53 | 54 | public void setScope(String scope) { 55 | this.scope = scope; 56 | } 57 | 58 | public String getJti() { 59 | return jti; 60 | } 61 | 62 | public void setJti(String jti) { 63 | this.jti = jti; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "JWT{" + 69 | "access_token='" + access_token + '\'' + 70 | ", token_type='" + token_type + '\'' + 71 | ", refresh_token='" + refresh_token + '\'' + 72 | ", expires_in=" + expires_in + 73 | ", scope='" + scope + '\'' + 74 | ", jti='" + jti + '\'' + 75 | '}'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/entity/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.entity; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | public class SysLog { 13 | 14 | private Long id; 15 | //用户名 16 | private String username; 17 | //用户操作 18 | private String operation; 19 | //请求方法 20 | private String method; 21 | //请求参数 22 | private String params; 23 | //IP地址 24 | private String ip; 25 | //创建时间 26 | private Date createDate; 27 | 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | 37 | public String getUsername() { 38 | return username; 39 | } 40 | 41 | public void setUsername(String username) { 42 | this.username = username; 43 | } 44 | 45 | public String getOperation() { 46 | return operation; 47 | } 48 | 49 | public void setOperation(String operation) { 50 | this.operation = operation; 51 | } 52 | 53 | public String getMethod() { 54 | return method; 55 | } 56 | 57 | public void setMethod(String method) { 58 | this.method = method; 59 | } 60 | 61 | public String getParams() { 62 | return params; 63 | } 64 | 65 | public void setParams(String params) { 66 | this.params = params; 67 | } 68 | 69 | public String getIp() { 70 | return ip; 71 | } 72 | 73 | public void setIp(String ip) { 74 | this.ip = ip; 75 | } 76 | 77 | public Date getCreateDate() { 78 | return createDate; 79 | } 80 | 81 | public void setCreateDate(Date createDate) { 82 | this.createDate = createDate; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.entity; 2 | 3 | import javax.persistence.*; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * Description:
8 | * Author:    mxdl
9 | * Date:     2019/2/19
10 | * Version:   V1.0.0
11 | * Update:    
12 | */ 13 | @Entity 14 | public class User implements Serializable { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | 19 | @Column(nullable = false, unique = true) 20 | private String username; 21 | 22 | @Column 23 | private String password; 24 | public User() { 25 | } 26 | 27 | public Long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getUsername() { 36 | return username; 37 | } 38 | 39 | public void setUsername(String username) { 40 | this.username = username; 41 | } 42 | 43 | public String getPassword() { 44 | return password; 45 | } 46 | 47 | public void setPassword(String password) { 48 | this.password = password; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/exception/CommonExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.exception; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.common.exception.CommonException; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.ControllerAdvice; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.ResponseBody; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @ControllerAdvice 19 | @ResponseBody 20 | public class CommonExceptionHandler { 21 | 22 | @ExceptionHandler(CommonException.class) 23 | public ResponseEntity handleException(Exception e) { 24 | RespDTO resp = new RespDTO(); 25 | CommonException taiChiException = (CommonException) e; 26 | resp.code = taiChiException.getCode(); 27 | resp.error = e.getMessage(); 28 | 29 | return new ResponseEntity(resp, HttpStatus.OK); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/service/LoggerService.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.service; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.fly.user.entity.SysLog; 5 | import com.fly.user.config.RabbitConfig; 6 | import org.springframework.amqp.core.AmqpTemplate; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | 11 | /** 12 | * Description:
13 | * Author:    mxdl
14 | * Date:     2019/2/19
15 | * Version:   V1.0.0
16 | * Update:    
17 | */ 18 | @Service 19 | public class LoggerService { 20 | 21 | @Autowired 22 | private AmqpTemplate rabbitTemplate; 23 | 24 | public void log(SysLog sysLog){ 25 | System.out.println("MYTAG:User LoggerService log start..."); 26 | rabbitTemplate.convertAndSend(RabbitConfig.queueName, JSON.toJSONString(sysLog)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.service; 2 | 3 | import com.fly.common.dto.RespDTO; 4 | import com.fly.common.exception.CommonException; 5 | import com.fly.common.exception.ErrorCode; 6 | import com.fly.user.dao.UserDao; 7 | import com.fly.user.dto.LoginDTO; 8 | import com.fly.user.entity.JWT; 9 | import com.fly.user.entity.User; 10 | import com.fly.user.client.AuthServiceClient; 11 | import com.fly.user.util.BPwdEncoderUtils; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.beans.factory.annotation.Qualifier; 14 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices; 15 | import org.springframework.stereotype.Service; 16 | 17 | /** 18 | * Description:
19 | * Author:    mxdl
20 | * Date:     2019/2/19
21 | * Version:   V1.0.0
22 | * Update:    
23 | */ 24 | @Service 25 | public class UserService { 26 | 27 | @Autowired 28 | public 29 | UserDao userDao; 30 | @Autowired 31 | AuthServiceClient authServiceClient; 32 | 33 | public User createUser(User user) { 34 | return userDao.save(user); 35 | } 36 | 37 | public User getUserInfo(String username) { 38 | return userDao.findByUsername(username); 39 | } 40 | 41 | public RespDTO login(String username, String password) { 42 | User user = userDao.findByUsername(username); 43 | if (null == user) { 44 | throw new CommonException(ErrorCode.USER_NOT_FOUND); 45 | } 46 | if (!BPwdEncoderUtils.matches(password, user.getPassword())) { 47 | throw new CommonException(ErrorCode.USER_PASSWORD_ERROR); 48 | } 49 | JWT jwt = authServiceClient.getToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2", "password", username, password); 50 | 51 | if (null == jwt) { 52 | throw new CommonException(ErrorCode.GET_TOKEN_FAIL); 53 | } 54 | LoginDTO loginDTO = new LoginDTO(); 55 | loginDTO.setUser(user); 56 | loginDTO.setToken(jwt.getAccess_token()); 57 | return RespDTO.onSuc(loginDTO); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/util/BPwdEncoderUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.util; 2 | 3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 4 | 5 | /** 6 | * Description:
7 | * Author:    mxdl
8 | * Date:     2019/2/19
9 | * Version:   V1.0.0
10 | * Update:    
11 | */ 12 | public class BPwdEncoderUtils { 13 | 14 | private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 15 | 16 | /** 17 | * 用BCryptPasswordEncoder 18 | * @param password 19 | * @return 20 | */ 21 | public static String BCryptPassword(String password){ 22 | return encoder.encode(password); 23 | } 24 | 25 | /** 26 | * 27 | * @param rawPassword 原始密码 28 | * @param encodedPassword 加密后的密码 29 | * @return 30 | */ 31 | public static boolean matches(CharSequence rawPassword, String encodedPassword){ 32 | return encoder.matches(rawPassword,encodedPassword); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.util; 2 | 3 | 4 | 5 | import org.springframework.web.context.request.RequestContextHolder; 6 | import org.springframework.web.context.request.ServletRequestAttributes; 7 | import javax.servlet.http.HttpServletRequest; 8 | import java.util.Enumeration; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * Description:
14 | * Author:    mxdl
15 | * Date:     2019/2/19
16 | * Version:   V1.0.0
17 | * Update:    
18 | */ 19 | public class HttpUtils { 20 | 21 | 22 | /** 23 | * 尝试获取当前请求的HttpServletRequest实例 24 | * 25 | * @return HttpServletRequest 26 | */ 27 | public static HttpServletRequest getHttpServletRequest() { 28 | try { 29 | return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 30 | } catch (Exception e) { 31 | return null; 32 | } 33 | } 34 | 35 | 36 | public static Map getHeaders(HttpServletRequest request) { 37 | Map map = new LinkedHashMap<>(); 38 | Enumeration enumeration = request.getHeaderNames(); 39 | while (enumeration.hasMoreElements()) { 40 | String key = enumeration.nextElement(); 41 | String value = request.getHeader(key); 42 | map.put(key, value); 43 | } 44 | return map; 45 | } 46 | 47 | /** 48 | * 获取请求客户端的真实ip地址 49 | * 50 | * @param request 请求对象 51 | * @return ip地址 52 | */ 53 | public static String getIpAddress(HttpServletRequest request) { 54 | 55 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 56 | String ip = request.getHeader("X-Forwarded-For"); 57 | 58 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 59 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 60 | ip = request.getHeader("Proxy-Client-IP"); 61 | } 62 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 63 | ip = request.getHeader("WL-Proxy-Client-IP"); 64 | } 65 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 66 | ip = request.getHeader("HTTP_CLIENT_IP"); 67 | } 68 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 69 | ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 70 | } 71 | if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 72 | ip = request.getRemoteAddr(); 73 | } 74 | } else if (ip.length() > 15) { 75 | String[] ips = ip.split(","); 76 | for (int index = 0; index < ips.length; index++) { 77 | String strIp = (String) ips[index]; 78 | if (!("unknown".equalsIgnoreCase(strIp))) { 79 | ip = strIp; 80 | break; 81 | } 82 | } 83 | } 84 | return ip; 85 | } 86 | 87 | /** 88 | * 获取请求客户端的真实ip地址 89 | * 90 | * @param 91 | * @return ip地址 92 | */ 93 | public static String getIpAddress() { 94 | // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 95 | return getIpAddress(getHttpServletRequest()); 96 | } 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/util/UserUtils.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.util; 2 | 3 | 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | import java.util.List; 8 | 9 | /** 10 | * Description:
11 | * Author:    mxdl
12 | * Date:     2019/2/19
13 | * Version:   V1.0.0
14 | * Update:    
15 | */ 16 | public class UserUtils { 17 | 18 | private static final String AUTHORIZATION = "authorization"; 19 | 20 | /** 21 | * 获取当前请求的token 22 | * @return 23 | */ 24 | public static String getCurrentToken() { 25 | return HttpUtils.getHeaders(HttpUtils.getHttpServletRequest()).get(AUTHORIZATION); 26 | } 27 | 28 | /** 29 | * 获取当前请求的用户Id 30 | * @return 31 | */ 32 | public static String getCurrentPrinciple() { 33 | return (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 34 | } 35 | 36 | /** 37 | * 判读当前token用户是否为接口所需的参数username 38 | * 39 | * @param username 40 | * @return 41 | */ 42 | public static boolean isMyself(String username) { 43 | return username.equals(getCurrentPrinciple()); 44 | } 45 | 46 | /** 47 | * 获取当前请求Authentication 48 | * 49 | * @return 50 | */ 51 | public static Authentication getCurrentAuthentication() { 52 | return SecurityContextHolder.getContext().getAuthentication(); 53 | } 54 | 55 | /** 56 | * 获取当前请求的权限信息 57 | * @return 58 | */ 59 | public static List getCurrentAuthorities() { 60 | return (List) SecurityContextHolder.getContext().getAuthentication().getAuthorities(); 61 | } 62 | 63 | /** 64 | * @param role 65 | * @return 66 | */ 67 | public static boolean hasRole(String role) { 68 | if (!role.startsWith("ROLE_")) { 69 | role = "ROLE_" + role; 70 | } 71 | boolean hasRole = false; 72 | List list = getCurrentAuthorities(); 73 | for (SimpleGrantedAuthority s : list) { 74 | if (role.equals(s.getAuthority())) { 75 | hasRole = true; 76 | break; 77 | } 78 | } 79 | return hasRole; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /module_user/src/main/java/com/fly/user/web/UserController.java: -------------------------------------------------------------------------------- 1 | package com.fly.user.web; 2 | 3 | import com.fly.common.annotation.SysLogger; 4 | import com.fly.common.dto.RespDTO; 5 | import com.fly.user.entity.User; 6 | import com.fly.user.service.UserService; 7 | import com.fly.user.util.BPwdEncoderUtils; 8 | import io.swagger.annotations.ApiOperation; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.beans.factory.annotation.Value; 11 | import org.springframework.security.access.prepost.PreAuthorize; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | /** 15 | * Description:
16 | * Author:    mxdl
17 | * Date:     2019/2/19
18 | * Version:   V1.0.0
19 | * Update:    
20 | */ 21 | @RestController 22 | @RequestMapping("/user") 23 | public class UserController { 24 | 25 | @Autowired 26 | UserService userService; 27 | 28 | @ApiOperation(value = "注册", notes = "username和password为必选项") 29 | @PostMapping("/registry") 30 | @SysLogger("registry") 31 | public User createUser(@RequestBody User user){ 32 | //参数判读省略,判读该用户在数据库是否已经存在省略 33 | String entryPassword= BPwdEncoderUtils.BCryptPassword(user.getPassword()); 34 | user.setPassword(entryPassword); 35 | return userService.createUser(user); 36 | } 37 | 38 | @ApiOperation(value = "登录", notes = "username和password为必选项") 39 | @PostMapping("/login") 40 | @SysLogger("login") 41 | public RespDTO login(@RequestParam String username , @RequestParam String password){ 42 | //参数判读省略 43 | return userService.login(username,password); 44 | } 45 | 46 | @ApiOperation(value = "根据用户名获取用户", notes = "根据用户名获取用户") 47 | @PostMapping("/{username}") 48 | @PreAuthorize("hasRole('USER')") 49 | @SysLogger("getUserInfo") 50 | // @PreAuthorize("hasAnyAuthority('ROLE_USER')") 51 | public RespDTO getUserInfo(@PathVariable("username") String username){ 52 | //参数判读省略 53 | User user= userService.getUserInfo(username); 54 | return RespDTO.onSuc(user); 55 | } 56 | 57 | @Value("${server.port}") 58 | String port; 59 | @GetMapping("/hi") 60 | public String home(@RequestParam String name) { 61 | return "hi "+name+",i am from port:" +port; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /module_user/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: user-service 4 | cloud: 5 | config: 6 | uri: http://localhost:8769 7 | fail-fast: true 8 | profiles: 9 | active: pro 10 | -------------------------------------------------------------------------------- /module_user/src/main/resources/public.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3FtAe8QQmu3k/Jalrx24 3 | rKfOQ+vtji4kwu/wubWKN87BZDyv4tau3VJ1Ub9JpsEFMi0csoZmuUNEEWx+lNOf 4 | i9QWoKNQgQ8nUWkmqiVc1BvAsrBUkuvx1zDKHYkwZ4i45aRnDcBthsTaI4PbsweD 5 | YPhW3N06YBIkZVLLMmc+IHFX+Bnmd6DcWlFU/eAeM8/6TGUhR2BoSV0zBrPR85XW 6 | E0/ZVA8XdYOdf6RvAwms0NkAvEwjHV8O7x/7Uq4+i7+YK5vrZEzVUD2TVCgDpTbJ 7 | 55Qb5BKICtIbi5F2mI2DmQ7zwGAH1tFvDmVDS9ZQy+nfy8aQ5MJ+Lutmi0IjQdHX 8 | 5QIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /module_zipkin/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' 3 | compile 'org.springframework.boot:spring-boot-starter-web' 4 | compile 'org.springframework.cloud:spring-cloud-starter-config' 5 | compile ('io.zipkin.java:zipkin-server:2.11.7'){ 6 | exclude group: 'org.springframework.boot',module:'spring-boot-starter-log4j2' 7 | } 8 | compile 'io.zipkin.java:zipkin-autoconfigure-ui:2.11.7' 9 | } 10 | jar { 11 | manifest { 12 | attributes 'Main-Class': 'com.fly.zipkin.ZipkinServiceApplication' 13 | } 14 | } -------------------------------------------------------------------------------- /module_zipkin/src/main/java/com/fly/zipkin/ZipkinServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.fly.zipkin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import zipkin.server.EnableZipkinServer; 7 | /** 8 | * Description:
9 | * Author:    mxdl
10 | * Date:     2019/2/19
11 | * Version:   V1.0.0
12 | * Update:    
13 | */ 14 | @SpringBootApplication 15 | @EnableZipkinServer 16 | @EnableEurekaClient 17 | public class ZipkinServiceApplication { 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ZipkinServiceApplication.class, args); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /module_zipkin/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | 2 | spring: 3 | application: 4 | name: zipkin-service 5 | cloud: 6 | config: 7 | uri: http://localhost:8769 8 | fail-fast: true 9 | profiles: 10 | active: pro 11 | 12 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'FlyCloud' 2 | include 'lib_common' 3 | include 'module_eureka' 4 | include 'module_config' 5 | include 'module_zipkin' 6 | include 'module_admin' 7 | include 'module_gateway' 8 | include 'module_monitor' 9 | include 'module_uaa' 10 | include 'module_log' 11 | include 'module_user' 12 | include 'module_blog' 13 | include 'module_news' 14 | 15 | -------------------------------------------------------------------------------- /sql/sys-blog.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | CREATE DATABASE `sys-blog` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 4 | 5 | use `sys-blog`; 6 | 7 | /* 8 | Navicat MySQL Data Transfer 9 | 10 | Source Server : SSSS 11 | Source Server Version : 50717 12 | Source Host : localhost:3306 13 | Source Database : sys_blog 14 | 15 | Target Server Type : MYSQL 16 | Target Server Version : 50717 17 | File Encoding : 65001 18 | 19 | */ 20 | 21 | SET FOREIGN_KEY_CHECKS=0; 22 | 23 | -- ---------------------------- 24 | -- Table structure for blog 25 | -- ---------------------------- 26 | DROP TABLE IF EXISTS `blog`; 27 | CREATE TABLE `blog` ( 28 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 29 | `suject` varchar(255) DEFAULT NULL, 30 | `title` varchar(255) DEFAULT NULL, 31 | `username` varchar(255) NOT NULL, 32 | PRIMARY KEY (`id`) 33 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 34 | 35 | INSERT INTO `blog` VALUES ('5', '今天天气真好', '一起出去玩啊', 'gxl'); 36 | 37 | -------------------------------------------------------------------------------- /sql/sys-log.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE DATABASE `sys-log` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 3 | 4 | use `sys-log`; 5 | 6 | /* 7 | Navicat MySQL Data Transfer 8 | 9 | Source Server : SSSS 10 | Source Server Version : 50717 11 | Source Host : localhost:3306 12 | Source Database : sys-log 13 | 14 | Target Server Type : MYSQL 15 | Target Server Version : 50717 16 | File Encoding : 65001 17 | 18 | */ 19 | 20 | SET FOREIGN_KEY_CHECKS=0; 21 | 22 | -- ---------------------------- 23 | -- Table structure for sys_log 24 | -- ---------------------------- 25 | DROP TABLE IF EXISTS `sys_log`; 26 | CREATE TABLE `sys_log` ( 27 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 28 | `create_date` datetime DEFAULT NULL, 29 | `ip` varchar(255) DEFAULT NULL, 30 | `method` varchar(255) DEFAULT NULL, 31 | `operation` varchar(255) DEFAULT NULL, 32 | `params` varchar(255) DEFAULT NULL, 33 | `username` varchar(255) DEFAULT NULL, 34 | PRIMARY KEY (`id`) 35 | ) ENGINE=InnoDB AUTO_INCREMENT=267 DEFAULT CHARSET=utf8; 36 | -------------------------------------------------------------------------------- /sql/sys-news.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE `sys-news` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; 2 | CREATE TABLE `news_detail` ( 3 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 4 | `typeid` int(11) DEFAULT NULL, 5 | `title` varchar(255) COLLATE utf8_bin DEFAULT NULL, 6 | `content` varchar(255) COLLATE utf8_bin DEFAULT NULL, 7 | `addtime` datetime DEFAULT NULL, 8 | PRIMARY KEY (`id`) 9 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; 10 | 11 | CREATE TABLE `news_type` ( 12 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 13 | `addtime` datetime NOT NULL, 14 | `typename` varchar(255) COLLATE utf8_bin NOT NULL, 15 | PRIMARY KEY (`id`) 16 | ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; 17 | 18 | -------------------------------------------------------------------------------- /sql/sys-news_news_detail.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) 2 | -- 3 | -- Host: localhost Database: sys-news 4 | -- ------------------------------------------------------ 5 | -- Server version 5.7.22-log 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `news_detail` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `news_detail`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `news_detail` ( 26 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 27 | `typeid` int(11) DEFAULT NULL, 28 | `title` varchar(255) COLLATE utf8_bin DEFAULT NULL, 29 | `content` text COLLATE utf8_bin, 30 | `addtime` datetime NOT NULL, 31 | PRIMARY KEY (`id`) 32 | ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; 33 | /*!40101 SET character_set_client = @saved_cs_client */; 34 | 35 | -- 36 | -- Dumping data for table `news_detail` 37 | -- 38 | 39 | LOCK TABLES `news_detail` WRITE; 40 | /*!40000 ALTER TABLE `news_detail` DISABLE KEYS */; 41 | INSERT INTO `news_detail` VALUES (1,0,'后移动互联网时代我的一些思考','这篇文章本来是写在年前的,题目太大不好下手,加之年后公司上了一个新项目一直很忙,酝酿了好长时间,一直拖到了现在,今天也终于发表了,后移动时代我的一些思考,新时代下,我们不能只顾低头拉车,更要懂得抬头看路。就在半个多月前的2月15号,在滴滴年度员工大会上程维亲自宣布裁员2000人,而2月19号京东也宣布裁员10%的副总裁级别的高管,而就在昨天3月8日下午,熊猫直播在官方微博上宣布将关闭服务器,证实了此前有关熊猫直播倒闭的传言,等等这些消息只表明一个问题,移动互联网寒冬真的来了。其实从从去年开始一直就有各种消息爆出移动互联网行业的不景气,一些小公司由于投资方的撤资,资金链断裂,而导致的裁员、倒闭的情况,出现的就更早了','2019-06-15 21:42:36'),(2,0,'SpringCloud微服务架构在移动后端开发中的应用与研究','年前我写了一篇文章:Android组件化方案最佳实践,主要介绍了Android客户端框架FlyTour的使用,工程的架构为组件化,模块编码架构为MVP,文章地址为:https://blog.csdn.net/geduo_83/article/details/86604852,有的网友说现在自己一个人在做一个Android的项目,自己不会后端开发,问现在有没有好点的后端开源的架子给推荐一下,就自己稍加修改就能上手用的那种,为此我在网上找了一圈儿,还真没发现有什么好的后端架子,也许是我还没有发现,能不能自己搭建一个通用的后台服务端的架子?我想也很有必要,记得《Android第一行代码》作者郭霖有一句很著名的话“当你在感叹,假如有这么一个东西就好了的时候,请注意,这是你的机会”,正式因为这句话,我决定自己搭建一套后端服务的架子,希望对有需要的同学有所帮助','2019-06-15 21:42:36'),(3,0,'浅谈单一结构体项目的组件化改造','浅谈单一结构体项目的组件化改造\",content:\"昨天晚上一年一度的315晚会又来了,今年虽然没有哪家大公司上榜,但是曝光了一些黑心小企业,我们平时用的塑料盆、塑料袋、孩子的塑料玩具有可能都是用医疗废弃物,如输液袋、输液管、一次性注射器、血袋等加工而成的,还有平日孩子们抢着买的辣条这种混合了十几中添加剂的垃圾食品的生产环境着实让人辣眼睛,我们无比惊叹这些企业为了金钱、利益没有一点道德底线,等待他们的将是法律的制裁。好了,我们言归正传,项目功能移植可以说在日常开发中很多时候都会遇到,把A项目中的几个功能移植到B项目当中,最近工作中就有这样一个需求,需要将公司的一个老项目的几个功能模块移植到新项目当中,一开始以为工作量不是很大,但是随着改造工作的深入,不得不改变原有的移植改造方案','2019-06-15 21:42:36'),(4,0,'开发杂谈:Android移动应用架构发展简史','好了,我们言归正传,我们在前面几篇文章谈到了一些项目架构的问题,年前写了一篇“Android组件化最佳实践”,年后写了一篇“浅谈单一结构体项目的组件化改造”,我们提到了单一结构项目里,结构混乱,层次不清,有些模块同一功能解决方案不统一、有了新需求只是在原有项目上不断的砌代码罢了。长此以往,整个项目就是铁板一块,为后期的项目维护和扩展造成了极大的困难。我们在软件开发的时候,在做一个项目之前,架构师做工作就是搭项目框架,这是一个前提工作,给整个项目制定开发标准,开发规范,如果没有规范,项目可以搞起来吗?当然可以,就是个开发人员各行其是,最后的结果就是,项目做完了,整个项目结构混乱,层次不清。反之,一旦形成自己的一套框架体系,就可以长期使用,甚至成为整个公司的一套开发标准,大大提高后期的项目开发效率,来了新项目就直接可以在新项目中使用,而把主要的精力放在业务功能的实现上','2019-06-15 21:42:36'),(5,0,'Android事件分发机制的探索与发现之View篇','关于Android事件传递机制的文章在前面也零零散散的写过两篇,当时也是时间有限,也没有过多的去完善匆匆就发出去了。因为Android事件分发机制是整个Android系统的难点也是重点,说它是难点是因为触摸事件的流转流程错综复杂,前一阵子在有个技术群里面很多人都说,事件分发这块自己也是学习了好多次,但是都是过一阵子,对事件的流转流程又忘了,记不住,学了又忘,忘了又学,出现这种情况就是对事件流转流程理解不深刻,对书上的流程图死记硬背导致的,有些书上甚至出现流程错误的问题,真是误人子弟。','2019-06-15 21:42:36'); 42 | /*!40000 ALTER TABLE `news_detail` ENABLE KEYS */; 43 | UNLOCK TABLES; 44 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 45 | 46 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 47 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 48 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 49 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 50 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 51 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 52 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 53 | 54 | -- Dump completed on 2019-06-23 23:14:00 55 | -------------------------------------------------------------------------------- /sql/sys-news_news_type.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) 2 | -- 3 | -- Host: localhost Database: sys-news 4 | -- ------------------------------------------------------ 5 | -- Server version 5.7.22-log 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `news_type` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `news_type`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `news_type` ( 26 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 27 | `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 28 | `typename` varchar(255) COLLATE utf8_bin NOT NULL, 29 | PRIMARY KEY (`id`) 30 | ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; 31 | /*!40101 SET character_set_client = @saved_cs_client */; 32 | 33 | -- 34 | -- Dumping data for table `news_type` 35 | -- 36 | 37 | LOCK TABLES `news_type` WRITE; 38 | /*!40000 ALTER TABLE `news_type` DISABLE KEYS */; 39 | INSERT INTO `news_type` VALUES (0,'2019-06-23 02:12:00','移动开发'),(1,'2019-06-23 02:12:00','大数据'),(2,'2019-06-23 02:12:00','人工智能'),(3,'2019-06-23 02:12:00','区块链'),(7,'2019-06-23 14:17:34','架构'); 40 | /*!40000 ALTER TABLE `news_type` ENABLE KEYS */; 41 | UNLOCK TABLES; 42 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 43 | 44 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 45 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 46 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 47 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 48 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 49 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 50 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 51 | 52 | -- Dump completed on 2019-06-23 23:14:01 53 | -------------------------------------------------------------------------------- /sql/sys-user.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE DATABASE `sys-user` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 3 | 4 | use `sys-user`; 5 | 6 | -- ---------------------------- 7 | -- Table structure for role 8 | -- ---------------------------- 9 | DROP TABLE IF EXISTS `role`; 10 | CREATE TABLE `role` ( 11 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 12 | `name` varchar(255) NOT NULL, 13 | PRIMARY KEY (`id`) 14 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 15 | 16 | -- ---------------------------- 17 | -- Table structure for user 18 | -- ---------------------------- 19 | DROP TABLE IF EXISTS `user`; 20 | CREATE TABLE `user` ( 21 | `id` bigint(20) NOT NULL AUTO_INCREMENT, 22 | `password` varchar(255) DEFAULT NULL, 23 | `username` varchar(255) NOT NULL, 24 | PRIMARY KEY (`id`), 25 | UNIQUE KEY `UK_sb8bbouer5wak8vyiiy4pf2bx` (`username`) 26 | ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; 27 | 28 | -- ---------------------------- 29 | -- Table structure for user_role 30 | -- ---------------------------- 31 | DROP TABLE IF EXISTS `user_role`; 32 | CREATE TABLE `user_role` ( 33 | `user_id` bigint(20) NOT NULL, 34 | `role_id` bigint(20) NOT NULL, 35 | KEY `FKa68196081fvovjhkek5m97n3y` (`role_id`), 36 | KEY `FK859n2jvi8ivhui0rl0esws6o` (`user_id`), 37 | CONSTRAINT `FK859n2jvi8ivhui0rl0esws6o` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`), 38 | CONSTRAINT `FKa68196081fvovjhkek5m97n3y` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`) 39 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 40 | 41 | 42 | INSERT INTO `user` VALUES ('1', '$2a$10$rlM./Q4dh5qXYmxFxUqkRetMPf6JewV/Hj/s4qBg/6U1.mzcue2oK', 'gxl'); 43 | 44 | 45 | INSERT INTO `role` VALUES ('1', 'ROLE_USER'); 46 | INSERT INTO `role` VALUES ('2', 'ROLE_ADMIN'); 47 | 48 | INSERT INTO `user_role` VALUES ('1', '1'); 49 | INSERT INTO `user_role` VALUES ('1', '2'); 50 | 51 | --------------------------------------------------------------------------------