├── apollo ├── .gitignore ├── apollo-build-scripts-master │ ├── .gitignore │ ├── Dockerfile │ ├── README.md │ ├── apollo-all-in-one.jar │ ├── client │ │ ├── META-INF │ │ │ └── app.properties │ │ ├── apollo-demo.jar │ │ └── log4j2.xml │ ├── demo.sh │ ├── docker-compose.yml │ ├── images │ │ ├── apollo-login.png │ │ ├── apollo-sample-home.png │ │ ├── sample-app-config.png │ │ ├── sample-app-modify-config.png │ │ ├── sample-app-release-config.png │ │ ├── sample-app-release-detail.png │ │ └── sample-app-submit-config.png │ ├── portal │ │ └── apollo-portal.conf │ ├── service │ │ └── apollo-service.conf │ └── sql │ │ ├── apolloconfigdb.sql │ │ └── apolloportaldb.sql ├── apollo-client │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── apollo │ │ │ │ └── apolloclient │ │ │ │ ├── ApolloClientApplication.java │ │ │ │ ├── JavaConfigBean.java │ │ │ │ ├── SampleRedisConfig.java │ │ │ │ └── User.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── apollo │ │ └── apolloclient │ │ └── ApolloClientApplicationTests.java └── pom.xml ├── mybatis ├── .gitignore ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── mybatis │ │ │ ├── MybatisApplication.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ ├── model │ │ │ └── User.java │ │ │ └── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ └── UserService.java │ └── resources │ │ ├── application.yml │ │ ├── generatorConfig.xml │ │ └── mapper │ │ └── UserMapper.xml │ └── test │ └── java │ └── priv │ └── simon │ └── mybatis │ └── MybatisApplicationTests.java ├── oauth2 ├── .idea │ ├── compiler.xml │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml ├── auth-server │ ├── .gitignore │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── oauth2 │ │ │ │ └── authresourceserver │ │ │ │ ├── AuthResourceServerApplication.java │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ ├── SecurityConfig.java │ │ │ │ └── TestEndpoints.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── oauth2 │ │ └── authresourceserver │ │ └── AuthResourceServerApplicationTests.java ├── oauth2.iml ├── pom.xml └── resource-server │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── resource │ │ │ └── resourceserver │ │ │ └── ResourceServerApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── priv │ └── simon │ └── resource │ └── resourceserver │ └── ResourceServerApplicationTests.java ├── oauth2_jwt ├── .gitignore ├── auth-server │ ├── .gitignore │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── oauth2 │ │ │ │ └── authresourceserver │ │ │ │ ├── AuthServerApplication.java │ │ │ │ ├── AuthorizationServerConfiguration.java │ │ │ │ ├── CustomTokenEnhancer.java │ │ │ │ ├── CustomerAccessTokenConverter.java │ │ │ │ └── SecurityConfig.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── mytest.jks │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── oauth2 │ │ └── authresourceserver │ │ └── AuthResourceServerApplicationTests.java └── resource-server │ ├── .gitignore │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── resource │ │ │ └── resourceserver │ │ │ ├── CustomerAccessTokenConverter.java │ │ │ ├── OAuth2ResourceServerConfig.java │ │ │ └── ResourceServerApplication.java │ └── resources │ │ ├── application.yml │ │ └── public.txt │ └── test │ └── java │ └── priv │ └── simon │ └── resource │ └── resourceserver │ └── ResourceServerApplicationTests.java ├── redis ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── springboot │ │ │ └── redis │ │ │ ├── RedisApplication.java │ │ │ ├── RedisConfig.java │ │ │ └── RedisUtils.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── priv │ └── simon │ └── springboot │ └── redis │ ├── RedisApplicationTests.java │ └── RedisUtilsTest.java ├── zipkin ├── chainmonitor │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── chainmonitor │ │ │ │ └── ChainmonitorApplication.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── chainmonitor │ │ └── ChainmonitorApplicationTests.java ├── consumer │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── consumer │ │ │ │ ├── ConsumerApplication.java │ │ │ │ ├── FeignService.java │ │ │ │ └── HelloController.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── consumer │ │ └── ConsumerApplicationTests.java ├── eureka │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── priv │ │ │ │ └── simon │ │ │ │ └── eureka │ │ │ │ └── EurekaApplication.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── priv │ │ └── simon │ │ └── eureka │ │ └── EurekaApplicationTests.java ├── pom.xml └── provider │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── provider │ │ │ ├── HelloController.java │ │ │ └── ProviderApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── priv │ └── simon │ └── provider │ └── ProviderApplicationTests.java └── zipkin_mysql ├── .gitignore ├── chainmonitor ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── chainmonitor │ │ │ └── ChainmonitorApplication.java │ └── resources │ │ ├── application.yml │ │ └── zipkin.sql │ └── test │ └── java │ └── priv │ └── simon │ └── chainmonitor │ └── ChainmonitorApplicationTests.java ├── consumer ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── consumer │ │ │ ├── ConsumerApplication.java │ │ │ ├── FeignService.java │ │ │ └── HelloController.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── priv │ └── simon │ └── consumer │ └── ConsumerApplicationTests.java ├── eureka ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── priv │ │ │ └── simon │ │ │ └── eureka │ │ │ └── EurekaApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── priv │ └── simon │ └── eureka │ └── EurekaApplicationTests.java ├── pom.xml └── provider ├── .gitignore ├── pom.xml └── src ├── main ├── java │ └── priv │ │ └── simon │ │ └── provider │ │ ├── HelloController.java │ │ └── ProviderApplication.java └── resources │ └── application.yml └── test └── java └── priv └── simon └── provider └── ProviderApplicationTests.java /apollo/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | .mvn 19 | mvnw 20 | mvnw.cmd 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /build/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .DS_Store 3 | application.pid 4 | 5 | # Mobile Tools for Java (J2ME) 6 | .mtj.tmp/ 7 | 8 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 9 | hs_err_pid* 10 | 11 | # Eclipse 12 | .classpath 13 | .project 14 | target 15 | .settings 16 | 17 | # Idea 18 | .idea 19 | *.iml 20 | 21 | # git 22 | *.orig 23 | 24 | # build related 25 | apollo-portal.jar 26 | apollo-service.jar 27 | *.log 28 | *.pid 29 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/Dockerfile: -------------------------------------------------------------------------------- 1 | # Dockerfile for apollo quick start 2 | # Build with: 3 | # docker build -t apollo-quick-start . 4 | # Run with: 5 | # docker-compose up 6 | 7 | FROM openjdk:8-jre-alpine 8 | MAINTAINER nobodyiam 9 | 10 | COPY apollo-all-in-one.jar /apollo-quick-start/apollo-all-in-one.jar 11 | COPY client /apollo-quick-start/client 12 | COPY demo.sh /apollo-quick-start/demo.sh 13 | COPY portal/apollo-portal.conf /apollo-quick-start/portal/apollo-portal.conf 14 | COPY service/apollo-service.conf /apollo-quick-start/service/apollo-service.conf 15 | 16 | EXPOSE 8070 8080 17 | 18 | RUN echo "http://mirrors.aliyun.com/alpine/v3.6/main" > /etc/apk/repositories \ 19 | && echo "http://mirrors.aliyun.com/alpine/v3.6/community" >> /etc/apk/repositories \ 20 | && apk update upgrade \ 21 | && apk add --no-cache curl bash \ 22 | && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ 23 | && echo "Asia/Shanghai" > /etc/timezone \ 24 | && sed -i'.bak' '/db_url/s/localhost/apollo-db/g' /apollo-quick-start/demo.sh \ 25 | && sed -i "s/exit 0;/tail -f \/dev\/null/g" /apollo-quick-start/demo.sh 26 | 27 | CMD ["/apollo-quick-start/demo.sh", "start"] 28 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/README.md: -------------------------------------------------------------------------------- 1 | * [一、准备工作](#%E4%B8%80%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C) 2 | * [二、安装步骤](#%E4%BA%8C%E5%AE%89%E8%A3%85%E6%AD%A5%E9%AA%A4) 3 | * [三、启动Apollo配置中心](#%E4%B8%89%E5%90%AF%E5%8A%A8apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83) 4 | * [四、使用Apollo配置中心](#%E5%9B%9B%E4%BD%BF%E7%94%A8apollo%E9%85%8D%E7%BD%AE%E4%B8%AD%E5%BF%83) 5 | 6 | 为了让大家更快的上手了解Apollo配置中心,我们这里准备了一个Quick Start,能够在几分钟内在本地环境部署、启动Apollo配置中心。 7 | 8 | 考虑到Docker的便捷性,我们还提供了Quick Start的Docker版本,如果你对Docker比较熟悉的话,可以参考[Apollo Quick Start Docker部署](https://github.com/ctripcorp/apollo/wiki/Apollo-Quick-Start-Docker%E9%83%A8%E7%BD%B2)通过Docker快速部署Apollo。 9 | 10 | 不过这里需要注意的是,Quick Start只针对本地测试使用,如果要部署到生产环境,还请另行参考[分布式部署指南](https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)。 11 | 12 | > 注:Quick Start需要有bash环境,Windows用户建议安装[Git Bash](https://git-for-windows.github.io/),或者也可以直接通过IDE环境启动,详见[Apollo开发指南](https://github.com/ctripcorp/apollo/wiki/Apollo%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97)。 13 | 14 | # 一、准备工作 15 | ## 1.1 Java 16 | 17 | * Apollo服务端:1.8+ 18 | * Apollo客户端:1.7+ 19 | 20 | 由于Quick Start会在本地同时启动服务端和客户端,所以需要在本地安装Java 1.8+。 21 | 22 | 在配置好后,可以通过如下命令检查: 23 | ```sh 24 | java -version 25 | ``` 26 | 27 | 样例输出: 28 | ```sh 29 | java version "1.8.0_74" 30 | Java(TM) SE Runtime Environment (build 1.8.0_74-b02) 31 | Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode) 32 | ``` 33 | 34 | ## 1.2 MySQL 35 | 36 | * 版本要求:5.6.5+ 37 | 38 | Apollo的表结构对`timestamp`使用了多个default声明,所以需要5.6.5以上版本。 39 | 40 | 连接上MySQL后,可以通过如下命令检查: 41 | ```sql 42 | SHOW VARIABLES WHERE Variable_name = 'version'; 43 | ``` 44 | 45 | | Variable_name | Value | 46 | |---------------|--------| 47 | | version | 5.7.11 | 48 | 49 | ## 1.3 下载Quick Start安装包 50 | 我们准备好了一个Quick Start安装包,大家只需要下载到本地,就可以直接使用,免去了编译、打包过程。 51 | 52 | 安装包共50M,如果访问github网速不给力的话,可以从百度网盘下载。 53 | 54 | 1. 从Github下载 55 | * checkout或下载[apollo-build-scripts项目](https://github.com/nobodyiam/apollo-build-scripts) 56 | * **由于Quick Start项目比较大,所以放在了另外的repository,请注意项目地址** 57 | * https://github.com/nobodyiam/apollo-build-scripts 58 | 2. 从百度网盘下载 59 | * 通过[网盘链接](https://pan.baidu.com/s/187W86LoeVuv3DMrOJhcg1A)下载 60 | * 下载到本地后,在本地解压apollo-quick-start.zip 61 | 3. 为啥安装包要50M这么大? 62 | * 因为这是一个可以自启动的jar包,里面包含了所有依赖jar包以及一个内置的tomcat容器 63 | 64 | # 二、安装步骤 65 | ## 2.1 创建数据库 66 | Apollo服务端共需要两个数据库:`ApolloPortalDB`和`ApolloConfigDB`,我们把数据库、表的创建和样例数据都分别准备了sql文件,只需要导入数据库即可。 67 | 68 | > 注意:如果你本地已经创建过Apollo数据库,请注意备份数据。我们准备的sql文件会清空Apollo相关的表。 69 | 70 | ### 2.1.1 创建ApolloPortalDB 71 | 通过各种MySQL客户端导入[sql/apolloportaldb.sql](https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloportaldb.sql)即可。 72 | 73 | 下面以MySQL原生客户端为例: 74 | ```sql 75 | source /your_local_path/sql/apolloportaldb.sql 76 | ``` 77 | 78 | 导入成功后,可以通过执行以下sql语句来验证: 79 | ```sql 80 | select `Id`, `AppId`, `Name` from ApolloPortalDB.App; 81 | ``` 82 | 83 | | Id | AppId | Name | 84 | |----|-----------|------------| 85 | | 1 | SampleApp | Sample App | 86 | 87 | ### 2.1.2 创建ApolloConfigDB 88 | 通过各种MySQL客户端导入[sql/apolloconfigdb.sql](https://github.com/nobodyiam/apollo-build-scripts/blob/master/sql/apolloconfigdb.sql)即可。 89 | 90 | 下面以MySQL原生客户端为例: 91 | ```sql 92 | source /your_local_path/sql/apolloconfigdb.sql 93 | ``` 94 | 95 | 导入成功后,可以通过执行以下sql语句来验证: 96 | ```sql 97 | select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item; 98 | ``` 99 | | NamespaceId | Key | Value | Comment | 100 | |-------------|---------|-------|--------------------| 101 | | 1 | timeout | 100 | sample timeout配置 | 102 | 103 | ## 2.2 配置数据库连接信息 104 | Apollo服务端需要知道如何连接到你前面创建的数据库,所以需要编辑[demo.sh](https://github.com/nobodyiam/apollo-build-scripts/blob/master/demo.sh),修改ApolloPortalDB和ApolloConfigDB相关的数据库连接串信息。 105 | 106 | > 注意:填入的用户需要具备对ApolloPortalDB和ApolloConfigDB数据的读写权限。 107 | 108 | ```sh 109 | #apollo config db info 110 | apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 111 | apollo_config_db_username=用户名 112 | apollo_config_db_password=密码(如果没有密码,留空即可) 113 | 114 | # apollo portal db info 115 | apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 116 | apollo_portal_db_username=用户名 117 | apollo_portal_db_password=密码(如果没有密码,留空即可) 118 | ``` 119 | 120 | > 注意:不要修改demo.sh的其它部分 121 | 122 | # 三、启动Apollo配置中心 123 | ## 3.1 确保端口未被占用 124 | Quick Start脚本会在本地启动3个服务,分别使用8070, 8080, 8090端口,请确保这3个端口当前没有被使用。 125 | 126 | 例如,在Linux/Mac下,可以通过如下命令检查: 127 | ```sh 128 | lsof -i:8080 129 | ``` 130 | 131 | ## 3.2 执行启动脚本 132 | ```sh 133 | ./demo.sh start 134 | ``` 135 | 136 | 当看到如下输出后,就说明启动成功了! 137 | ```sh 138 | ==== starting service ==== 139 | Service logging file is ./service/apollo-service.log 140 | Started [10768] 141 | Waiting for config service startup....... 142 | Config service started. You may visit http://localhost:8080 for service status now! 143 | Waiting for admin service startup.... 144 | Admin service started 145 | ==== starting portal ==== 146 | Portal logging file is ./portal/apollo-portal.log 147 | Started [10846] 148 | Waiting for portal startup...... 149 | Portal started. You can visit http://localhost:8070 now! 150 | ``` 151 | 152 | ## 3.3 异常排查 153 | 如果启动遇到了异常,可以分别查看service和portal目录下的log文件排查问题。 154 | 155 | > 注:在启动apollo-configservice的过程中会在日志中输出eureka注册失败的信息,如`com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused`。需要注意的是,这个是预期的情况,因为apollo-configservice需要向Meta Server(它自己)注册服务,但是因为在启动过程中,自己还没起来,所以会报这个错。后面会进行重试的动作,所以等自己服务起来后就会注册正常了。 156 | 157 | ## 3.4 注意 158 | Quick Start只是用来帮助大家快速体验Apollo项目,具体实际使用时请参考:[分布式部署指南](https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97)。 159 | 160 | 另外需要注意的是Quick Start不支持增加环境,只有通过分布式部署才可以新增环境,同样请参考:[分布式部署指南](https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97) 161 | 162 | # 四、使用Apollo配置中心 163 | ## 4.1 使用样例项目 164 | 165 | ### 4.1.1 查看样例配置 166 | 1. 打开http://localhost:8070 167 | 168 | > Quick Start集成了[Spring Security简单认证](https://github.com/ctripcorp/apollo/wiki/Portal-%E5%AE%9E%E7%8E%B0%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD#%E5%AE%9E%E7%8E%B0%E6%96%B9%E5%BC%8F%E4%B8%80%E4%BD%BF%E7%94%A8apollo%E6%8F%90%E4%BE%9B%E7%9A%84spring-security%E7%AE%80%E5%8D%95%E8%AE%A4%E8%AF%81),更多信息可以参考[Portal 实现用户登录功能](https://github.com/ctripcorp/apollo/wiki/Portal-%E5%AE%9E%E7%8E%B0%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD) 169 | 170 | 登录 171 | 172 | 2. 输入用户名apollo,密码admin后登录 173 | 174 | ![首页](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/apollo-sample-home.png) 175 | 176 | 3. 点击SampleApp进入配置界面,可以看到当前有一个配置timeout=100 177 | ![配置界面](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/sample-app-config.png) 178 | 179 | > 如果提示`系统出错,请重试或联系系统负责人`,请稍后几秒钟重试一下,因为通过Eureka注册的服务有一个刷新的延时。 180 | 181 | ### 4.1.2 运行客户端程序 182 | 我们准备了一个简单的[Demo客户端](https://github.com/ctripcorp/apollo/blob/master/apollo-demo/src/main/java/com/ctrip/framework/apollo/demo/api/SimpleApolloConfigDemo.java)来演示从Apollo配置中心获取配置。 183 | 184 | 程序很简单,就是用户输入一个key的名字,程序会输出这个key对应的值。 185 | 186 | 如果没找到这个key,则输出undefined。 187 | 188 | 同时,客户端还会监听配置变化事件,一旦有变化就会输出变化的配置信息。 189 | 190 | 运行`./demo.sh client`启动Demo客户端,忽略前面的调试信息,可以看到如下提示: 191 | ```sh 192 | Apollo Config Demo. Please input key to get the value. Input quit to exit. 193 | > 194 | ``` 195 | 输入`timeout`,会看到如下信息: 196 | ```sh 197 | > timeout 198 | > [SimpleApolloConfigDemo] Loading key : timeout with value: 100 199 | ``` 200 | 201 | > 如果运行客户端遇到问题,可以通过修改`client/log4j2.xml`中的level为DEBUG来查看更详细日志信息 202 | > ```xml 203 | > 204 | > 205 | > 206 | > ``` 207 | 208 | ### 4.1.3 修改配置并发布 209 | 210 | 1. 在配置界面点击timeout这一项的编辑按钮 211 | ![编辑配置](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/sample-app-modify-config.png) 212 | 213 | 2. 在弹出框中把值改成200并提交 214 | ![配置修改](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/sample-app-submit-config.png) 215 | 216 | 3. 点击发布按钮,并填写发布信息 217 | ![发布](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/sample-app-release-config.png) 218 | 219 | ![发布信息](https://github.com/nobodyiam/apollo-build-scripts/blob/master/images/sample-app-release-detail.png) 220 | 221 | ### 4.1.4 客户端查看修改后的值 222 | 如果客户端一直在运行的话,在配置发布后就会监听到配置变化,并输出修改的配置信息: 223 | ```sh 224 | [SimpleApolloConfigDemo] Changes for namespace application 225 | [SimpleApolloConfigDemo] Change - key: timeout, oldValue: 100, newValue: 200, changeType: MODIFIED 226 | ``` 227 | 228 | 再次输入`timeout`查看对应的值,会看到如下信息: 229 | ```sh 230 | > timeout 231 | > [SimpleApolloConfigDemo] Loading key : timeout with value: 200 232 | ``` 233 | 234 | ## 4.2 使用新的项目 235 | ### 4.2.1 应用接入Apollo 236 | 这部分可以参考[Java应用接入指南](https://github.com/ctripcorp/apollo/wiki/Java%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97) 237 | 238 | ### 4.2.2 运行客户端程序 239 | 由于使用了新的项目,所以客户端需要修改appId信息。 240 | 241 | 编辑`client/META-INF/app.properties`,修改app.id为你新创建的app id。 242 | ```properties 243 | app.id=你的appId 244 | ``` 245 | # 运行`./demo.sh client`启动Demo客户端即可。 -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/apollo-all-in-one.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/apollo-all-in-one.jar -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/client/META-INF/app.properties: -------------------------------------------------------------------------------- 1 | app.id=SampleApp 2 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/client/apollo-demo.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/client/apollo-demo.jar -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/client/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # apollo config db info 4 | apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 5 | apollo_config_db_username=root 6 | apollo_config_db_password=123456 7 | 8 | # apollo portal db info 9 | apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 10 | apollo_portal_db_username=root 11 | apollo_portal_db_password=123456 12 | 13 | # =============== Please do not modify the following content =============== # 14 | 15 | if [ "$(uname)" == "Darwin" ]; then 16 | windows="0" 17 | elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then 18 | windows="0" 19 | elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then 20 | windows="1" 21 | else 22 | windows="0" 23 | fi 24 | 25 | # meta server url 26 | config_server_url=http://localhost:8080 27 | admin_server_url=http://localhost:8090 28 | eureka_service_url=$config_server_url/eureka/ 29 | portal_url=http://localhost:8070 30 | 31 | # JAVA OPTS 32 | BASE_JAVA_OPTS="-Denv=dev" 33 | CLIENT_JAVA_OPTS="$BASE_JAVA_OPTS -Dapollo.meta=$config_server_url" 34 | SERVER_JAVA_OPTS="$BASE_JAVA_OPTS -Dspring.profiles.active=github -Deureka.service.url=$eureka_service_url" 35 | PORTAL_JAVA_OPTS="$BASE_JAVA_OPTS -Ddev_meta=$config_server_url -Dspring.profiles.active=github,auth -Dspring.resources.cache-period=86400" 36 | 37 | # executable 38 | JAR_FILE=apollo-all-in-one.jar 39 | SERVICE_DIR=./service 40 | SERVICE_JAR_NAME=apollo-service.jar 41 | SERVICE_JAR=$SERVICE_DIR/$SERVICE_JAR_NAME 42 | SERVICE_LOG=$SERVICE_DIR/apollo-service.log 43 | PORTAL_DIR=./portal 44 | PORTAL_JAR_NAME=apollo-portal.jar 45 | PORTAL_JAR=$PORTAL_DIR/$PORTAL_JAR_NAME 46 | PORTAL_LOG=$PORTAL_DIR/apollo-portal.log 47 | CLIENT_DIR=./client 48 | CLIENT_JAR=$CLIENT_DIR/apollo-demo.jar 49 | 50 | # go to script directory 51 | cd "${0%/*}" 52 | 53 | function checkJava { 54 | if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then 55 | if [ "$windows" == "1" ]; then 56 | tmp_java_home=`cygpath -sw "$JAVA_HOME"` 57 | export JAVA_HOME=`cygpath -u $tmp_java_home` 58 | echo "Windows new JAVA_HOME is: $JAVA_HOME" 59 | fi 60 | _java="$JAVA_HOME/bin/java" 61 | elif type -p java > /dev/null; then 62 | _java=java 63 | else 64 | echo "Could not find java executable, please check PATH and JAVA_HOME variables." 65 | exit 1 66 | fi 67 | 68 | if [[ "$_java" ]]; then 69 | version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}') 70 | if [[ "$version" < "1.8" ]]; then 71 | echo "Java version is $version, please make sure java 1.8+ is in the path" 72 | exit 1 73 | fi 74 | fi 75 | } 76 | 77 | function checkServerAlive { 78 | declare -i counter=0 79 | declare -i max_counter=24 # 24*5=120s 80 | declare -i total_time=0 81 | 82 | SERVER_URL="$1" 83 | 84 | until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --head $SERVER_URL | grep "Coyote")" != "" ]]; 85 | do 86 | printf "." 87 | counter+=1 88 | sleep 5 89 | done 90 | 91 | total_time=counter*5 92 | 93 | if [[ (( counter -ge max_counter )) ]]; 94 | then 95 | return $total_time 96 | fi 97 | 98 | return 0 99 | } 100 | 101 | checkJava 102 | 103 | if [ "$1" = "start" ] ; then 104 | echo "==== starting service ====" 105 | echo "Service logging file is $SERVICE_LOG" 106 | export JAVA_OPTS="$SERVER_JAVA_OPTS -Dlogging.file=./apollo-service.log -Dspring.datasource.url=$apollo_config_db_url -Dspring.datasource.username=$apollo_config_db_username -Dspring.datasource.password=$apollo_config_db_password" 107 | 108 | if [[ -f $SERVICE_JAR ]]; then 109 | rm -rf $SERVICE_JAR 110 | fi 111 | 112 | ln $JAR_FILE $SERVICE_JAR 113 | chmod a+x $SERVICE_JAR 114 | 115 | $SERVICE_JAR start --configservice --adminservice 116 | 117 | rc=$? 118 | if [[ $rc != 0 ]]; 119 | then 120 | echo "Failed to start service, return code: $rc. Please check $SERVICE_LOG for more information." 121 | exit $rc; 122 | fi 123 | 124 | printf "Waiting for config service startup" 125 | checkServerAlive $config_server_url 126 | 127 | rc=$? 128 | if [[ $rc != 0 ]]; 129 | then 130 | printf "\nConfig service failed to start in $rc seconds! Please check $SERVICE_LOG for more information.\n" 131 | exit 1; 132 | fi 133 | 134 | printf "\nConfig service started. You may visit $config_server_url for service status now!\n" 135 | 136 | printf "Waiting for admin service startup" 137 | checkServerAlive $admin_server_url 138 | 139 | rc=$? 140 | if [[ $rc != 0 ]]; 141 | then 142 | printf "\nAdmin service failed to start in $rc seconds! Please check $SERVICE_LOG for more information.\n" 143 | exit 1; 144 | fi 145 | 146 | printf "\nAdmin service started\n" 147 | 148 | echo "==== starting portal ====" 149 | echo "Portal logging file is $PORTAL_LOG" 150 | export JAVA_OPTS="$PORTAL_JAVA_OPTS -Dlogging.file=./apollo-portal.log -Dserver.port=8070 -Dspring.datasource.url=$apollo_portal_db_url -Dspring.datasource.username=$apollo_portal_db_username -Dspring.datasource.password=$apollo_portal_db_password" 151 | 152 | if [[ -f $PORTAL_JAR ]]; then 153 | rm -rf $PORTAL_JAR 154 | fi 155 | 156 | ln $JAR_FILE $PORTAL_JAR 157 | chmod a+x $PORTAL_JAR 158 | 159 | $PORTAL_JAR start --portal 160 | 161 | rc=$? 162 | if [[ $rc != 0 ]]; 163 | then 164 | echo "Failed to start portal, return code: $rc. Please check $PORTAL_LOG for more information." 165 | exit $rc; 166 | fi 167 | 168 | printf "Waiting for portal startup" 169 | checkServerAlive $portal_url 170 | 171 | rc=$? 172 | if [[ $rc != 0 ]]; 173 | then 174 | printf "\nPortal failed to start in $rc seconds! Please check $PORTAL_LOG for more information.\n" 175 | exit 1; 176 | fi 177 | 178 | printf "\nPortal started. You can visit $portal_url now!\n" 179 | 180 | exit 0; 181 | elif [ "$1" = "client" ] ; then 182 | if [ "$windows" == "1" ]; then 183 | java -classpath "$CLIENT_DIR;$CLIENT_JAR" $CLIENT_JAVA_OPTS com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo 184 | else 185 | java -classpath $CLIENT_DIR:$CLIENT_JAR $CLIENT_JAVA_OPTS com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo 186 | fi 187 | 188 | elif [ "$1" = "stop" ] ; then 189 | echo "==== stopping portal ====" 190 | cd $PORTAL_DIR 191 | ./$PORTAL_JAR_NAME stop 192 | 193 | cd .. 194 | 195 | echo "==== stopping service ====" 196 | cd $SERVICE_DIR 197 | ./$SERVICE_JAR_NAME stop 198 | 199 | else 200 | echo "Usage: demo.sh ( commands ... )" 201 | echo "commands:" 202 | echo " start start services and portal" 203 | echo " client start client demo program" 204 | echo " stop stop services and portal" 205 | exit 1 206 | fi 207 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | apollo-quick-start: 5 | image: apollo-quick-start 6 | container_name: apollo-quick-start 7 | depends_on: 8 | - apollo-db 9 | ports: 10 | - "8080:8080" 11 | - "8070:8070" 12 | links: 13 | - apollo-db 14 | 15 | apollo-db: 16 | image: mysql:5.7 17 | container_name: apollo-db 18 | environment: 19 | TZ: Asia/Shanghai 20 | MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' 21 | depends_on: 22 | - apollo-dbdata 23 | ports: 24 | - "13306:3306" 25 | volumes: 26 | - ./sql:/docker-entrypoint-initdb.d 27 | volumes_from: 28 | - apollo-dbdata 29 | 30 | apollo-dbdata: 31 | image: alpine:latest 32 | container_name: apollo-dbdata 33 | volumes: 34 | - /var/lib/mysql 35 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/apollo-login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/apollo-login.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/apollo-sample-home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/apollo-sample-home.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/sample-app-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/sample-app-config.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/sample-app-modify-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/sample-app-modify-config.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/sample-app-release-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/sample-app-release-config.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/sample-app-release-detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/sample-app-release-detail.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/images/sample-app-submit-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-build-scripts-master/images/sample-app-submit-config.png -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/portal/apollo-portal.conf: -------------------------------------------------------------------------------- 1 | MODE=service 2 | PID_FOLDER=. 3 | LOG_FOLDER=. 4 | -------------------------------------------------------------------------------- /apollo/apollo-build-scripts-master/service/apollo-service.conf: -------------------------------------------------------------------------------- 1 | MODE=service 2 | PID_FOLDER=. 3 | LOG_FOLDER=. 4 | -------------------------------------------------------------------------------- /apollo/apollo-client/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | .mvn 19 | mvnw 20 | mvnw.cmd 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /build/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ -------------------------------------------------------------------------------- /apollo/apollo-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.apollo 7 | apollo-client 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | apollo-client 12 | apollo客户端 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | com.ctrip.framework.apollo 34 | apollo-client 35 | 1.1.1 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /apollo/apollo-client/src/main/java/priv/simon/apollo/apolloclient/ApolloClientApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.apollo.apolloclient; 2 | 3 | import com.ctrip.framework.apollo.Config; 4 | import com.ctrip.framework.apollo.model.ConfigChangeEvent; 5 | import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; 6 | import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener; 7 | import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue; 8 | import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.beans.factory.annotation.Value; 11 | import org.springframework.boot.SpringApplication; 12 | import org.springframework.boot.autoconfigure.SpringBootApplication; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import javax.sql.rowset.spi.SyncResolver; 17 | import java.util.List; 18 | import java.util.Set; 19 | 20 | @EnableApolloConfig 21 | @SpringBootApplication 22 | @RestController 23 | public class ApolloClientApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(ApolloClientApplication.class, args); 27 | } 28 | 29 | //1.Java Config方式 30 | @Autowired 31 | JavaConfigBean javaConfigBean; 32 | 33 | @RequestMapping("/index1") 34 | public String hello1(){ 35 | return javaConfigBean.getTimeout()+""; 36 | } 37 | 38 | //2. ConfigurationProperties使用方式 39 | @Autowired 40 | SampleRedisConfig sampleRedisConfig; 41 | 42 | @RequestMapping("/index2") 43 | public String hello2(){ 44 | return sampleRedisConfig.getCommandTimeout()+"--"+sampleRedisConfig.getExpireSeconds(); 45 | } 46 | // 3. @ApolloConfig使用 47 | @ApolloConfig 48 | private Config config; 49 | 50 | @RequestMapping("/index3") 51 | public String hello3(){ 52 | Set propertyNames = config.getPropertyNames(); 53 | propertyNames.forEach(key -> { 54 | System.err.println(key+"="+config.getIntProperty(key,0)); 55 | }); 56 | return propertyNames.toString(); 57 | } 58 | 59 | @ApolloConfigChangeListener 60 | private void someOnChange(ConfigChangeEvent changeEvent) { 61 | //update injected value of batch if it is changed in Apollo 62 | if (changeEvent.isChanged("timeout")) { 63 | System.out.println(config.getIntProperty("timeout", 0)); 64 | } 65 | } 66 | //4. @ApolloJsonValue使用 67 | @ApolloJsonValue("${jsonBeanProperty:[]}") 68 | private List anotherJsonBeans; 69 | 70 | @RequestMapping("/index4") 71 | public void hello4(){ 72 | anotherJsonBeans.forEach(item -> { 73 | System.err.println(item.getUsername()+"--"+item.getPassword()); 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /apollo/apollo-client/src/main/java/priv/simon/apollo/apolloclient/JavaConfigBean.java: -------------------------------------------------------------------------------- 1 | package priv.simon.apollo.apolloclient; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * Java Config方式 8 | * 9 | * @author simon 10 | * @create 2018-11-02 15:00 11 | **/ 12 | @Configuration 13 | public class JavaConfigBean { 14 | @Value("${timeout:20}") 15 | private int timeout; 16 | 17 | public int getTimeout() { 18 | return timeout; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /apollo/apollo-client/src/main/java/priv/simon/apollo/apolloclient/SampleRedisConfig.java: -------------------------------------------------------------------------------- 1 | package priv.simon.apollo.apolloclient; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | /** 7 | * ConfigurationProperties使用方式 8 | * 9 | * @author simon 10 | * @create 2018-11-02 9:30 11 | **/ 12 | @Configuration 13 | @ConfigurationProperties(prefix = "redis.cache") 14 | public class SampleRedisConfig { 15 | private int expireSeconds; 16 | private int commandTimeout; 17 | 18 | public void setExpireSeconds(int expireSeconds) { 19 | this.expireSeconds = expireSeconds; 20 | } 21 | 22 | public void setCommandTimeout(int commandTimeout) { 23 | this.commandTimeout = commandTimeout; 24 | } 25 | 26 | public int getExpireSeconds() { 27 | return expireSeconds; 28 | } 29 | 30 | public int getCommandTimeout() { 31 | return commandTimeout; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /apollo/apollo-client/src/main/java/priv/simon/apollo/apolloclient/User.java: -------------------------------------------------------------------------------- 1 | package priv.simon.apollo.apolloclient; 2 | 3 | /** 4 | * 用户 5 | * 6 | * @author simon 7 | * @create 2018-11-02 16:41 8 | **/ 9 | public class User { 10 | private String username; 11 | private String password; 12 | 13 | public String getUsername() { 14 | return username; 15 | } 16 | 17 | public void setUsername(String username) { 18 | this.username = username; 19 | } 20 | 21 | public String getPassword() { 22 | return password; 23 | } 24 | 25 | public void setPassword(String password) { 26 | this.password = password; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /apollo/apollo-client/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/apollo/apollo-client/src/main/resources/application.properties -------------------------------------------------------------------------------- /apollo/apollo-client/src/test/java/priv/simon/apollo/apolloclient/ApolloClientApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.apollo.apolloclient; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApolloClientApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /apollo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.apollo 7 | apollo-client 8 | 0.0.1-SNAPSHOT 9 | 10 | apollo-client 11 | 12 | 13 | -------------------------------------------------------------------------------- /mybatis/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | .mvn 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /build/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ -------------------------------------------------------------------------------- /mybatis/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /mybatis/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /mybatis/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | mybatis 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | mybatis 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.0.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-jdbc 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-web 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 1.3.2 40 | 41 | 42 | 43 | com.alibaba 44 | druid-spring-boot-starter 45 | 1.1.10 46 | 47 | 48 | junit 49 | junit 50 | test 51 | 52 | 53 | 54 | com.github.pagehelper 55 | pagehelper-spring-boot-starter 56 | 1.2.10 57 | 58 | 59 | mysql 60 | mysql-connector-java 61 | runtime 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-starter-test 66 | test 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-maven-plugin 75 | 76 | 77 | org.mybatis.generator 78 | mybatis-generator-maven-plugin 79 | 1.3.5 80 | 81 | true 82 | true 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/MybatisApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan("priv.simon.mybatis.mapper") 9 | public class MybatisApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(MybatisApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.*; 5 | import priv.simon.mybatis.model.User; 6 | import priv.simon.mybatis.service.impl.UserService; 7 | 8 | /** 9 | * @author simon 10 | * @create 2018-11-19 12:29 11 | **/ 12 | @RestController 13 | public class UserController { 14 | @Autowired 15 | private UserService userService; 16 | 17 | @ResponseBody 18 | @PostMapping("/add") 19 | public int addUser(User user) { 20 | return userService.addUser(user); 21 | } 22 | 23 | @ResponseBody 24 | @GetMapping("/all") 25 | public Object findAllUser( 26 | @RequestParam(name = "pageNum", required = false, defaultValue = "1") 27 | int pageNum, 28 | @RequestParam(name = "pageSize", required = false, defaultValue = "10") 29 | int pageSize) { 30 | return userService.findAllUser(pageNum, pageSize); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis.mapper; 2 | 3 | import org.apache.ibatis.annotations.Insert; 4 | import org.apache.ibatis.annotations.Result; 5 | import org.apache.ibatis.annotations.Results; 6 | import org.apache.ibatis.annotations.Select; 7 | import priv.simon.mybatis.model.User; 8 | 9 | import java.util.List; 10 | 11 | public interface UserMapper { 12 | /** 13 | * 插入数据 14 | * @param record 数据记录 15 | * @return 成功操作的记录数 16 | */ 17 | @Insert("INSERT INTO user(userId,username,password,phone}) VALUES(#{userId}, #{username}, #{password},#{phone})") 18 | int insert(User record); 19 | 20 | /** 21 | * 查询所有用户 22 | * 23 | * @return 所有用户数据 24 | */ 25 | @Select("SELECT * FROM user") 26 | @Results({ 27 | @Result(property = "userId",column = "userId"), 28 | @Result(property = "username",column = "username"), 29 | @Result(property = "password",column = "password"), 30 | @Result(property = "phone",column = "phone") 31 | }) 32 | List selectUsers(); 33 | } -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/model/User.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis.model; 2 | 3 | public class User { 4 | private Integer userId; 5 | 6 | private String username; 7 | 8 | private String password; 9 | 10 | private String phone; 11 | 12 | public Integer getUserId() { 13 | return userId; 14 | } 15 | 16 | public void setUserId(Integer userId) { 17 | this.userId = userId; 18 | } 19 | 20 | public String getUsername() { 21 | return username; 22 | } 23 | 24 | public void setUsername(String username) { 25 | this.username = username == null ? null : username.trim(); 26 | } 27 | 28 | public String getPassword() { 29 | return password; 30 | } 31 | 32 | public void setPassword(String password) { 33 | this.password = password == null ? null : password.trim(); 34 | } 35 | 36 | public String getPhone() { 37 | return phone; 38 | } 39 | 40 | public void setPhone(String phone) { 41 | this.phone = phone == null ? null : phone.trim(); 42 | } 43 | } -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis.service; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import priv.simon.mybatis.model.User; 5 | 6 | /** 7 | * @author simon 8 | * @create 2018-11-19 12:26 9 | **/ 10 | public interface IUserService { 11 | int addUser(User user); 12 | PageInfo findAllUser(int pageNum, int pageSize); 13 | } 14 | -------------------------------------------------------------------------------- /mybatis/src/main/java/priv/simon/mybatis/service/impl/UserService.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis.service.impl; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import priv.simon.mybatis.mapper.UserMapper; 8 | import priv.simon.mybatis.model.User; 9 | import priv.simon.mybatis.service.IUserService; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author simon 15 | * @create 2018-11-19 12:27 16 | **/ 17 | @Service 18 | public class UserService implements IUserService { 19 | 20 | private final UserMapper userDao; 21 | 22 | @Autowired 23 | public UserService(UserMapper userDao) { 24 | this.userDao = userDao; 25 | } 26 | 27 | @Override 28 | public int addUser(User user) { 29 | return userDao.insert(user); 30 | } 31 | 32 | /* 33 | * 这个方法中用到了我们开头配置依赖的分页插件pagehelper 34 | * 很简单,只需要在service层传入参数,然后将参数传递给一个插件的一个静态方法即可; 35 | * pageNum 开始页数 36 | * pageSize 每页显示的数据条数 37 | * */ 38 | @Override 39 | public PageInfo findAllUser(int pageNum, int pageSize) { 40 | //将参数传给这个方法就可以实现物理分页了,非常简单。 41 | PageHelper.startPage(pageNum, pageSize); 42 | List userDomains = userDao.selectUsers(); 43 | return new PageInfo(userDomains); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /mybatis/src/main/resources/application.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/mybatis/src/main/resources/application.yml -------------------------------------------------------------------------------- /mybatis/src/main/resources/generatorConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /mybatis/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | user 6 | 7 | 8 | userId,userName,password,phone 9 | 10 | 11 | INSERT INTO 12 | 13 | 14 | userName,password, 15 | 16 | phone, 17 | 18 | 19 | 20 | #{userName, jdbcType=VARCHAR},#{password, jdbcType=VARCHAR}, 21 | 22 | #{phone, jdbcType=VARCHAR}, 23 | 24 | 25 | 26 | 32 | 33 | -------------------------------------------------------------------------------- /mybatis/src/test/java/priv/simon/mybatis/MybatisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.mybatis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class MybatisApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /oauth2/.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 | -------------------------------------------------------------------------------- /oauth2/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /oauth2/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /oauth2/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /oauth2/auth-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /oauth2/auth-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.oauth2 7 | auth-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | auth-resource-server 12 | 授权服务器 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR2 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-oauth2 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-security 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-dependencies 54 | ${spring-cloud.version} 55 | pom 56 | import 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /oauth2/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/AuthResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 7 | 8 | @EnableAuthorizationServer 9 | @SpringBootApplication 10 | public class AuthResourceServerApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(AuthResourceServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /oauth2/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/AuthorizationServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.security.authentication.AuthenticationManager; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 9 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; 10 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; 11 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; 12 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 13 | import org.springframework.security.oauth2.provider.token.TokenStore; 14 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 15 | 16 | /** 17 | * 授权服务器配置 18 | * 19 | * @author simon 20 | * @create 2018-10-29 11:51 21 | **/ 22 | @Configuration 23 | public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 24 | 25 | @Autowired 26 | private AuthenticationManager authenticationManager; 27 | 28 | @Autowired 29 | UserDetailsService userDetailsService; 30 | 31 | // 使用最基本的InMemoryTokenStore生成token 32 | @Bean 33 | public TokenStore memoryTokenStore() { 34 | return new InMemoryTokenStore(); 35 | } 36 | 37 | /** 38 | * 配置客户端详情服务 39 | * 客户端详细信息在这里进行初始化,你能够把客户端详情信息写死在这里或者是通过数据库来存储调取详情信息 40 | * @param clients 41 | * @throws Exception 42 | */ 43 | @Override 44 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 45 | clients.inMemory() 46 | .withClient("client1")//用于标识用户ID 47 | .authorizedGrantTypes("authorization_code","client_credentials","password","implicit","refresh_token")//授权方式 48 | .scopes("test")//授权范围 49 | .secret(PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("123456"));//客户端安全码,secret密码配置从 Spring Security 5.0开始必须以 {bcrypt}+加密后的密码 这种格式填写; 50 | } 51 | 52 | /** 53 | * 用来配置令牌端点(Token Endpoint)的安全约束. 54 | * @param security 55 | * @throws Exception 56 | */ 57 | @Override 58 | public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { 59 | /* 配置token获取合验证时的策略 */ 60 | security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").allowFormAuthenticationForClients(); 61 | } 62 | 63 | /** 64 | * 用来配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services) 65 | * @param endpoints 66 | * @throws Exception 67 | */ 68 | @Override 69 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 70 | // 配置tokenStore 71 | endpoints.authenticationManager(authenticationManager).tokenStore(memoryTokenStore()).userDetailsService(userDetailsService); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /oauth2/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.security.authentication.AuthenticationManager; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.core.userdetails.User; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 11 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; 12 | 13 | /** 14 | * 配置spring security 15 | * 16 | * @author simon 17 | * @create 2018-10-29 16:25 18 | **/ 19 | @EnableWebSecurity//开启权限验证 20 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 21 | /** 22 | * 配置这个bean会在做AuthorizationServerConfigurer配置的时候使用 23 | * @return 24 | * @throws Exception 25 | */ 26 | @Bean 27 | @Override 28 | public AuthenticationManager authenticationManagerBean() throws Exception { 29 | return super.authenticationManagerBean(); 30 | } 31 | 32 | /** 33 | * 配置用户 34 | * 使用内存中的用户,实际项目中,一般使用的是数据库保存用户,具体的实现类可以使用JdbcDaoImpl或者JdbcUserDetailsManager 35 | * @return 36 | */ 37 | @Bean 38 | @Override 39 | protected UserDetailsService userDetailsService() { 40 | InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); 41 | manager.createUser(User.withUsername("admin").password(PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("admin")).authorities("USER").build()); 42 | return manager; 43 | } 44 | 45 | // @Override 46 | // protected void configure(HttpSecurity http) throws Exception { 47 | // http.requestMatchers().anyRequest().and().authorizeRequests().antMatchers("/oauth/*").permitAll(); 48 | // } 49 | 50 | @Override 51 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 52 | auth.userDetailsService(userDetailsService()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /oauth2/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/TestEndpoints.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author simon 11 | * @create 2018-10-29 17:18 12 | **/ 13 | @RestController 14 | public class TestEndpoints { 15 | private static final Logger log = LoggerFactory.getLogger(TestEndpoints.class); 16 | // 添加一个测试访问接口 17 | @GetMapping("/user") 18 | public Authentication getUser(Authentication authentication) { 19 | log.info("resource: user {}", authentication); 20 | return authentication; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /oauth2/auth-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/oauth2/auth-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /oauth2/auth-server/src/test/java/priv/simon/oauth2/authresourceserver/AuthResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AuthResourceServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /oauth2/oauth2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /oauth2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | priv.simon.oauth2 8 | oauth2 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | auth-server 13 | resource-server 14 | 15 | -------------------------------------------------------------------------------- /oauth2/resource-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.resource 7 | resource-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | resource-server 12 | 资源服务器 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR2 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-security 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-oauth2 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-dependencies 54 | ${spring-cloud.version} 55 | pom 56 | import 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /oauth2/resource-server/src/main/java/priv/simon/resource/resourceserver/ResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @EnableResourceServer 13 | @RestController 14 | @SpringBootApplication 15 | public class ResourceServerApplication { 16 | 17 | private static final Logger log = LoggerFactory.getLogger(ResourceServerApplication.class); 18 | 19 | public static void main(String[] args) { 20 | SpringApplication.run(ResourceServerApplication.class, args); 21 | } 22 | 23 | @GetMapping("/user") 24 | public Authentication getUser(Authentication authentication) { 25 | log.info("resource: user {}", authentication); 26 | return authentication; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /oauth2/resource-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/oauth2/resource-server/src/main/resources/application.yml -------------------------------------------------------------------------------- /oauth2/resource-server/src/test/java/priv/simon/resource/resourceserver/ResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ResourceServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /oauth2_jwt/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | .mvn 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /build/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.oauth2 7 | auth-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | auth-server 12 | 授权服务器 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR2 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-oauth2 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-security 40 | 41 | 42 | org.springframework.security 43 | spring-security-jwt 44 | 1.0.7.RELEASE 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.cloud 58 | spring-cloud-dependencies 59 | ${spring-cloud.version} 60 | pom 61 | import 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-maven-plugin 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/AuthServerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; 6 | 7 | @EnableAuthorizationServer 8 | @SpringBootApplication 9 | public class AuthServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AuthServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/AuthorizationServerConfiguration.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.io.ClassPathResource; 7 | import org.springframework.security.authentication.AuthenticationManager; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 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.configurers.AuthorizationServerEndpointsConfigurer; 13 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; 14 | import org.springframework.security.oauth2.provider.token.DefaultTokenServices; 15 | import org.springframework.security.oauth2.provider.token.TokenEnhancer; 16 | import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; 17 | import org.springframework.security.oauth2.provider.token.TokenStore; 18 | import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; 19 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 20 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 21 | import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory; 22 | 23 | import java.util.Arrays; 24 | import java.util.concurrent.TimeUnit; 25 | 26 | /** 27 | * 授权服务器配置 28 | * 29 | * @author simon 30 | * @create 2018-10-29 11:51 31 | **/ 32 | @Configuration 33 | public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter { 34 | 35 | @Autowired 36 | private AuthenticationManager authenticationManager; 37 | 38 | @Autowired 39 | UserDetailsService userDetailsService; 40 | 41 | @Bean 42 | public TokenStore tokenStore(){ 43 | return new JwtTokenStore(accessTokenConverter()); 44 | } 45 | 46 | 47 | @Bean 48 | public JwtAccessTokenConverter accessTokenConverter() { 49 | final JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 50 | // converter.setSigningKey("123"); 51 | KeyStoreKeyFactory keyStoreKeyFactory = 52 | new KeyStoreKeyFactory(new ClassPathResource("mytest.jks"), "mypass".toCharArray()); 53 | converter.setKeyPair(keyStoreKeyFactory.getKeyPair("mytest")); 54 | converter.setAccessTokenConverter(new CustomerAccessTokenConverter()); 55 | return converter; 56 | } 57 | 58 | /** 59 | * 注入自定义token生成方式 60 | * 61 | * @return 62 | */ 63 | @Bean 64 | public TokenEnhancer customerEnhancer() { 65 | return new CustomTokenEnhancer(); 66 | } 67 | 68 | /** 69 | * 配置客户端详情服务 70 | * 客户端详细信息在这里进行初始化,你能够把客户端详情信息写死在这里或者是通过数据库来存储调取详情信息 71 | * @param clients 72 | * @throws Exception 73 | */ 74 | @Override 75 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 76 | clients.inMemory() 77 | .withClient("client1")//用于标识用户ID 78 | .authorizedGrantTypes("authorization_code","refresh_token")//授权方式 79 | .scopes("test")//授权范围 80 | .secret(PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("123456"));//客户端安全码,secret密码配置从 Spring Security 5.0开始必须以 {bcrypt}+加密后的密码 这种格式填写; 81 | } 82 | 83 | /** 84 | * 用来配置令牌端点(Token Endpoint)的安全约束. 85 | * @param security 86 | * @throws Exception 87 | */ 88 | @Override 89 | public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { 90 | /* 配置token获取合验证时的策略 */ 91 | security.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").allowFormAuthenticationForClients(); 92 | } 93 | 94 | /** 95 | * 用来配置授权(authorization)以及令牌(token)的访问端点和令牌服务(token services) 96 | * @param endpoints 97 | * @throws Exception 98 | */ 99 | @Override 100 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 101 | // 配置tokenStore 102 | // endpoints.authenticationManager(authenticationManager).tokenStore(tokenStore()) 103 | // .accessTokenConverter(accessTokenConverter()).userDetailsService(userDetailsService); 104 | //指定认证管理器 105 | endpoints.authenticationManager(authenticationManager); 106 | //指定token存储位置 107 | endpoints.tokenStore(tokenStore()); 108 | 109 | endpoints.accessTokenConverter(accessTokenConverter()); 110 | endpoints.userDetailsService(userDetailsService); 111 | //自定义token生成方式 112 | TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); 113 | tokenEnhancerChain.setTokenEnhancers(Arrays.asList(customerEnhancer(),accessTokenConverter())); 114 | endpoints.tokenEnhancer(tokenEnhancerChain); 115 | 116 | // 配置TokenServices参数 117 | DefaultTokenServices tokenServices = (DefaultTokenServices) endpoints.getDefaultAuthorizationServerTokenServices(); 118 | tokenServices.setTokenStore(endpoints.getTokenStore()); 119 | tokenServices.setSupportRefreshToken(true); 120 | tokenServices.setClientDetailsService(endpoints.getClientDetailsService()); 121 | tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer()); 122 | tokenServices.setAccessTokenValiditySeconds((int) TimeUnit.DAYS.toSeconds(1));//一天 123 | endpoints.tokenServices(tokenServices); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/CustomTokenEnhancer.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.security.core.userdetails.UserDetails; 4 | import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; 5 | import org.springframework.security.oauth2.common.OAuth2AccessToken; 6 | import org.springframework.security.oauth2.provider.OAuth2Authentication; 7 | import org.springframework.security.oauth2.provider.token.TokenEnhancer; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * 自定义token生成携带的信息 14 | * 15 | * @author simon 16 | * @create 2018-11-14 10:16 17 | **/ 18 | public class CustomTokenEnhancer implements TokenEnhancer { 19 | @Override 20 | public OAuth2AccessToken enhance(OAuth2AccessToken oAuth2AccessToken, OAuth2Authentication oAuth2Authentication) { 21 | final Map additionalInfo = new HashMap<>(); 22 | //获取登录信息 23 | UserDetails user = (UserDetails) oAuth2Authentication.getUserAuthentication().getPrincipal(); 24 | additionalInfo.put("userName", user.getUsername()); 25 | additionalInfo.put("authorities", user.getAuthorities()); 26 | ((DefaultOAuth2AccessToken) oAuth2AccessToken).setAdditionalInformation(additionalInfo); 27 | return oAuth2AccessToken; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/CustomerAccessTokenConverter.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.core.authority.AuthorityUtils; 5 | import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; 6 | import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; 7 | 8 | import java.util.LinkedHashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * 自定义CustomerAccessTokenConverter 这个类的作用主要用于AccessToken的转换, 13 | * 默认使用DefaultAccessTokenConverter 这个装换器 14 | * DefaultAccessTokenConverter有个UserAuthenticationConverter,这个转换器作用是把用户的信息放入token中, 15 | * 默认只是放入user_name 16 | *

17 | * 自定义了下这个方法,加入了额外的信息 18 | *

19 | * @author simon 20 | * @create 2018-11-14 10:26 21 | **/ 22 | public class CustomerAccessTokenConverter extends DefaultAccessTokenConverter { 23 | 24 | public CustomerAccessTokenConverter() { 25 | super.setUserTokenConverter(new CustomerUserAuthenticationConverter()); 26 | } 27 | 28 | private class CustomerUserAuthenticationConverter extends DefaultUserAuthenticationConverter{ 29 | @Override 30 | public Map convertUserAuthentication(Authentication authentication) { 31 | LinkedHashMap response = new LinkedHashMap <>(); 32 | response.put("details", authentication.getDetails()); 33 | response.put("test","hello"); 34 | if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { 35 | response.put("authorities", AuthorityUtils.authorityListToSet(authentication.getAuthorities())); 36 | } 37 | return response; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/java/priv/simon/oauth2/authresourceserver/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.security.authentication.AuthenticationManager; 5 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 7 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 8 | import org.springframework.security.core.userdetails.User; 9 | import org.springframework.security.core.userdetails.UserDetailsService; 10 | import org.springframework.security.crypto.factory.PasswordEncoderFactories; 11 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; 12 | 13 | /** 14 | * 配置spring security 15 | * 16 | * @author simon 17 | * @create 2018-10-29 16:25 18 | **/ 19 | @EnableWebSecurity//开启权限验证 20 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 21 | /** 22 | * 配置这个bean会在做AuthorizationServerConfigurer配置的时候使用 23 | * @return 24 | * @throws Exception 25 | */ 26 | @Bean 27 | @Override 28 | public AuthenticationManager authenticationManagerBean() throws Exception { 29 | return super.authenticationManagerBean(); 30 | } 31 | 32 | /** 33 | * 配置用户 34 | * 使用内存中的用户,实际项目中,一般使用的是数据库保存用户,具体的实现类可以使用JdbcDaoImpl或者JdbcUserDetailsManager 35 | * @return 36 | */ 37 | @Bean 38 | @Override 39 | protected UserDetailsService userDetailsService() { 40 | InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); 41 | manager.createUser(User.withUsername("admin").password(PasswordEncoderFactories.createDelegatingPasswordEncoder().encode("admin")).authorities("USER").build()); 42 | return manager; 43 | } 44 | 45 | // @Override 46 | // protected void configure(HttpSecurity http) throws Exception { 47 | // http.requestMatchers().anyRequest().and().authorizeRequests().antMatchers("/oauth/*").permitAll(); 48 | // } 49 | 50 | @Override 51 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 52 | auth.userDetailsService(userDetailsService()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/oauth2_jwt/auth-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/main/resources/mytest.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/oauth2_jwt/auth-server/src/main/resources/mytest.jks -------------------------------------------------------------------------------- /oauth2_jwt/auth-server/src/test/java/priv/simon/oauth2/authresourceserver/AuthResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.oauth2.authresourceserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.security.jwt.Jwt; 7 | import org.springframework.security.jwt.JwtHelper; 8 | import org.springframework.test.context.junit4.SpringRunner; 9 | 10 | @RunWith(SpringRunner.class) 11 | @SpringBootTest 12 | public class AuthResourceServerApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | String token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoiaGVsbG8iLCJzY29wZSI6WyJ0ZXN0Il0sImRldGFpbHMiOnsicmVtb3RlQWRkcmVzcyI6IjA6MDowOjA6MDowOjA6MSIsInNlc3Npb25JZCI6IjM0QjE4OUVBNkYxREE0ODM0RTVBRUEzMUU5MUEyNDYwIn0sImV4cCI6MTU0MjI3NzExNSwidXNlck5hbWUiOiJhZG1pbiIsImF1dGhvcml0aWVzIjpbeyJhdXRob3JpdHkiOiJVU0VSIn1dLCJqdGkiOiI4ZTRhNzJkMy1hZmZiLTQ5NzctYjE3NC1jYjllZTRmMmUwOGIiLCJjbGllbnRfaWQiOiJjbGllbnQxIn0.aszoP7crZZRmCdHxO_tuIfnd9FdCMIcI1z1SGygYL0WTjapiA35LH3LnZzX0QmtdqrUGr9mP1Pl5YmNoAYVibd7GSkB1P7vSd251gut7IrmTV3_wL7rj-zR4pfMHF5NhIHbG4FKtXM3E_l93I0IbJGx8t8tCg8N4mGsKHTe0Ht6IjdUT2ET8iohuQ_6XAwEvhRlcJah420G5v4tVQP7eHnZmoFkB1bJ0mXI0Knq-4lFS1xkmIv8qctxQJt6Oin6c4zRHTMvOC4DfknbyDAUy31XLYkFr-7cyy46Nt93E3iPRCNFJRsFybdjVm9S3SI5iPpsw1JRyfyv9iQG17ystaA"; 17 | Jwt jwt = JwtHelper.decode(token); 18 | System.err.println(jwt.toString()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | .mvn 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /build/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon.resource 7 | resource-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | resource-server 12 | 资源服务器 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.6.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR2 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-security 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-oauth2 40 | 41 | 42 | org.springframework.security 43 | spring-security-jwt 44 | 1.0.7.RELEASE 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/main/java/priv/simon/resource/resourceserver/CustomerAccessTokenConverter.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 4 | import org.springframework.security.core.Authentication; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.authority.AuthorityUtils; 7 | import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; 8 | import org.springframework.security.oauth2.provider.token.DefaultUserAuthenticationConverter; 9 | import org.springframework.util.StringUtils; 10 | 11 | import java.util.Collection; 12 | import java.util.Map; 13 | 14 | /** 15 | * 自定义CustomerAccessTokenConverter 这个类的作用主要用于AccessToken的转换, 16 | * 默认使用DefaultAccessTokenConverter 这个装换器 17 | * DefaultAccessTokenConverter有个UserAuthenticationConverter,这个转换器作用是把用户的信息放入token中, 18 | * 默认只是放入username 19 | *

20 | * 自定义了下这个方法,加入了额外的信息 21 | *

22 | * @author simon 23 | * @create 2018-11-14 10:26 24 | **/ 25 | public class CustomerAccessTokenConverter extends DefaultAccessTokenConverter { 26 | 27 | public CustomerAccessTokenConverter() { 28 | super.setUserTokenConverter(new CustomerUserAuthenticationConverter()); 29 | } 30 | 31 | private class CustomerUserAuthenticationConverter extends DefaultUserAuthenticationConverter { 32 | 33 | @Override 34 | public Authentication extractAuthentication(Map map) { 35 | Collection authorities = this.getAuthorities(map); 36 | return new UsernamePasswordAuthenticationToken(map, "N/A", authorities); 37 | } 38 | 39 | private Collection getAuthorities(Map map) { 40 | if (!map.containsKey("authorities")) { 41 | return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils.arrayToCommaDelimitedString(new String[]{"USER"})); 42 | } else { 43 | Object authorities = map.get("authorities"); 44 | if (authorities instanceof String) { 45 | return AuthorityUtils.commaSeparatedStringToAuthorityList((String) authorities); 46 | } else if (authorities instanceof Collection) { 47 | return AuthorityUtils.commaSeparatedStringToAuthorityList(StringUtils.collectionToCommaDelimitedString((Collection) authorities)); 48 | } else { 49 | throw new IllegalArgumentException("Authorities must be either a String or a Collection"); 50 | } 51 | } 52 | } 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/main/java/priv/simon/resource/resourceserver/OAuth2ResourceServerConfig.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Primary; 6 | import org.springframework.core.io.ClassPathResource; 7 | import org.springframework.core.io.Resource; 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.DefaultTokenServices; 12 | import org.springframework.security.oauth2.provider.token.TokenStore; 13 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; 14 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.InputStream; 19 | import java.io.InputStreamReader; 20 | 21 | /** 22 | * 资源服务器配置 23 | * 24 | * @author simon 25 | * @create 2018-11-14 11:03 26 | **/ 27 | @Configuration 28 | @EnableResourceServer 29 | public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter { 30 | 31 | @Bean 32 | public JwtAccessTokenConverter accessTokenConverter(){ 33 | JwtAccessTokenConverter converter = new JwtAccessTokenConverter(); 34 | Resource resource = new ClassPathResource("public.txt"); 35 | String publicKey; 36 | try { 37 | publicKey = inputStream2String(resource.getInputStream()); 38 | } catch (final IOException e) { 39 | throw new RuntimeException(e); 40 | } 41 | converter.setVerifierKey(publicKey); 42 | converter.setAccessTokenConverter(new CustomerAccessTokenConverter()); 43 | return converter; 44 | } 45 | 46 | @Bean 47 | public TokenStore tokenStore() { 48 | return new JwtTokenStore(accessTokenConverter()); 49 | } 50 | 51 | @Override 52 | public void configure(ResourceServerSecurityConfigurer resources) throws Exception { 53 | DefaultTokenServices defaultTokenServices = new DefaultTokenServices(); 54 | defaultTokenServices.setTokenStore(tokenStore()); 55 | resources.tokenServices(defaultTokenServices); 56 | // resources.tokenStore(tokenStore()); 57 | } 58 | 59 | private String inputStream2String(InputStream is) throws IOException { 60 | BufferedReader in = new BufferedReader(new InputStreamReader(is)); 61 | StringBuilder builder = new StringBuilder(); 62 | String line; 63 | while ((line = in.readLine()) != null) { 64 | builder.append(line); 65 | } 66 | return builder.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/main/java/priv/simon/resource/resourceserver/ResourceServerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.security.core.Authentication; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | @RestController 12 | @SpringBootApplication 13 | public class ResourceServerApplication { 14 | 15 | private static final Logger log = LoggerFactory.getLogger(ResourceServerApplication.class); 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(ResourceServerApplication.class, args); 19 | } 20 | 21 | @GetMapping("/user") 22 | public Authentication getUser(Authentication authentication) { 23 | log.info("resource: user {}", authentication); 24 | return authentication; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/oauth2_jwt/resource-server/src/main/resources/application.yml -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/main/resources/public.txt: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhAF1qpL+8On3rF2M77lR 3 | +l3WXKpGXIc2SwIXHwQvml/4SG7fJcupYVOkiaXj4f8g1e7qQCU4VJGvC/gGJ7sW 4 | fn+L+QKVaRhs9HuLsTzHcTVl2h5BeawzZoOi+bzQncLclhoMYXQJJ5fULnadRbKN 5 | HO7WyvrvYCANhCmdDKsDMDKxHTV9ViCIDpbyvdtjgT1fYLu66xZhubSHPowXXO15 6 | LGDkROF0onqc8j4V29qy5iSnx8I9UIMEgrRpd6raJftlAeLXFa7BYlE2hf7cL+oG 7 | hY+q4S8CjHRuiDfebKFC1FJA3v3G9p9K4slrHlovxoVfe6QdduD8repoH07jWULu 8 | qQIDAQAB 9 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /oauth2_jwt/resource-server/src/test/java/priv/simon/resource/resourceserver/ResourceServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.resource.resourceserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ResourceServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /redis/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | /out/ 20 | 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ -------------------------------------------------------------------------------- /redis/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext { 3 | springBootVersion = '2.1.0.RELEASE' 4 | } 5 | repositories { 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 10 | } 11 | } 12 | 13 | apply plugin: 'java' 14 | apply plugin: 'eclipse' 15 | apply plugin: 'org.springframework.boot' 16 | apply plugin: 'io.spring.dependency-management' 17 | 18 | group = 'priv.simon.springboot' 19 | version = '0.0.1-SNAPSHOT' 20 | sourceCompatibility = 1.8 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | 27 | dependencies { 28 | implementation('org.springframework.boot:spring-boot-starter-data-redis') 29 | implementation('org.springframework.boot:spring-boot-starter-web') 30 | testImplementation('org.springframework.boot:spring-boot-starter-test') 31 | } 32 | -------------------------------------------------------------------------------- /redis/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/redis/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /redis/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Feb 06 12:27:20 CET 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip 7 | -------------------------------------------------------------------------------- /redis/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 | -------------------------------------------------------------------------------- /redis/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 | -------------------------------------------------------------------------------- /redis/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'redis' 2 | -------------------------------------------------------------------------------- /redis/src/main/java/priv/simon/springboot/redis/RedisApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.springboot.redis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author simon 8 | * @date 2017/11/28 9 | */ 10 | @SpringBootApplication 11 | public class RedisApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /redis/src/main/java/priv/simon/springboot/redis/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package priv.simon.springboot.redis; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 4 | import com.fasterxml.jackson.annotation.PropertyAccessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.data.redis.connection.RedisConnectionFactory; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 11 | import org.springframework.data.redis.serializer.StringRedisSerializer; 12 | 13 | /** 14 | * redis配置类 15 | * 16 | * @author simon 17 | * @create 2018-11-28 10:01 18 | **/ 19 | @Configuration 20 | public class RedisConfig { 21 | @Bean 22 | public RedisTemplate redisTemplate(RedisConnectionFactory factory){ 23 | RedisTemplate template = new RedisTemplate <>(); 24 | template.setConnectionFactory(factory); 25 | 26 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); 27 | ObjectMapper om = new ObjectMapper(); 28 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 29 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 30 | jackson2JsonRedisSerializer.setObjectMapper(om); 31 | 32 | StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); 33 | // key采用String的序列化方式 34 | template.setKeySerializer(stringRedisSerializer); 35 | // hash的key也采用String的序列化方式 36 | template.setHashKeySerializer(stringRedisSerializer); 37 | // value序列化方式采用jackson 38 | template.setValueSerializer(jackson2JsonRedisSerializer); 39 | // hash的value序列化方式采用jackson 40 | template.setHashValueSerializer(jackson2JsonRedisSerializer); 41 | template.afterPropertiesSet(); 42 | 43 | return template; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /redis/src/main/java/priv/simon/springboot/redis/RedisUtils.java: -------------------------------------------------------------------------------- 1 | package priv.simon.springboot.redis; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.RedisTemplate; 5 | import org.springframework.stereotype.Component; 6 | import org.springframework.util.CollectionUtils; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.Set; 11 | import java.util.concurrent.TimeUnit; 12 | 13 | /** 14 | * redis 工具类 15 | * 16 | * @author simon 17 | * @date 2018-11-28 10:35 18 | **/ 19 | @Component 20 | public class RedisUtils { 21 | /** 22 | * 注入redisTemplate bean 23 | */ 24 | @Autowired 25 | private RedisTemplate redisTemplate; 26 | 27 | /** 28 | * 指定缓存失效时间 29 | * 30 | * @param key 键 31 | * @param time 时间(秒) 32 | * @return 33 | */ 34 | public boolean expire(String key, long time) { 35 | try { 36 | if (time > 0) { 37 | redisTemplate.expire(key, time, TimeUnit.SECONDS); 38 | } 39 | return true; 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | return false; 43 | } 44 | } 45 | 46 | /** 47 | * 根据key获取过期时间 48 | * 49 | * @param key 键 不能为null 50 | * @return 时间(秒) 返回0代表为永久有效 51 | */ 52 | public long getExpire(String key) { 53 | return redisTemplate.getExpire(key, TimeUnit.SECONDS); 54 | } 55 | 56 | /** 57 | * 判断key是否存在 58 | * 59 | * @param key 键 60 | * @return true 存在 false不存在 61 | */ 62 | public boolean hasKey(String key) { 63 | try { 64 | return redisTemplate.hasKey(key); 65 | } catch (Exception e) { 66 | e.printStackTrace(); 67 | return false; 68 | } 69 | } 70 | 71 | /** 72 | * 删除缓存 73 | * 74 | * @param key 可以传一个值 或多个 75 | */ 76 | @SuppressWarnings("unchecked") 77 | public void del(String... key) { 78 | if (key != null && key.length > 0) { 79 | if (key.length == 1) { 80 | redisTemplate.delete(key[0]); 81 | } else { 82 | redisTemplate.delete(CollectionUtils.arrayToList(key)); 83 | } 84 | } 85 | } 86 | // ============================String(字符串)============================= 87 | 88 | /** 89 | * 普通缓存获取 90 | * 91 | * @param key 键 92 | * @return 值 93 | */ 94 | public Object get(String key) { 95 | return key == null ? null : redisTemplate.opsForValue().get(key); 96 | } 97 | 98 | /** 99 | * 普通缓存放入 100 | * 101 | * @param key 键 102 | * @param value 值 103 | * @return true成功 false失败 104 | */ 105 | public boolean set(String key, Object value) { 106 | try { 107 | redisTemplate.opsForValue().set(key, value); 108 | return true; 109 | } catch (Exception e) { 110 | e.printStackTrace(); 111 | return false; 112 | } 113 | } 114 | 115 | /** 116 | * 普通缓存放入并设置时间 117 | * 118 | * @param key 键 119 | * @param value 值 120 | * @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期 121 | * @return true成功 false 失败 122 | */ 123 | public boolean set(String key, Object value, long time) { 124 | try { 125 | if (time > 0) { 126 | redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); 127 | } else { 128 | set(key, value); 129 | } 130 | return true; 131 | } catch (Exception e) { 132 | e.printStackTrace(); 133 | return false; 134 | } 135 | } 136 | 137 | /** 138 | * 递增 139 | * 140 | * @param key 键 141 | * @param delta 要增加几(大于0) 142 | * @return 143 | */ 144 | public long incr(String key, long delta) { 145 | if (delta < 0) { 146 | throw new RuntimeException("递增因子必须大于0"); 147 | } 148 | return redisTemplate.opsForValue().increment(key, delta); 149 | } 150 | 151 | /** 152 | * 递减 153 | * 154 | * @param key 键 155 | * @param delta 要减少几(小于0) 156 | * @return 157 | */ 158 | public long decr(String key, long delta) { 159 | if (delta < 0) { 160 | throw new RuntimeException("递减因子必须大于0"); 161 | } 162 | return redisTemplate.opsForValue().increment(key, -delta); 163 | } 164 | // ================================Hash(哈希)================================= 165 | 166 | /** 167 | * HashGet 168 | * 169 | * @param key 键 不能为null 170 | * @param item 项 不能为null 171 | * @return 值 172 | */ 173 | public Object hget(String key, String item) { 174 | return redisTemplate.opsForHash().get(key, item); 175 | } 176 | 177 | /** 178 | * 获取hashKey对应的所有键值 179 | * 180 | * @param key 键 181 | * @return 对应的多个键值 182 | */ 183 | public Map hmget(String key) { 184 | return redisTemplate.opsForHash().entries(key); 185 | } 186 | 187 | /** 188 | * HashSet 189 | * 190 | * @param key 键 191 | * @param map 对应多个键值 192 | * @return true 成功 false 失败 193 | */ 194 | public boolean hmset(String key, Map map) { 195 | try { 196 | redisTemplate.opsForHash().putAll(key, map); 197 | return true; 198 | } catch (Exception e) { 199 | e.printStackTrace(); 200 | return false; 201 | } 202 | } 203 | 204 | /** 205 | * HashSet 并设置时间 206 | * 207 | * @param key 键 208 | * @param map 对应多个键值 209 | * @param time 时间(秒) 210 | * @return true成功 false失败 211 | */ 212 | public boolean hmset(String key, Map map, long time) { 213 | try { 214 | redisTemplate.opsForHash().putAll(key, map); 215 | if (time > 0) { 216 | expire(key, time); 217 | } 218 | return true; 219 | } catch (Exception e) { 220 | e.printStackTrace(); 221 | return false; 222 | } 223 | } 224 | 225 | /** 226 | * 向一张hash表中放入数据,如果不存在将创建 227 | * 228 | * @param key 键 229 | * @param item 项 230 | * @param value 值 231 | * @return true 成功 false失败 232 | */ 233 | public boolean hset(String key, String item, Object value) { 234 | try { 235 | redisTemplate.opsForHash().put(key, item, value); 236 | return true; 237 | } catch (Exception e) { 238 | e.printStackTrace(); 239 | return false; 240 | } 241 | } 242 | 243 | /** 244 | * 向一张hash表中放入数据,如果不存在将创建 245 | * 246 | * @param key 键 247 | * @param item 项 248 | * @param value 值 249 | * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 250 | * @return true 成功 false失败 251 | */ 252 | public boolean hset(String key, String item, Object value, long time) { 253 | try { 254 | redisTemplate.opsForHash().put(key, item, value); 255 | if (time > 0) { 256 | expire(key, time); 257 | } 258 | return true; 259 | } catch (Exception e) { 260 | e.printStackTrace(); 261 | return false; 262 | } 263 | } 264 | 265 | /** 266 | * 删除hash表中的值 267 | * 268 | * @param key 键 不能为null 269 | * @param item 项 可以使多个 不能为null 270 | */ 271 | public void hdel(String key, Object... item) { 272 | redisTemplate.opsForHash().delete(key, item); 273 | } 274 | 275 | /** 276 | * 判断hash表中是否有该项的值 277 | * 278 | * @param key 键 不能为null 279 | * @param item 项 不能为null 280 | * @return true 存在 false不存在 281 | */ 282 | public boolean hHasKey(String key, String item) { 283 | return redisTemplate.opsForHash().hasKey(key, item); 284 | } 285 | 286 | /** 287 | * hash递增 如果不存在,就会创建一个 并把新增后的值返回 288 | * 289 | * @param key 键 290 | * @param item 项 291 | * @param by 要增加几(大于0) 292 | * @return 293 | */ 294 | public double hincr(String key, String item, double by) { 295 | return redisTemplate.opsForHash().increment(key, item, by); 296 | } 297 | 298 | /** 299 | * hash递减 300 | * 301 | * @param key 键 302 | * @param item 项 303 | * @param by 要减少记(小于0) 304 | * @return 305 | */ 306 | public double hdecr(String key, String item, double by) { 307 | return redisTemplate.opsForHash().increment(key, item, -by); 308 | } 309 | // ============================Set(集合)============================= 310 | 311 | /** 312 | * 根据key获取Set中的所有值 313 | * 314 | * @param key 键 315 | * @return 316 | */ 317 | public Set sGet(String key) { 318 | try { 319 | return redisTemplate.opsForSet().members(key); 320 | } catch (Exception e) { 321 | e.printStackTrace(); 322 | return null; 323 | } 324 | } 325 | 326 | /** 327 | * 根据value从一个set中查询,是否存在 328 | * 329 | * @param key 键 330 | * @param value 值 331 | * @return true 存在 false不存在 332 | */ 333 | public boolean sHasKey(String key, Object value) { 334 | try { 335 | return redisTemplate.opsForSet().isMember(key, value); 336 | } catch (Exception e) { 337 | e.printStackTrace(); 338 | return false; 339 | } 340 | } 341 | 342 | /** 343 | * 将数据放入set缓存 344 | * 345 | * @param key 键 346 | * @param values 值 可以是多个 347 | * @return 成功个数 348 | */ 349 | public long sSet(String key, Object... values) { 350 | try { 351 | return redisTemplate.opsForSet().add(key, values); 352 | } catch (Exception e) { 353 | e.printStackTrace(); 354 | return 0; 355 | } 356 | } 357 | 358 | /** 359 | * 将set数据放入缓存 360 | * 361 | * @param key 键 362 | * @param time 时间(秒) 363 | * @param values 值 可以是多个 364 | * @return 成功个数 365 | */ 366 | public long sSetAndTime(String key, long time, Object... values) { 367 | try { 368 | Long count = redisTemplate.opsForSet().add(key, values); 369 | if (time > 0) 370 | expire(key, time); 371 | return count; 372 | } catch (Exception e) { 373 | e.printStackTrace(); 374 | return 0; 375 | } 376 | } 377 | 378 | /** 379 | * 获取set缓存的长度 380 | * 381 | * @param key 键 382 | * @return 383 | */ 384 | public long sGetSetSize(String key) { 385 | try { 386 | return redisTemplate.opsForSet().size(key); 387 | } catch (Exception e) { 388 | e.printStackTrace(); 389 | return 0; 390 | } 391 | } 392 | 393 | /** 394 | * 移除值为value的 395 | * 396 | * @param key 键 397 | * @param values 值 可以是多个 398 | * @return 移除的个数 399 | */ 400 | public long setRemove(String key, Object... values) { 401 | try { 402 | Long count = redisTemplate.opsForSet().remove(key, values); 403 | return count; 404 | } catch (Exception e) { 405 | e.printStackTrace(); 406 | return 0; 407 | } 408 | } 409 | // ===============================List(列表)================================= 410 | 411 | /** 412 | * 获取list缓存的内容 413 | * 414 | * @param key 键 415 | * @param start 开始 416 | * @param end 结束 0 到 -1代表所有值 417 | * @return 418 | */ 419 | public List lGet(String key, long start, long end) { 420 | try { 421 | return redisTemplate.opsForList().range(key, start, end); 422 | } catch (Exception e) { 423 | e.printStackTrace(); 424 | return null; 425 | } 426 | } 427 | 428 | /** 429 | * 获取list缓存的长度 430 | * 431 | * @param key 键 432 | * @return 433 | */ 434 | public long lGetListSize(String key) { 435 | try { 436 | return redisTemplate.opsForList().size(key); 437 | } catch (Exception e) { 438 | e.printStackTrace(); 439 | return 0; 440 | } 441 | } 442 | 443 | /** 444 | * 通过索引 获取list中的值 445 | * 446 | * @param key 键 447 | * @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推 448 | * @return 449 | */ 450 | public Object lGetIndex(String key, long index) { 451 | try { 452 | return redisTemplate.opsForList().index(key, index); 453 | } catch (Exception e) { 454 | e.printStackTrace(); 455 | return null; 456 | } 457 | } 458 | 459 | /** 460 | * 将list放入缓存 461 | * 462 | * @param key 键 463 | * @param value 值 464 | * @return 465 | */ 466 | public boolean lSet(String key, Object value) { 467 | try { 468 | redisTemplate.opsForList().rightPush(key, value); 469 | return true; 470 | } catch (Exception e) { 471 | e.printStackTrace(); 472 | return false; 473 | } 474 | } 475 | 476 | /** 477 | * 将list放入缓存 478 | * 479 | * @param key 键 480 | * @param value 值 481 | * @param time 时间(秒) 482 | * @return 483 | */ 484 | public boolean lSet(String key, Object value, long time) { 485 | try { 486 | redisTemplate.opsForList().rightPush(key, value); 487 | if (time > 0) 488 | expire(key, time); 489 | return true; 490 | } catch (Exception e) { 491 | e.printStackTrace(); 492 | return false; 493 | } 494 | } 495 | 496 | /** 497 | * 将list放入缓存 498 | * 499 | * @param key 键 500 | * @param value 值 501 | * @return 502 | */ 503 | public boolean lSet(String key, List value) { 504 | try { 505 | redisTemplate.opsForList().rightPushAll(key, value); 506 | return true; 507 | } catch (Exception e) { 508 | e.printStackTrace(); 509 | return false; 510 | } 511 | } 512 | 513 | /** 514 | * 将list放入缓存 515 | * 516 | * @param key 键 517 | * @param value 值 518 | * @param time 时间(秒) 519 | * @return 520 | */ 521 | public boolean lSet(String key, List value, long time) { 522 | try { 523 | redisTemplate.opsForList().rightPushAll(key, value); 524 | if (time > 0) 525 | expire(key, time); 526 | return true; 527 | } catch (Exception e) { 528 | e.printStackTrace(); 529 | return false; 530 | } 531 | } 532 | 533 | /** 534 | * 根据索引修改list中的某条数据 535 | * 536 | * @param key 键 537 | * @param index 索引 538 | * @param value 值 539 | * @return 540 | */ 541 | public boolean lUpdateIndex(String key, long index, Object value) { 542 | try { 543 | redisTemplate.opsForList().set(key, index, value); 544 | return true; 545 | } catch (Exception e) { 546 | e.printStackTrace(); 547 | return false; 548 | } 549 | } 550 | 551 | /** 552 | * 移除N个值为value 553 | * 554 | * @param key 键 555 | * @param count 移除多少个 556 | * @param value 值 557 | * @return 移除的个数 558 | */ 559 | public long lRemove(String key, long count, Object value) { 560 | try { 561 | Long remove = redisTemplate.opsForList().remove(key, count, value); 562 | return remove; 563 | } catch (Exception e) { 564 | e.printStackTrace(); 565 | return 0; 566 | } 567 | } 568 | } 569 | -------------------------------------------------------------------------------- /redis/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/simondongji/SpringCloudProject/502ecd10cc2a9adc194c30b29d2a501a1d954dbc/redis/src/main/resources/application.properties -------------------------------------------------------------------------------- /redis/src/test/java/priv/simon/springboot/redis/RedisApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.springboot.redis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class RedisApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /redis/src/test/java/priv/simon/springboot/redis/RedisUtilsTest.java: -------------------------------------------------------------------------------- 1 | package priv.simon.springboot.redis; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | @RunWith(SpringRunner.class) 10 | @SpringBootTest 11 | public class RedisUtilsTest { 12 | 13 | @Autowired 14 | private RedisUtils redisUtils; 15 | 16 | @Test 17 | public void expire() { 18 | redisUtils.expire("name",230); 19 | } 20 | 21 | @Test 22 | public void getExpire() { 23 | redisUtils.getExpire("name"); 24 | } 25 | 26 | @Test 27 | public void hasKey() { 28 | redisUtils.hasKey("name"); 29 | } 30 | 31 | @Test 32 | public void del() { 33 | redisUtils.del("name"); 34 | } 35 | 36 | @Test 37 | public void get() { 38 | System.out.println(redisUtils.get("name")); 39 | } 40 | 41 | @Test 42 | public void set() { 43 | redisUtils.set("nama","221"); 44 | } 45 | 46 | @Test 47 | public void set1() { 48 | } 49 | 50 | @Test 51 | public void incr() { 52 | } 53 | 54 | @Test 55 | public void decr() { 56 | } 57 | 58 | @Test 59 | public void hget() { 60 | } 61 | 62 | @Test 63 | public void hmget() { 64 | } 65 | 66 | @Test 67 | public void hmset() { 68 | } 69 | 70 | @Test 71 | public void hmset1() { 72 | } 73 | 74 | @Test 75 | public void hset() { 76 | } 77 | 78 | @Test 79 | public void hset1() { 80 | } 81 | 82 | @Test 83 | public void hdel() { 84 | } 85 | 86 | @Test 87 | public void hHasKey() { 88 | } 89 | 90 | @Test 91 | public void hincr() { 92 | } 93 | 94 | @Test 95 | public void hdecr() { 96 | } 97 | 98 | @Test 99 | public void sGet() { 100 | } 101 | 102 | @Test 103 | public void sHasKey() { 104 | } 105 | 106 | @Test 107 | public void sSet() { 108 | } 109 | 110 | @Test 111 | public void sSetAndTime() { 112 | } 113 | 114 | @Test 115 | public void sGetSetSize() { 116 | } 117 | 118 | @Test 119 | public void setRemove() { 120 | } 121 | 122 | @Test 123 | public void lGet() { 124 | } 125 | 126 | @Test 127 | public void lGetListSize() { 128 | } 129 | 130 | @Test 131 | public void lGetIndex() { 132 | } 133 | 134 | @Test 135 | public void lSet() { 136 | } 137 | 138 | @Test 139 | public void lSet1() { 140 | } 141 | 142 | @Test 143 | public void lSet2() { 144 | } 145 | 146 | @Test 147 | public void lSet3() { 148 | } 149 | 150 | @Test 151 | public void lUpdateIndex() { 152 | } 153 | 154 | @Test 155 | public void lRemove() { 156 | } 157 | } -------------------------------------------------------------------------------- /zipkin/chainmonitor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | chainmonitor 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | chainmonitor 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | 39 | io.zipkin.java 40 | zipkin-autoconfigure-ui 41 | 2.11.5 42 | 43 | 44 | 45 | io.zipkin.java 46 | zipkin-server 47 | 2.11.5 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.cloud 60 | spring-cloud-dependencies 61 | ${spring-cloud.version} 62 | pom 63 | import 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-maven-plugin 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /zipkin/chainmonitor/src/main/java/priv/simon/chainmonitor/ChainmonitorApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.chainmonitor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import zipkin2.server.internal.EnableZipkinServer; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableZipkinServer 11 | public class ChainmonitorApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ChainmonitorApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /zipkin/chainmonitor/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8770 3 | 4 | spring: 5 | application: 6 | name: chainmonitor 7 | 8 | eureka: 9 | client: 10 | serviceUrl: 11 | defaultZone: http://localhost:8761/eureka/ 12 | management: 13 | metrics: 14 | web: 15 | server: 16 | auto-time-requests: false -------------------------------------------------------------------------------- /zipkin/chainmonitor/src/test/java/priv/simon/chainmonitor/ChainmonitorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.chainmonitor; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ChainmonitorApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | consumer 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | consumer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-openfeign 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-zipkin 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-dependencies 57 | ${spring-cloud.version} 58 | pom 59 | import 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.springframework.boot 68 | spring-boot-maven-plugin 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /zipkin/consumer/src/main/java/priv/simon/consumer/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 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.openfeign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableFeignClients 11 | public class ConsumerApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConsumerApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /zipkin/consumer/src/main/java/priv/simon/consumer/FeignService.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * Created by simon on 2018/9/25. 10 | */ 11 | @FeignClient(name = "provider") 12 | public interface FeignService { 13 | @RequestMapping(value = "/getBookByName",method = RequestMethod.GET) 14 | String getBookByName(@RequestParam("id") String id); 15 | } 16 | -------------------------------------------------------------------------------- /zipkin/consumer/src/main/java/priv/simon/consumer/HelloController.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * Created by simon on 2018/9/25. 10 | */ 11 | @RestController 12 | public class HelloController { 13 | @Autowired 14 | private FeignService feignService; 15 | 16 | @RequestMapping(value = "getBookName") 17 | public String getBookName(@RequestParam("id") String id){ 18 | return feignService.getBookByName(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /zipkin/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8801 3 | 4 | spring: 5 | application: 6 | name: consumer 7 | zipkin: 8 | base-url: http://chainmonitor/ 9 | sleuth: 10 | sampler: 11 | probability: 1.0 12 | eureka: 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /zipkin/consumer/src/test/java/priv/simon/consumer/ConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConsumerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin/eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | eureka 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-eureka-server 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /zipkin/eureka/src/main/java/priv/simon/eureka/EurekaApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /zipkin/eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /zipkin/eureka/src/test/java/priv/simon/eureka/EurekaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.eureka; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | priv.simon 7 | zipkin 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 链路监控 11 | 12 | 13 | eureka 14 | chainmonitor 15 | consumer 16 | provider 17 | 18 | -------------------------------------------------------------------------------- /zipkin/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | provider 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-zipkin 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-dependencies 54 | ${spring-cloud.version} 55 | pom 56 | import 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /zipkin/provider/src/main/java/priv/simon/provider/HelloController.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by simon on 2018/9/25. 9 | */ 10 | @RestController 11 | public class HelloController { 12 | @RequestMapping(value = "/getBookByName") 13 | public String getNameById(@RequestParam("id") String id){ 14 | String bookName = ""; 15 | switch (id){ 16 | case "1" : 17 | bookName = "Java"; 18 | break; 19 | case "2" : 20 | bookName = "C++"; 21 | break; 22 | default: 23 | bookName = "phython"; 24 | } 25 | return bookName; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zipkin/provider/src/main/java/priv/simon/provider/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /zipkin/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8800 3 | 4 | spring: 5 | application: 6 | name: provider 7 | zipkin: 8 | base-url: http://chainmonitor/ 9 | sleuth: 10 | sampler: 11 | probability: 1.0 12 | eureka: 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /zipkin/provider/src/test/java/priv/simon/provider/ProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin_mysql/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | .mvn 27 | mvnw.cmd 28 | mvnw -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | .mvn 27 | mvnw 28 | mvnw.cmd -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | chainmonitor 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | chainmonitor 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | 39 | io.zipkin.java 40 | zipkin-autoconfigure-ui 41 | 2.11.5 42 | 43 | 44 | 45 | io.zipkin.java 46 | zipkin-server 47 | 2.11.5 48 | 49 | 50 | io.zipkin.java 51 | zipkin-autoconfigure-storage-mysql 52 | 2.11.5 53 | 54 | 55 | io.zipkin.zipkin2 56 | zipkin-storage-mysql-v1 57 | 2.11.5 58 | 59 | 60 | org.jooq 61 | jooq 62 | 3.11.4 63 | 64 | 65 | mysql 66 | mysql-connector-java 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-jdbc 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-starter-test 75 | test 76 | 77 | 78 | 79 | org.apache.commons 80 | commons-dbcp2 81 | 2.3.0 82 | 83 | 84 | 85 | 86 | 87 | 88 | org.springframework.cloud 89 | spring-cloud-dependencies 90 | ${spring-cloud.version} 91 | pom 92 | import 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | org.springframework.boot 101 | spring-boot-maven-plugin 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/src/main/java/priv/simon/chainmonitor/ChainmonitorApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.chainmonitor; 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.context.annotation.Bean; 7 | import org.springframework.context.annotation.Primary; 8 | import zipkin2.server.internal.EnableZipkinServer; 9 | import zipkin2.storage.mysql.v1.MySQLStorage; 10 | 11 | import javax.sql.DataSource; 12 | 13 | @SpringBootApplication 14 | @EnableEurekaClient 15 | @EnableZipkinServer 16 | public class ChainmonitorApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ChainmonitorApplication.class, args); 20 | } 21 | 22 | // @Bean 23 | // public MySQLStorage mySQLStorage(DataSource datasource) { 24 | // return MySQLStorage.newBuilder().datasource(datasource).executor(Runnable::run).build(); 25 | // } 26 | } 27 | -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8770 3 | 4 | spring: 5 | application: 6 | name: chainmonitor 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/zipkin?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false 9 | username: root 10 | password: 123456 11 | driver-class-name: com.mysql.jdbc.Driver 12 | initialization-mode: always 13 | continue-on-error: true 14 | schema: classpath:/zipkin.sql 15 | dbcp2: 16 | #初始化连接:连接池启动时创建的初始化连接数量 17 | initial-size: 50 18 | #从连接池获取一个连接时,最大的等待时间,连接池会等待N毫秒,等待不到,则抛出异常 19 | max-wait-millis: 60000 20 | #最大空闲连接:连接池中容许保持空闲状态的最大连接数量,超过的空闲连接将被释放,如果设置为负数表示不限制 21 | max-idle: 100 22 | #通过这个池创建连接的默认自动提交状态。如果不设置,则setAutoCommit 方法将不被调用 23 | default-auto-commit: true 24 | #通过这个池创建连接的默认只读状态 25 | default-read-only: false 26 | #指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 27 | test-on-borrow: true 28 | type: org.apache.commons.dbcp2.BasicDataSource 29 | jpa: 30 | database: mysql 31 | show-sql: true 32 | hibernate: 33 | ddl-auto: update 34 | properties: 35 | hibernate: 36 | dialect: org.hibernate.dialect.MySQL5Dialect 37 | eureka: 38 | client: 39 | serviceUrl: 40 | defaultZone: http://localhost:8761/eureka/ 41 | management: 42 | metrics: 43 | web: 44 | server: 45 | auto-time-requests: false 46 | zipkin: 47 | storage: 48 | type: mysql 49 | -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/src/main/resources/zipkin.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS zipkin_spans ( 2 | `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', 3 | `trace_id` BIGINT NOT NULL, 4 | `id` BIGINT NOT NULL, 5 | `name` VARCHAR(255) NOT NULL, 6 | `parent_id` BIGINT, 7 | `debug` BIT(1), 8 | `start_ts` BIGINT COMMENT 'Span.timestamp(): epoch micros used for endTs query and to implement TTL', 9 | `duration` BIGINT COMMENT 'Span.duration(): micros used for minDuration and maxDuration query' 10 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 11 | 12 | ALTER TABLE zipkin_spans ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `id`) COMMENT 'ignore insert on duplicate'; 13 | ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`, `id`) COMMENT 'for joining with zipkin_annotations'; 14 | ALTER TABLE zipkin_spans ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTracesByIds'; 15 | ALTER TABLE zipkin_spans ADD INDEX(`name`) COMMENT 'for getTraces and getSpanNames'; 16 | ALTER TABLE zipkin_spans ADD INDEX(`start_ts`) COMMENT 'for getTraces ordering and range'; 17 | 18 | CREATE TABLE IF NOT EXISTS zipkin_annotations ( 19 | `trace_id_high` BIGINT NOT NULL DEFAULT 0 COMMENT 'If non zero, this means the trace uses 128 bit traceIds instead of 64 bit', 20 | `trace_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.trace_id', 21 | `span_id` BIGINT NOT NULL COMMENT 'coincides with zipkin_spans.id', 22 | `a_key` VARCHAR(255) NOT NULL COMMENT 'BinaryAnnotation.key or Annotation.value if type == -1', 23 | `a_value` BLOB COMMENT 'BinaryAnnotation.value(), which must be smaller than 64KB', 24 | `a_type` INT NOT NULL COMMENT 'BinaryAnnotation.type() or -1 if Annotation', 25 | `a_timestamp` BIGINT COMMENT 'Used to implement TTL; Annotation.timestamp or zipkin_spans.timestamp', 26 | `endpoint_ipv4` INT COMMENT 'Null when Binary/Annotation.endpoint is null', 27 | `endpoint_ipv6` BINARY(16) COMMENT 'Null when Binary/Annotation.endpoint is null, or no IPv6 address', 28 | `endpoint_port` SMALLINT COMMENT 'Null when Binary/Annotation.endpoint is null', 29 | `endpoint_service_name` VARCHAR(255) COMMENT 'Null when Binary/Annotation.endpoint is null' 30 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 31 | 32 | ALTER TABLE zipkin_annotations ADD UNIQUE KEY(`trace_id_high`, `trace_id`, `span_id`, `a_key`, `a_timestamp`) COMMENT 'Ignore insert on duplicate'; 33 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`, `span_id`) COMMENT 'for joining with zipkin_spans'; 34 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id_high`, `trace_id`) COMMENT 'for getTraces/ByIds'; 35 | ALTER TABLE zipkin_annotations ADD INDEX(`endpoint_service_name`) COMMENT 'for getTraces and getServiceNames'; 36 | ALTER TABLE zipkin_annotations ADD INDEX(`a_type`) COMMENT 'for getTraces'; 37 | ALTER TABLE zipkin_annotations ADD INDEX(`a_key`) COMMENT 'for getTraces'; 38 | ALTER TABLE zipkin_annotations ADD INDEX(`trace_id`, `span_id`, `a_key`) COMMENT 'for dependencies job'; 39 | 40 | CREATE TABLE IF NOT EXISTS zipkin_dependencies ( 41 | `day` DATE NOT NULL, 42 | `parent` VARCHAR(255) NOT NULL, 43 | `child` VARCHAR(255) NOT NULL, 44 | `call_count` BIGINT, 45 | `error_count` BIGINT 46 | ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED CHARACTER SET=utf8 COLLATE utf8_general_ci; 47 | 48 | ALTER TABLE zipkin_dependencies ADD UNIQUE KEY(`day`, `parent`, `child`); -------------------------------------------------------------------------------- /zipkin_mysql/chainmonitor/src/test/java/priv/simon/chainmonitor/ChainmonitorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.chainmonitor; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ChainmonitorApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin_mysql/consumer/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | .mvn 27 | mvnw.cmd 28 | mvnw -------------------------------------------------------------------------------- /zipkin_mysql/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | consumer 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | consumer 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-openfeign 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-zipkin 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.cloud 56 | spring-cloud-dependencies 57 | ${spring-cloud.version} 58 | pom 59 | import 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.springframework.boot 68 | spring-boot-maven-plugin 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /zipkin_mysql/consumer/src/main/java/priv/simon/consumer/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 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.openfeign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableEurekaClient 10 | @EnableFeignClients 11 | public class ConsumerApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConsumerApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /zipkin_mysql/consumer/src/main/java/priv/simon/consumer/FeignService.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * Created by simon on 2018/9/25. 10 | */ 11 | @FeignClient(name = "provider") 12 | public interface FeignService { 13 | @RequestMapping(value = "/getBookByName",method = RequestMethod.GET) 14 | String getBookByName(@RequestParam("id") String id); 15 | } 16 | -------------------------------------------------------------------------------- /zipkin_mysql/consumer/src/main/java/priv/simon/consumer/HelloController.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * Created by simon on 2018/9/25. 10 | */ 11 | @RestController 12 | public class HelloController { 13 | @Autowired 14 | private FeignService feignService; 15 | 16 | @RequestMapping(value = "getBookName") 17 | public String getBookName(@RequestParam("id") String id){ 18 | return feignService.getBookByName(id); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /zipkin_mysql/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8801 3 | 4 | spring: 5 | application: 6 | name: consumer 7 | zipkin: 8 | base-url: http://chainmonitor/ 9 | sleuth: 10 | sampler: 11 | probability: 1.0 12 | eureka: 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /zipkin_mysql/consumer/src/test/java/priv/simon/consumer/ConsumerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.consumer; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ConsumerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin_mysql/eureka/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | .mvn 27 | mvnw.cmd 28 | mvnw -------------------------------------------------------------------------------- /zipkin_mysql/eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | eureka 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-eureka-server 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-dependencies 46 | ${spring-cloud.version} 47 | pom 48 | import 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /zipkin_mysql/eureka/src/main/java/priv/simon/eureka/EurekaApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.eureka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class EurekaApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /zipkin_mysql/eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /zipkin_mysql/eureka/src/test/java/priv/simon/eureka/EurekaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.eureka; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /zipkin_mysql/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | priv.simon 7 | zipkin_mysql 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 链路监控 11 | 12 | 13 | eureka 14 | chainmonitor 15 | consumer 16 | provider 17 | 18 | -------------------------------------------------------------------------------- /zipkin_mysql/provider/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | .mvn 27 | mvnw.cmd 28 | mvnw -------------------------------------------------------------------------------- /zipkin_mysql/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | priv.simon 7 | provider 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | provider 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-zipkin 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.cloud 53 | spring-cloud-dependencies 54 | ${spring-cloud.version} 55 | pom 56 | import 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /zipkin_mysql/provider/src/main/java/priv/simon/provider/HelloController.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RequestParam; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * Created by simon on 2018/9/25. 9 | */ 10 | @RestController 11 | public class HelloController { 12 | @RequestMapping(value = "/getBookByName") 13 | public String getNameById(@RequestParam("id") String id){ 14 | String bookName = ""; 15 | switch (id){ 16 | case "1" : 17 | bookName = "Java"; 18 | break; 19 | case "2" : 20 | bookName = "C++"; 21 | break; 22 | default: 23 | bookName = "phython"; 24 | } 25 | return bookName; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /zipkin_mysql/provider/src/main/java/priv/simon/provider/ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /zipkin_mysql/provider/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8803 3 | 4 | spring: 5 | application: 6 | name: provider 7 | zipkin: 8 | base-url: http://chainmonitor/ 9 | sleuth: 10 | sampler: 11 | probability: 1.0 12 | eureka: 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /zipkin_mysql/provider/src/test/java/priv/simon/provider/ProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package priv.simon.provider; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ProviderApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------