├── .gitignore ├── README.assets └── image-20190730212117628.png ├── README.md ├── build.sh ├── cloud-eureka ├── Dockerfile ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── work │ │ │ └── eip │ │ │ └── example │ │ │ └── eureka │ │ │ └── CloudEurekaApplication.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── work │ └── eip │ └── example │ └── eureka │ └── CloudEurekaApplicationTests.java ├── db-example ├── Dockerfile ├── db-example.mwb ├── db-example.mwb.bak └── docker │ ├── init_sql │ ├── 01_create_schema.sql │ └── 02_init_book.sql │ └── my.cnf ├── docker-compose.yml ├── gateway-example ├── Dockerfile ├── README.md ├── docker │ └── entrypoint.sh ├── pom.xml └── src │ └── main │ ├── java │ └── work │ │ └── eip │ │ └── example │ │ └── cloud │ │ └── gateway │ │ ├── GateWayApplication.java │ │ ├── SentinelConfig.java │ │ ├── controller │ │ └── GatewayController.java │ │ └── example │ │ ├── GatewayConfig.java │ │ ├── RequestTimeFilter.java │ │ ├── RequestTimeGatewayFilterFactory.java │ │ └── TokenFilter.java │ └── resources │ ├── application-example.yml │ └── application.yml ├── myconf.env ├── svc-example ├── Dockerfile ├── README.md ├── mvnw ├── mvnw.cmd ├── package-lock.json ├── pom.xml └── src │ ├── main │ ├── java │ │ └── work │ │ │ └── eip │ │ │ └── example │ │ │ └── svc │ │ │ ├── SvcExampleApplication.java │ │ │ ├── base │ │ │ ├── AssertUtils.java │ │ │ ├── BaseDAO.java │ │ │ ├── BaseService.java │ │ │ ├── PaginationDTO.java │ │ │ ├── PaginationUtils.java │ │ │ ├── SnowFlakeService.java │ │ │ └── SvcExecption.java │ │ │ ├── book │ │ │ ├── BookController.java │ │ │ ├── BookCreateDTO.java │ │ │ ├── BookDTO.java │ │ │ ├── BookDao.java │ │ │ ├── BookDao.xml │ │ │ ├── BookEntity.java │ │ │ └── BookService.java │ │ │ └── config │ │ │ ├── PageHelperConfig.java │ │ │ └── Swagger2.java │ └── resources │ │ ├── application.yml │ │ └── logback-spring.xml │ └── test │ └── java │ └── work │ └── eip │ └── example │ └── svc │ └── questionaire │ └── SvcQuestionaireApplicationTests.java └── web-example ├── .gitignore ├── Dockerfile ├── README.md ├── babel.config.js ├── docker └── nginx.80.conf ├── package-lock.json ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ └── logo.png ├── components │ ├── BookCreate.vue │ └── BookList.vue ├── main.js ├── plugins │ └── element.js └── service.js └── vue.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-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 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | 31 | /*/*-logs/ 32 | /*/target/ 33 | -------------------------------------------------------------------------------- /README.assets/image-20190730212117628.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/README.assets/image-20190730212117628.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kuboard-example 2 | 3 | kuboard 的主要特点: 4 | * 面向运维场景的设计 5 | * 微服务分层显示 6 | * 关联到微服务上下文的监控 7 | 8 | 详细文档请参考 Kuboard 官网, 9 | [https://kuboard.cn](https://kuboard.cn) 10 | 11 | kuboard-example 完成部署后的效果如下所示: 12 | 13 |

14 | 在线演示 15 |

16 | 17 | ![image-20190730212117628](README.assets/image-20190730212117628.png) 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## db-example 4 | tag=eipsample/example-db-example 5 | 6 | cd ./db-example 7 | 8 | docker build -t $tag:latest . 9 | 10 | if test "$1" != ""; then 11 | docker push $tag:latest 12 | docker tag $tag:latest $tag:$1 13 | docker push $tag:$1 14 | fi 15 | 16 | cd .. 17 | 18 | 19 | ## svc-example 20 | tag=eipsample/example-svc-example 21 | 22 | cd ./svc-example 23 | 24 | mvn clean package -Dmaven.test.skip=true 25 | 26 | docker build -t $tag:latest . 27 | 28 | if test "$1" != ""; then 29 | docker push $tag:latest 30 | docker tag $tag:latest $tag:$1 31 | docker push $tag:$1 32 | fi 33 | 34 | cd .. 35 | 36 | 37 | ## gateway-example 38 | tag=eipsample/example-gateway-example 39 | 40 | cd ./gateway-example 41 | 42 | mvn clean package -Dmaven.test.skip=true 43 | 44 | docker build -t $tag:latest . 45 | 46 | if test "$1" != ""; then 47 | docker push $tag:latest 48 | docker tag $tag:latest $tag:$1 49 | docker push $tag:$1 50 | fi 51 | 52 | cd .. 53 | 54 | ## web-example 55 | tag=eipsample/example-web-example 56 | 57 | cd ./web-example 58 | 59 | npm install --registry=https://registry.npm.taobao.org 60 | npm run build 61 | 62 | docker build -t $tag:latest . 63 | 64 | if test "$1" != ""; then 65 | docker push $tag:latest 66 | docker tag $tag:latest $tag:$1 67 | docker push $tag:$1 68 | fi 69 | 70 | cd .. 71 | 72 | ## cloud-eureka 73 | tag=eipsample/example-cloud-eureka 74 | 75 | cd ./cloud-eureka 76 | 77 | mvn clean package -Dmaven.test.skip=true 78 | 79 | docker build -t $tag:latest . 80 | 81 | if test "$1" != ""; then 82 | docker push $tag:latest 83 | docker tag $tag:latest $tag:$1 84 | docker push $tag:$1 85 | fi 86 | 87 | -------------------------------------------------------------------------------- /cloud-eureka/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eipwork/jdk:1.0.0 2 | 3 | ARG JAR_FILE_NAME=cloud-eureka-0.0.1-SNAPSHOT.jar 4 | ARG PORT=9200 5 | ARG MANAGEMENT_PORT=9500 6 | 7 | COPY ./target/lib /eip-work/lib 8 | COPY ./target/$JAR_FILE_NAME.original /eip-work/app.jar 9 | 10 | ENV CLASSPATH=/eip-work/lib 11 | 12 | EXPOSE $PORT 13 | EXPOSE $MANAGEMENT_PORT 14 | 15 | WORKDIR /eip-work 16 | 17 | ENTRYPOINT ["java", "-jar", "/eip-work/app.jar"] -------------------------------------------------------------------------------- /cloud-eureka/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/cloud-eureka/README.md -------------------------------------------------------------------------------- /cloud-eureka/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 | -------------------------------------------------------------------------------- /cloud-eureka/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 | -------------------------------------------------------------------------------- /cloud-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | eip 8 | cloud-eureka 9 | work.eip.example.eureka.CloudEurekaApplication 10 | 1.8 11 | Greenwich.RELEASE 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.2.RELEASE 18 | 19 | 20 | ${work.eip.app.group} 21 | ${work.eip.app.projectName} 22 | 0.0.1-SNAPSHOT 23 | ${work.eip.app.projectName} 24 | 25 | 26 | 27 | org.springframework.cloud 28 | spring-cloud-starter-netflix-eureka-server 29 | 30 | 31 | at.twinformatics 32 | eureka-consul-adapter 33 | 1.3.0 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | test 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.cloud 46 | spring-cloud-dependencies 47 | ${spring-cloud.version} 48 | pom 49 | import 50 | 51 | 52 | 53 | 54 | 55 | 56 | spring-milestones 57 | Spring Milestones 58 | https://repo.spring.io/milestone 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-jar-plugin 71 | 72 | 73 | 74 | true 75 | lib/ 76 | ${work.eip.app.mainClass} 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-dependency-plugin 85 | 86 | 87 | copy-dependencies 88 | prepare-package 89 | 90 | copy-dependencies 91 | 92 | 93 | ${project.build.directory}/lib 94 | false 95 | false 96 | true 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /cloud-eureka/src/main/java/work/eip/example/eureka/CloudEurekaApplication.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.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 CloudEurekaApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(CloudEurekaApplication.class, args); 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /cloud-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: cloud-eureka 4 | 5 | server: 6 | port: 9200 7 | management: 8 | endpoints: 9 | web.exposure.include: metrics 10 | server: 11 | port: 9500 12 | 13 | eureka: 14 | instance: 15 | preferIpAddress: true 16 | client: 17 | register-with-eureka: false 18 | fetch-registry: false 19 | service-url: 20 | defaultZone: ${CLOUD_EUREKA_DEFAULT_ZONE} 21 | server: 22 | eviction-interval-timer-in-ms: 60000 23 | enable-self-preservation: false 24 | -------------------------------------------------------------------------------- /cloud-eureka/src/test/java/work/eip/example/eureka/CloudEurekaApplicationTests.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.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 CloudEurekaApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /db-example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eipwork/mysql:5.7.26-1.1.11 2 | 3 | LABEL maintainer="shaohq@foxmail.com" 4 | 5 | #把数据库初始化数据的文件复制到工作目录下 6 | RUN mv /etc/my.cnf /etc/my.cnf.backup 7 | COPY docker/my.cnf /etc/my.cnf 8 | COPY docker/init_sql/*.sql /init_sql/ 9 | 10 | EXPOSE 3306 11 | EXPOSE 9104 12 | 13 | ENV ENABLE_EUREKA_CLIENT=TRUE 14 | ENV eureka.name=db-example 15 | ENV eureka.port=80 16 | ENV eureka.management.port=9104 17 | ENV eureka.serviceUrl.default=http://monitor-eureka:9000/eureka -------------------------------------------------------------------------------- /db-example/db-example.mwb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/db-example/db-example.mwb -------------------------------------------------------------------------------- /db-example/db-example.mwb.bak: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/db-example/db-example.mwb.bak -------------------------------------------------------------------------------- /db-example/docker/init_sql/01_create_schema.sql: -------------------------------------------------------------------------------- 1 | -- MySQL Script generated by MySQL Workbench 2 | -- Fri Jul 12 23:05:46 2019 3 | -- Model: New Model Version: 1.0 4 | -- MySQL Workbench Forward Engineering 5 | 6 | SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; 7 | SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; 8 | SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; 9 | 10 | -- ----------------------------------------------------- 11 | -- Schema eip_db_example 12 | -- ----------------------------------------------------- 13 | 14 | -- ----------------------------------------------------- 15 | -- Schema eip_db_example 16 | -- ----------------------------------------------------- 17 | CREATE SCHEMA IF NOT EXISTS `eip_db_example` DEFAULT CHARACTER SET utf8 ; 18 | USE `eip_db_example` ; 19 | 20 | -- ----------------------------------------------------- 21 | -- Table `eip_db_example`.`book` 22 | -- ----------------------------------------------------- 23 | CREATE TABLE IF NOT EXISTS `eip_db_example`.`book` ( 24 | `id` BIGINT(19) NOT NULL, 25 | `name` VARCHAR(45) NULL, 26 | `author` VARCHAR(45) NULL, 27 | `sn` VARCHAR(45) NULL, 28 | `create_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, 29 | `update_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 30 | PRIMARY KEY (`id`)) 31 | ENGINE = InnoDB; 32 | 33 | CREATE USER 'eip_user' IDENTIFIED BY '1qaz2wsx'; 34 | 35 | GRANT ALL ON `eip_db_example`.* TO 'eip_user'; 36 | 37 | SET SQL_MODE=@OLD_SQL_MODE; 38 | SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; 39 | SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; 40 | -------------------------------------------------------------------------------- /db-example/docker/init_sql/02_init_book.sql: -------------------------------------------------------------------------------- 1 | USE `eip_db_example` ; 2 | SET NAMES utf8mb4; 3 | SET FOREIGN_KEY_CHECKS = 0; 4 | 5 | begin; 6 | 7 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641015112482816, 'fff', 'xfff', 'ddd', '2019-07-13 00:03:57', '2019-07-13 00:03:57'); 8 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641016047026176, 'xxx', 'xxx', 'xxx', '2019-07-13 00:04:01', '2019-07-13 00:04:01'); 9 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641017217236992, 'aaa', 'aaa', 'aaa', '2019-07-13 00:04:05', '2019-07-13 00:04:05'); 10 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641018462158848, 'eeeeee', 'eee', 'eee', '2019-07-13 00:04:10', '2019-07-13 00:04:10'); 11 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641019647836160, 'ddd', 'ddd', 'ddd', '2019-07-13 00:04:14', '2019-07-13 00:04:14'); 12 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641020919758848, 'qqq', 'qqq', 'qqq', '2019-07-13 00:04:19', '2019-07-13 00:04:19'); 13 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641021989568512, 'www', 'www', 'www', '2019-07-13 00:04:23', '2019-07-13 00:04:23'); 14 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641023605948416, 'zzz', 'zzzz', 'zzz', '2019-07-13 00:04:30', '2019-07-13 00:04:30'); 15 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641027053404160, 'ggg', 'ggg', 'ggg', '2019-07-13 00:04:43', '2019-07-13 00:04:43'); 16 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641028536090624, 'ttt', 'ttt', 'ttt', '2019-07-13 00:04:48', '2019-07-13 00:04:48'); 17 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641030054690816, 'bbb', 'bbb', 'bbb', '2019-07-13 00:04:54', '2019-07-13 00:04:54'); 18 | INSERT INTO `book`(`id`, `name`, `author`, `sn`, `create_time`, `update_time`) VALUES (2641032248573952, 'hhh', 'hhh', 'hhh', '2019-07-13 00:05:02', '2019-07-13 00:05:02'); 19 | 20 | commit; -------------------------------------------------------------------------------- /db-example/docker/my.cnf: -------------------------------------------------------------------------------- 1 | # Default options are read from the following files in the given order: 2 | # /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf 3 | # 该配置文件覆盖 mysql 官方docker镜像默认配置文件路径/etc/my.cnf 4 | 5 | [mysqld] 6 | # 7 | # Remove leading # and set to the amount of RAM for the most important data 8 | # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. 9 | # innodb_buffer_pool_size = 128M 10 | # 11 | # Remove leading # to turn on a very important data integrity option: logging 12 | # changes to the binary log between backups. 13 | # log_bin 14 | 15 | # Remove leading # to set options mainly useful for reporting servers. 16 | # The server defaults are faster for transactions and fast SELECTs. 17 | # Adjust sizes as needed, experiment to find the optimal values. 18 | # join_buffer_size = 128M 19 | # sort_buffer_size = 2M 20 | # read_rnd_buffer_size = 2M 21 | skip-host-cache 22 | skip-name-resolve 23 | datadir=/var/lib/mysql 24 | socket=/var/lib/mysql/mysql.sock 25 | secure-file-priv=/var/lib/mysql-files 26 | user=mysql 27 | 28 | default-time_zone='+8:00' 29 | 30 | # Disabling symbolic-links is recommended to prevent assorted security risks 31 | symbolic-links=0 32 | 33 | log-error=/var/log/mysqld.log 34 | pid-file=/var/run/mysqld/mysqld.pid 35 | 36 | slow_query_log=ON #开启慢日志 37 | slow_query_log_file=/var/log/mysql-slow.log #日志存放位置 38 | long_query_time=2 #超时时间1秒(超过1秒就会被记录下来) -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | db-example: 4 | image: eipwork/example-db-example:latest 5 | environment: 6 | MYSQL_ROOT_PASSWORD: x87hxpE36Js%l 7 | volumes: 8 | - eip-db-example:/var/lib/mysql 9 | ports: 10 | - "8806:3306" 11 | 12 | volumes: 13 | eip-db-example: 14 | driver: local -------------------------------------------------------------------------------- /gateway-example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eipwork/jdk:1.0.0 2 | 3 | ARG JAR_FILE_NAME=gateway-0.0.1-SNAPSHOT.jar 4 | ARG PORT=9201 5 | ARG MANAGEMENT_PORT=9001 6 | 7 | EXPOSE $PORT 8 | EXPOSE $MANAGEMENT_PORT 9 | 10 | WORKDIR /eip 11 | COPY ./target/$JAR_FILE_NAME $JAR_FILE_NAME 12 | COPY ./docker/entrypoint.sh /entrypoint_gateway.sh 13 | 14 | RUN chmod +x /entrypoint_gateway.sh 15 | 16 | ENV JAR_FILE_NAME=$JAR_FILE_NAME 17 | 18 | CMD ["/entrypoint_gateway.sh"] -------------------------------------------------------------------------------- /gateway-example/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/gateway-example/README.md -------------------------------------------------------------------------------- /gateway-example/docker/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export JAR_FILE_RENAME="gateway-$SPRING_PROFILES_ACTIVE.jar" 4 | export PINPOINT_APP_NAME="gateway-$SPRING_PROFILES_ACTIVE" 5 | 6 | echo "pinpoint does not support spring cloud gateway, https://github.com/naver/pinpoint/issues/5267" 7 | sed -i "/profiler.entrypoint=/ s/=.*/=com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter.filter/" /pinpoint-agent/pinpoint.config 8 | 9 | /entrypoint.sh 10 | -------------------------------------------------------------------------------- /gateway-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | eip 8 | gateway 9 | work.eip.example.cloud.gateway.GateWayApplication 10 | 1.8 11 | Greenwich.RELEASE 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.2.RELEASE 18 | 19 | ${work.eip.app.group} 20 | ${work.eip.app.projectName} 21 | 0.0.1-SNAPSHOT 22 | ${work.eip.app.projectName} 23 | 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-gateway 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-netflix-eureka-client 40 | 41 | 42 | io.micrometer 43 | micrometer-registry-prometheus 44 | 45 | 46 | com.alibaba.csp 47 | sentinel-spring-cloud-gateway-adapter 48 | 1.6.0 49 | 50 | 51 | com.alibaba.csp 52 | sentinel-transport-simple-http 53 | 1.6.0 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.cloud 61 | spring-cloud-dependencies 62 | ${spring-cloud.version} 63 | pom 64 | import 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.boot 73 | spring-boot-maven-plugin 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/GateWayApplication.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * @Author: colin 9 | * @Date: 2019/2/22 11:26 10 | * @Description: 11 | * @Version: V1.0 12 | */ 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | public class GateWayApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(GateWayApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/SentinelConfig.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway; 2 | 3 | import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule; 4 | import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager; 5 | import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter; 6 | import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.ObjectProvider; 9 | import org.springframework.cloud.gateway.filter.GlobalFilter; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.core.Ordered; 13 | import org.springframework.core.annotation.Order; 14 | import org.springframework.http.codec.ServerCodecConfigurer; 15 | import org.springframework.web.reactive.result.view.ViewResolver; 16 | 17 | import javax.annotation.PostConstruct; 18 | import java.util.Collections; 19 | import java.util.HashSet; 20 | import java.util.List; 21 | import java.util.Set; 22 | 23 | @Configuration 24 | @Slf4j 25 | public class SentinelConfig { 26 | 27 | private List viewResolvers; 28 | private ServerCodecConfigurer serverCodecConfigurer; 29 | 30 | public SentinelConfig(ObjectProvider> viewResolversProvider, 31 | ServerCodecConfigurer serverCodecConfigurer) { 32 | this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList); 33 | this.serverCodecConfigurer = serverCodecConfigurer; 34 | } 35 | 36 | /** 37 | * 配置SentinelGatewayBlockExceptionHandler,限流后异常处理 38 | * @return 39 | */ 40 | @Bean 41 | @Order(Ordered.HIGHEST_PRECEDENCE) 42 | public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() { 43 | return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer); 44 | } 45 | 46 | /** 47 | * 配置SentinelGatewayFilter 48 | * @return 49 | */ 50 | @Bean 51 | @Order(-1) 52 | public GlobalFilter sentinelGatewayFilter() { 53 | return new SentinelGatewayFilter(); 54 | } 55 | 56 | @PostConstruct 57 | public void doInit() { 58 | initGatewayRules(); 59 | } 60 | 61 | /** 62 | * 配置限流规则 63 | */ 64 | private void initGatewayRules() { 65 | Set rules = new HashSet<>(); 66 | rules.add(new GatewayFlowRule("path_route") 67 | .setCount(1) // 限流阈值 68 | .setIntervalSec(1) // 统计时间窗口,单位是秒,默认是 1 秒 69 | ); 70 | GatewayRuleManager.loadRules(rules); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/controller/GatewayController.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway.controller; 2 | 3 | import org.springframework.web.bind.annotation.RequestMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | import reactor.core.publisher.Mono; 6 | 7 | /** 8 | * @Author: colin 9 | * @Date: 2019/2/22 13:35 10 | * @Description: 11 | * @Version: V1.0 12 | */ 13 | @RestController 14 | public class GatewayController { 15 | 16 | @RequestMapping("/fallback") 17 | public Mono fallback() { 18 | return Mono.just("fallback"); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/example/GatewayConfig.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | 8 | 9 | @Profile("example") 10 | @Configuration 11 | @Slf4j 12 | public class GatewayConfig { 13 | 14 | @Bean 15 | public TokenFilter tokenFilter(){ 16 | return new TokenFilter(); 17 | } 18 | 19 | @Bean 20 | public RequestTimeGatewayFilterFactory elapsedGatewayFilterFactory() { 21 | log.info("profile example"); 22 | return new RequestTimeGatewayFilterFactory(); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/example/RequestTimeFilter.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.web.server.ServerWebExchange; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @Author: colin 12 | * @Date: 2019/2/25 19:10 13 | * @Description: 自定义过滤器 14 | * @Version: V1.0 15 | */ 16 | @Slf4j 17 | public class RequestTimeFilter implements GatewayFilter, Ordered { 18 | 19 | private static final String REQUEST_TIME_BEGIN = "requestTimeBegin"; 20 | 21 | @Override 22 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 23 | if (log.isInfoEnabled()) { 24 | log.info("Profile example"); 25 | } 26 | exchange.getAttributes().put(REQUEST_TIME_BEGIN, System.currentTimeMillis()); 27 | return chain.filter(exchange).then( 28 | Mono.fromRunnable(() -> { 29 | Long startTime = exchange.getAttribute(REQUEST_TIME_BEGIN); 30 | if (startTime != null) { 31 | log.info(exchange.getRequest().getURI().getRawPath() + ": " + (System.currentTimeMillis() - startTime) + "ms"); 32 | } 33 | }) 34 | ); 35 | } 36 | 37 | /** 38 | * 给过滤器设定优先级别的,值越大则优先级越低 39 | * @return 40 | */ 41 | @Override 42 | public int getOrder() { 43 | return 0; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/example/RequestTimeGatewayFilterFactory.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilter; 5 | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; 6 | import reactor.core.publisher.Mono; 7 | 8 | import java.util.Arrays; 9 | import java.util.List; 10 | 11 | /** 12 | * @Author: colin 13 | * @Date: 2019/2/26 01:11 14 | * @Description: 自定义过滤器工厂 15 | * @Version: V1.0 16 | */ 17 | @Slf4j 18 | public class RequestTimeGatewayFilterFactory extends AbstractGatewayFilterFactory { 19 | 20 | private static final String REQUEST_TIME_BEGIN = "requestTimeBegin"; 21 | private static final String KEY = "withParams"; 22 | 23 | @Override 24 | public List shortcutFieldOrder() { 25 | return Arrays.asList(KEY); 26 | } 27 | 28 | public RequestTimeGatewayFilterFactory() { 29 | super(Config.class); 30 | } 31 | 32 | @Override 33 | public GatewayFilter apply(Config config) { 34 | return (exchange, chain) -> { 35 | exchange.getAttributes().put(REQUEST_TIME_BEGIN, System.currentTimeMillis()); 36 | return chain.filter(exchange).then( 37 | Mono.fromRunnable(() -> { 38 | Long startTime = exchange.getAttribute(REQUEST_TIME_BEGIN); 39 | if (startTime != null) { 40 | StringBuilder sb = new StringBuilder(exchange.getRequest().getURI().getRawPath()) 41 | .append(": ") 42 | .append(System.currentTimeMillis() - startTime) 43 | .append("ms"); 44 | if (config.isWithParams()) { 45 | sb.append(" params:").append(exchange.getRequest().getQueryParams()); 46 | } 47 | log.info(sb.toString()); 48 | } 49 | }) 50 | ); 51 | }; 52 | } 53 | 54 | /** 55 | * 静态内部类,接收参数。判断是否打印请求参数 56 | */ 57 | public static class Config { 58 | private boolean withParams; 59 | public boolean isWithParams() { 60 | return withParams; 61 | } 62 | public void setWithParams(boolean withParams) { 63 | this.withParams = withParams; 64 | } 65 | 66 | } 67 | } 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /gateway-example/src/main/java/work/eip/example/cloud/gateway/example/TokenFilter.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.cloud.gateway.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.cloud.gateway.filter.GatewayFilterChain; 5 | import org.springframework.cloud.gateway.filter.GlobalFilter; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.web.server.ServerWebExchange; 8 | import reactor.core.publisher.Mono; 9 | 10 | /** 11 | * @Author: colin 12 | * @Date: 2019/2/26 09:14 13 | * @Description: 14 | * @Version: V1.0 15 | */ 16 | @Slf4j 17 | public class TokenFilter implements GlobalFilter, Ordered { 18 | 19 | @Override 20 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { 21 | // String token = exchange.getRequest().getQueryParams().getFirst("token"); 22 | // if (token == null || token.isEmpty()) { 23 | // log.info( "token is empty..." ); 24 | // exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED); 25 | // return exchange.getResponse().setComplete(); 26 | // } 27 | return chain.filter(exchange); 28 | } 29 | 30 | @Override 31 | public int getOrder() { 32 | return -100; 33 | } 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /gateway-example/src/main/resources/application-example.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 9201 4 | management: 5 | server: 6 | port: 9001 7 | 8 | spring: 9 | application: 10 | name: gateway-example 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /gateway-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | maxHttpHeaderSize: 102400 4 | management: 5 | endpoint: 6 | gateway: 7 | enabled: true 8 | endpoints: 9 | web: 10 | exposure: 11 | include: gateway, prometheus 12 | 13 | spring: 14 | cloud: 15 | gateway: 16 | discovery: 17 | locator: 18 | enabled: true 19 | lower-case-service-id: true 20 | routes: 21 | # AfterRoutePredicateFactory: 请求时间满足在配置时间之后 22 | # BeforeRoutePredicateFactory: 请求时间满足在配置时间之前 23 | # BetweenRoutePredicateFactory: 请求时间满足在配置时间之间 24 | 25 | eureka: 26 | instance: 27 | preferIpAddress: true 28 | lease-renewal-interval-in-seconds: 5 29 | lease-expiration-duration-in-seconds: 15 30 | client: 31 | register-with-eureka: true 32 | registry-fetch-interval-seconds: 50 33 | serviceUrl: 34 | defaultZone: ${CLOUD_EUREKA_DEFAULT_ZONE} 35 | 36 | 37 | -------------------------------------------------------------------------------- /myconf.env: -------------------------------------------------------------------------------- 1 | DB_HOST=localhost 2 | #DB_HOST=localhost 3 | 4 | CLOUD_EUREKA_DEFAULT_ZONE=http://localhost:9200/eureka/ 5 | eureka.instance.lease-renewal-interval-in-seconds=5 6 | eureka.instance.lease-expiration-duration-in-seconds=15 7 | 8 | DB_EXAMPLE_URL=jdbc:mysql://${DB_HOST}:8806/eip_db_example?characterEncoding=utf8&useSSL=false 9 | DB_EXAMPLE_USERNAME=eip_user 10 | DB_EXAMPLE_PASSWORD=1qaz2wsx 11 | 12 | snowflake.dataCenterId=1 13 | 14 | logging.level.work.eip.example.svc=DEBUG 15 | csp.sentinel.dashboard.server=localhost:8080 -------------------------------------------------------------------------------- /svc-example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eipwork/jdk:1.0.0 2 | 3 | ARG JAR_FILE_NAME=svc-example-0.0.1-SNAPSHOT.jar 4 | ARG PORT=9301 5 | ARG MANAGEMENT_PORT=9401 6 | 7 | EXPOSE $PORT 8 | EXPOSE $MANAGEMENT_PORT 9 | 10 | WORKDIR /eip 11 | COPY ./target/$JAR_FILE_NAME $JAR_FILE_NAME 12 | 13 | ENV JAR_FILE_NAME=$JAR_FILE_NAME 14 | ENV PINPOINT_APP_NAME=svc-example 15 | 16 | -------------------------------------------------------------------------------- /svc-example/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/svc-example/README.md -------------------------------------------------------------------------------- /svc-example/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 | -------------------------------------------------------------------------------- /svc-example/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 | -------------------------------------------------------------------------------- /svc-example/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "lockfileVersion": 1 3 | } 4 | -------------------------------------------------------------------------------- /svc-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | eip-example 8 | svc-example 9 | work.eip.example.svc.SvcExampleApplication 10 | 1.8 11 | Greenwich.RELEASE 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.1.2.RELEASE 18 | 19 | 20 | ${work.eip.app.group} 21 | ${work.eip.app.projectName} 22 | 0.0.1-SNAPSHOT 23 | ${work.eip.app.projectName} 24 | 25 | 26 | 27 | net.sourceforge.jexcelapi 28 | jxl 29 | 2.6.10 30 | 31 | 32 | com.github.pagehelper 33 | pagehelper-spring-boot-starter 34 | 1.2.3 35 | 36 | 37 | org.mybatis.spring.boot 38 | mybatis-spring-boot-starter 39 | 2.0.0 40 | 41 | 42 | io.jsonwebtoken 43 | jjwt 44 | 0.9.0 45 | 46 | 47 | org.projectlombok 48 | lombok 49 | true 50 | 51 | 52 | mysql 53 | mysql-connector-java 54 | runtime 55 | 56 | 57 | com.alibaba 58 | druid 59 | 1.1.0 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-starter-web 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-actuator 68 | 69 | 70 | org.springframework.cloud 71 | spring-cloud-starter-netflix-eureka-client 72 | 73 | 74 | org.springframework.cloud 75 | spring-cloud-alibaba-sentinel 76 | 0.9.0.RELEASE 77 | 78 | 79 | org.springframework.cloud 80 | spring-cloud-starter-openfeign 81 | 82 | 83 | com.alibaba 84 | fastjson 85 | 1.2.37 86 | 87 | 88 | org.apache.poi 89 | poi 90 | 3.14 91 | 92 | 93 | org.apache.poi 94 | poi-ooxml 95 | 3.14 96 | 97 | 98 | org.springframework.boot 99 | spring-boot-configuration-processor 100 | true 101 | 102 | 103 | org.springframework.boot 104 | spring-boot-starter-test 105 | test 106 | 107 | 108 | 109 | io.springfox 110 | springfox-swagger2 111 | 2.9.2 112 | 113 | 114 | mapstruct 115 | org.mapstruct 116 | 117 | 118 | 119 | 120 | io.springfox 121 | springfox-swagger-ui 122 | 2.9.2 123 | 124 | 125 | io.micrometer 126 | micrometer-registry-prometheus 127 | 1.1.4 128 | 129 | 130 | 131 | 132 | 133 | 134 | org.springframework.cloud 135 | spring-cloud-dependencies 136 | ${spring-cloud.version} 137 | pom 138 | import 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | src/main/resources 147 | 148 | 149 | src/main/java 150 | 151 | **/*.xml 152 | 153 | false 154 | 155 | 156 | 157 | 158 | org.springframework.boot 159 | spring-boot-maven-plugin 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/SvcExampleApplication.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | import java.util.Properties; 11 | 12 | 13 | @SpringBootApplication 14 | @EnableDiscoveryClient 15 | @MapperScan("work.eip.example.svc.**") 16 | public class SvcExampleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(SvcExampleApplication.class, args); 20 | } 21 | 22 | @Bean 23 | public PageHelper pageHelper() { 24 | System.out.println("MyBatisConfiguration.pageHelper()"); 25 | PageHelper pageHelper = new PageHelper(); 26 | Properties p = new Properties(); 27 | p.setProperty("offsetAsPageNum", "true"); 28 | p.setProperty("rowBoundsWithCount", "true"); 29 | p.setProperty("reasonable", "true"); 30 | pageHelper.setProperties(p); 31 | return pageHelper; 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/AssertUtils.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | public class AssertUtils { 4 | 5 | public static void assertTrue(boolean b, String errorMessage) { 6 | if (!b) { 7 | throw new SvcExecption(errorMessage); 8 | } 9 | } 10 | 11 | public static void assertNotNull(Object o, String errorMessage) { 12 | if (o == null) { 13 | throw new SvcExecption(errorMessage); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/BaseDAO.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | @Repository 6 | public interface BaseDAO { 7 | 8 | public long insert(Entity pdLegalEntity); 9 | 10 | public long deleteById(long id); 11 | 12 | public Entity findById(long id); 13 | 14 | public long update(Entity pdLegalEntity); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/BaseService.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.BeanUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.lang.reflect.Method; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @Slf4j 13 | abstract public class BaseService> { 14 | 15 | @Autowired 16 | protected SnowFlakeService snowFlakeService; 17 | 18 | @Autowired 19 | protected DAO dao; 20 | 21 | protected abstract Entity instanciateEntity(); 22 | 23 | protected abstract DTO instanciateDTO(); 24 | 25 | public long create(CreateDTO createDTO, String defaultStatus) { 26 | Entity entity = instanciateEntity(); 27 | BeanUtils.copyProperties(createDTO, entity); 28 | long id = snowFlakeService.nextId(); 29 | setId(entity, id); 30 | setStatus(entity, defaultStatus); 31 | log.debug("插入记录: " + entity); 32 | dao.insert(entity); 33 | return id; 34 | } 35 | 36 | public void delete(Long id) { 37 | AssertUtils.assertTrue(id != null, "id 不能为空"); 38 | long modified = dao.deleteById(id); 39 | AssertUtils.assertTrue(modified == 1, "主键未找到: " + id); 40 | } 41 | 42 | public DTO show(Long id) { 43 | AssertUtils.assertTrue(id != null, "id 不能为空"); 44 | DTO dto = instanciateDTO(); 45 | Entity entity = dao.findById(id); 46 | log.debug("查询结果: " + entity); 47 | AssertUtils.assertNotNull(entity, "主键未找到: " + id); 48 | BeanUtils.copyProperties(entity, dto); 49 | return dto; 50 | } 51 | 52 | protected List convertToDTOList(List entities) { 53 | List dtoList = new ArrayList<>(); 54 | entities.forEach(entity -> { 55 | DTO dto = instanciateDTO(); 56 | BeanUtils.copyProperties(entity, dto); 57 | dtoList.add(dto); 58 | }); 59 | return dtoList; 60 | } 61 | 62 | public void modify(Long id, CreateDTO createDTO) { 63 | AssertUtils.assertTrue(id != null, "id 不能为空"); 64 | AssertUtils.assertNotNull(createDTO, "被修改的对象不能为空"); 65 | Entity entity = instanciateEntity(); 66 | setId(entity, id); 67 | BeanUtils.copyProperties(createDTO, entity); 68 | log.debug("修改记录: " + entity); 69 | long modified = dao.update(entity); 70 | AssertUtils.assertTrue(modified == 1, "主键未找到: " + id); 71 | } 72 | 73 | public void modifyStatus(Long id, String status) { 74 | AssertUtils.assertTrue(id != null, "id 不能为空"); 75 | Entity entity = instanciateEntity(); 76 | setId(entity, id); 77 | setStatus(entity, status); 78 | log.debug("修改状态: " + entity); 79 | long modified = dao.update(entity); 80 | AssertUtils.assertTrue(modified == 1, "主键未找到: " + id); 81 | } 82 | 83 | private void setId(Entity entity, long id) { 84 | try { 85 | Class klass = entity.getClass(); 86 | Method setId = klass.getMethod("setId", long.class); 87 | setId.invoke(entity, id); 88 | } catch (NoSuchMethodException e) { 89 | throw new SvcExecption(e.getMessage()); 90 | } catch (IllegalAccessException e) { 91 | throw new SvcExecption(e.getMessage()); 92 | } catch (InvocationTargetException e) { 93 | throw new SvcExecption(e.getMessage()); 94 | } 95 | } 96 | 97 | private void setStatus(Entity entity, String status) { 98 | try { 99 | Class klass = entity.getClass(); 100 | Method setStatus = klass.getMethod("setStatus", String.class); 101 | setStatus.invoke(entity, status); 102 | } catch (NoSuchMethodException e) { 103 | throw new SvcExecption(e.getMessage()); 104 | } catch (IllegalAccessException e) { 105 | throw new SvcExecption(e.getMessage()); 106 | } catch (InvocationTargetException e) { 107 | throw new SvcExecption(e.getMessage()); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/PaginationDTO.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class PaginationDTO { 9 | private int pageSize; 10 | private int pageNum; 11 | private long total; 12 | private List list; 13 | } 14 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/PaginationUtils.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | import com.github.pagehelper.Page; 4 | 5 | import java.util.List; 6 | 7 | public class PaginationUtils { 8 | 9 | public static PaginationDTO wrapPaginationDTO(Page page, List list) { 10 | 11 | PaginationDTO paginationDTO = new PaginationDTO(); 12 | paginationDTO.setList(list); 13 | paginationDTO.setPageNum(page.getPageNum()); 14 | paginationDTO.setPageSize(page.getPageSize()); 15 | paginationDTO.setTotal(page.getTotal()); 16 | return paginationDTO; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/SnowFlakeService.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Service; 5 | 6 | @Service 7 | public class SnowFlakeService { 8 | /** 9 | * 起始的时间戳 1552872764461 2019-03-18 09:32:44 10 | */ 11 | private final static long START_STMP = 1552872764461L; 12 | 13 | /** 14 | * 每一部分占用的位数 15 | */ 16 | private final static long SEQUENCE_BIT = 8; //序列号占用的位数 17 | private final static long MACHINE_BIT = 6; //机器标识占用的位数 18 | private final static long DATACENTER_BIT = 4;//数据中心占用的位数 19 | 20 | /** 21 | * 每一部分的最大值 22 | */ 23 | private final static long MAX_DATACENTER_NUM = -1L ^ (-1L << DATACENTER_BIT); 24 | private final static long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT); 25 | private final static long MAX_SEQUENCE = -1L ^ (-1L << SEQUENCE_BIT); 26 | 27 | /** 28 | * 每一部分向左的位移 29 | */ 30 | private final static long MACHINE_LEFT = SEQUENCE_BIT; 31 | private final static long DATACENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT; 32 | private final static long TIMESTMP_LEFT = DATACENTER_LEFT + DATACENTER_BIT; 33 | 34 | @Value("${snowflake.dataCenterId}") 35 | private long dataCenterId; //数据中心 36 | private long machineId; //机器标识 37 | private long sequence = 0L; //序列号 38 | private long lastStmp = -1L;//上一次时间戳 39 | 40 | public void setDataCenterId(long dataCenterId) { 41 | if (this.dataCenterId > MAX_DATACENTER_NUM || this.dataCenterId < 0) { 42 | throw new IllegalArgumentException("dataCenterId can't be greater than MAX_DATACENTER_NUM or less than 0"); 43 | } 44 | this.dataCenterId = this.dataCenterId; 45 | } 46 | 47 | public void setMachineId(long machineId) { 48 | if (machineId > MAX_MACHINE_NUM || machineId < 0) { 49 | throw new IllegalArgumentException("machineId can't be greater than MAX_MACHINE_NUM or less than 0"); 50 | } 51 | this.machineId = machineId; 52 | } 53 | 54 | /** 55 | * 产生下一个ID 56 | * 57 | * @return 58 | */ 59 | public synchronized long nextId() { 60 | long currStmp = getNewstmp(); 61 | if (currStmp < lastStmp) { 62 | throw new RuntimeException("Clock moved backwards. Refusing to generate id"); 63 | } 64 | 65 | if (currStmp == lastStmp) { 66 | //相同毫秒内,序列号自增 67 | sequence = (sequence + 1) & MAX_SEQUENCE; 68 | //同一毫秒的序列数已经达到最大 69 | if (sequence == 0L) { 70 | currStmp = getNextMill(); 71 | } 72 | } else { 73 | //不同毫秒内,序列号置为0 74 | sequence = 0L; 75 | } 76 | 77 | lastStmp = currStmp; 78 | 79 | return (currStmp - START_STMP) << TIMESTMP_LEFT //时间戳部分 80 | | dataCenterId << DATACENTER_LEFT //数据中心部分 81 | | machineId << MACHINE_LEFT //机器标识部分 82 | | sequence; //序列号部分 83 | } 84 | 85 | private long getNextMill() { 86 | long mill = getNewstmp(); 87 | while (mill <= lastStmp) { 88 | mill = getNewstmp(); 89 | } 90 | return mill; 91 | } 92 | 93 | private long getNewstmp() { 94 | return System.currentTimeMillis(); 95 | } 96 | 97 | public static void main(String[] args) { 98 | SnowFlakeService snowFlake = new SnowFlakeService(); 99 | snowFlake.setDataCenterId(2); 100 | snowFlake.setMachineId(3); 101 | for (int i = 0; i < (1 << 12); i++) { 102 | System.out.println(snowFlake.nextId()); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/base/SvcExecption.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.base; 2 | 3 | public class SvcExecption extends RuntimeException { 4 | 5 | public SvcExecption(String msg) { 6 | super(msg); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookController.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import com.github.pagehelper.Page; 4 | import com.github.pagehelper.PageHelper; 5 | import io.swagger.annotations.*; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | import work.eip.example.svc.base.PaginationDTO; 9 | import work.eip.example.svc.base.PaginationUtils; 10 | 11 | import javax.validation.Valid; 12 | 13 | /** 14 | * @Author: colin 15 | * @Date: 2019/4/26 10:04 16 | * @Description: 17 | * @Version: V1.0 18 | */ 19 | @RestController 20 | @RequestMapping("/book") 21 | @Api(description = "书目管理") 22 | @ApiResponses( 23 | @ApiResponse(code = 500,message = "INTERNAL_SERVER_ERROR") 24 | ) 25 | public class BookController { 26 | 27 | @Autowired 28 | private BookService bookService; 29 | 30 | @GetMapping("/list") 31 | @ApiOperation("书目列表") 32 | public PaginationDTO list( 33 | @ApiParam("起始页") @RequestParam(value = "pageNum",required = false, defaultValue = "1") Integer pageNum, 34 | @ApiParam("每页大小") @RequestParam(value = "pageSize",required = false, defaultValue = "10") Integer pageSize) 35 | { 36 | Page page = PageHelper.startPage(pageNum, pageSize, true); 37 | return PaginationUtils.wrapPaginationDTO(page, bookService.query()); 38 | } 39 | @PostMapping("/create") 40 | @ApiOperation("新增书目") 41 | public Long create( 42 | @ApiParam("书目") @Valid @RequestBody BookCreateDTO bookCreateDTO) 43 | { 44 | return bookService.create(bookCreateDTO); 45 | } 46 | 47 | @GetMapping("/{id}/show") 48 | @ApiOperation("查看书目") 49 | public BookDTO show(@ApiParam("书目ID") @PathVariable Long id) 50 | { 51 | return bookService.show(id); 52 | } 53 | 54 | @DeleteMapping("/{id}/delete") 55 | @ApiOperation("删除书目") 56 | public void delete(@ApiParam("书目ID") @PathVariable Long id) 57 | { 58 | bookService.delete(id); 59 | } 60 | 61 | @PatchMapping("/{id}/modify") 62 | @ApiOperation("修改书目信息") 63 | public void modify( 64 | @ApiParam(required=true, value = "id") @PathVariable Long id, 65 | @Valid @RequestBody BookCreateDTO bookCreateDTO 66 | ){ 67 | bookService.modify(id, bookCreateDTO); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookCreateDTO.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.Length; 5 | 6 | import javax.validation.constraints.NotNull; 7 | import javax.validation.constraints.Pattern; 8 | 9 | /** 10 | * @Author: colin 11 | * @Date: 2019/4/26 10:05 12 | * @Description: 13 | * @Version: V1.0 14 | */ 15 | @Data 16 | public class BookCreateDTO { 17 | 18 | @NotNull 19 | @Length(max=45, min=3, message = "名字长度需在3-45位之间") 20 | private String name; 21 | 22 | @NotNull 23 | @Length(max=45, min=3, message = "作者长度需在3-45位之间") 24 | private String author; 25 | 26 | @NotNull 27 | @Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9]+$") 28 | @Length(max=45, min=3, message = "SN长度需在3-45位之间") 29 | private String sn; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookDTO.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @Author: colin 9 | * @Date: 2019/4/26 10:04 10 | * @Description: 11 | * @Version: V1.0 12 | */ 13 | @Data 14 | public class BookDTO extends BookCreateDTO { 15 | 16 | private long id; 17 | private Date createTime; 18 | private Date updateTime; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookDao.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import org.apache.ibatis.annotations.Param; 4 | import org.springframework.stereotype.Repository; 5 | import work.eip.example.svc.base.BaseDAO; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @Author: shaohuanqing 11 | */ 12 | @Repository 13 | public interface BookDao extends BaseDAO { 14 | 15 | List query(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | INSERT INTO book 16 | (id, name, author, sn) 17 | VALUES 18 | (#{id}, #{name}, #{author}, #{sn}) 19 | 20 | 21 | 24 | 25 | 29 | 30 | 31 | DELETE FROM book 32 | WHERE id = #{id} 33 | 34 | 35 | 36 | update book 37 | 38 | 39 | name =#{name}, 40 | 41 | 42 | author =#{author}, 43 | 44 | 45 | sn =#{sn}, 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookEntity.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @Author: colin 9 | * @Date: 2019/4/26 09:44 10 | * @Description: 11 | * @Version: V1.0 12 | */ 13 | @Data 14 | public class BookEntity extends BookCreateDTO { 15 | 16 | private long id; 17 | private Date createTime; 18 | private Date updateTime; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/book/BookService.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.book; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.BeanUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | import work.eip.example.svc.base.AssertUtils; 9 | import work.eip.example.svc.base.BaseService; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @Author: shaohuanqing 15 | * @Date: 2019/7/12 16 | */ 17 | @Service 18 | @Slf4j 19 | public class BookService extends BaseService { 20 | 21 | @Autowired 22 | private BookDao bookDao; 23 | 24 | @Override 25 | protected BookEntity instanciateEntity() { 26 | return new BookEntity(); 27 | } 28 | 29 | @Override 30 | protected BookDTO instanciateDTO() { 31 | return new BookDTO(); 32 | } 33 | 34 | @Transactional 35 | public long create(BookCreateDTO createDTO) { 36 | BookEntity entity = this.instanciateEntity(); 37 | BeanUtils.copyProperties(createDTO, entity); 38 | long id = this.snowFlakeService.nextId(); 39 | entity.setId(id); 40 | log.debug("插入记录: " + entity); 41 | bookDao.insert(entity); 42 | return id; 43 | } 44 | 45 | public List query() { 46 | List entityList = bookDao.query(); 47 | log.debug("查询结果: " + entityList.size()); 48 | return convertToDTOList(entityList); 49 | } 50 | 51 | public BookDTO show(Long id) { 52 | AssertUtils.assertTrue(id != null, "id 不能为空"); 53 | BookDTO dto = this.instanciateDTO(); 54 | BookEntity entity = this.dao.findById(id); 55 | log.debug("查询结果: " + entity); 56 | AssertUtils.assertNotNull(entity, "主键未找到: " + id); 57 | BeanUtils.copyProperties(entity, dto); 58 | return dto; 59 | } 60 | 61 | 62 | @Transactional 63 | public void modify(Long id, BookCreateDTO bookCreateDTO) { 64 | AssertUtils.assertTrue(id != null, "id 不能为空"); 65 | AssertUtils.assertNotNull(bookCreateDTO, "被修改的对象不能为空"); 66 | BookEntity entity = this.instanciateEntity(); 67 | entity.setId(id); 68 | BeanUtils.copyProperties(bookCreateDTO, entity); 69 | dao.update(entity); 70 | } 71 | 72 | 73 | public void delete(Long id) { 74 | AssertUtils.assertTrue(id != null, "id 不能为空"); 75 | long modified = dao.deleteById(id); 76 | AssertUtils.assertTrue(modified == 1, "主键未找到: " + id); 77 | } 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/config/PageHelperConfig.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.config; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | public class PageHelperConfig { 9 | 10 | @Bean 11 | public PageHelper paginationInterceptor() { 12 | return new PageHelper(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /svc-example/src/main/java/work/eip/example/svc/config/Swagger2.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.config; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.PathSelectors; 8 | import springfox.documentation.builders.RequestHandlerSelectors; 9 | import springfox.documentation.service.ApiInfo; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class Swagger2 { 17 | 18 | @Value("${spring.application.name}") 19 | private String appName; 20 | 21 | @Bean 22 | public Docket createRestApi() { 23 | return new Docket(DocumentationType.SWAGGER_2) 24 | .apiInfo(apiInfo()) 25 | .select() 26 | .apis(RequestHandlerSelectors.basePackage("work.eip.example.svc"))//api接口包扫描路径 27 | .paths(PathSelectors.any())//可以根据url路径设置哪些请求加入文档,忽略哪些请求 28 | .build(); 29 | } 30 | private ApiInfo apiInfo() { 31 | return new ApiInfoBuilder() 32 | .title(this.appName)//设置文档的标题 33 | .description(this.appName + " 接口文档")//设置文档的描述->1.Overview 34 | .termsOfServiceUrl("http://eip.work")//设置文档的License信息->1.3 License information 35 | .build(); 36 | } 37 | } -------------------------------------------------------------------------------- /svc-example/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | maxHttpHeaderSize: 102400 4 | port: 9301 5 | management: 6 | endpoints: 7 | web.exposure.include: prometheus 8 | server: 9 | port: 9401 10 | 11 | spring: 12 | application: 13 | name: svc-example 14 | datasource: 15 | type: com.alibaba.druid.pool.DruidDataSource 16 | url: ${DB_EXAMPLE_URL} 17 | username: ${DB_EXAMPLE_USERNAME} 18 | password: ${DB_EXAMPLE_PASSWORD} 19 | 20 | mybatis: 21 | global-config: 22 | id-type: 0 23 | db-column-underline: true 24 | 25 | eureka: 26 | instance: 27 | preferIpAddress: true 28 | lease-renewal-interval-in-seconds: 5 29 | lease-expiration-duration-in-seconds: 15 30 | client: 31 | serviceUrl: 32 | defaultZone: ${CLOUD_EUREKA_DEFAULT_ZONE} 33 | 34 | feign.sentinel.enabled: true 35 | 36 | ribbon: 37 | ConnectTimeOut: 3000 38 | ReadTimeout: 40000 39 | MaxAutoRetries: 1 #对当前实例的重试次数 40 | MaxAutoRetriesNextServer: 1 #切换实例的重试次数 41 | ServerListRefreshInterval: 5000 42 | 43 | log: 44 | path: ${spring.application.name}-logs 45 | 46 | logging: 47 | level: 48 | io.swagger.models.parameters.AbstractSerializableParameter: error 49 | 50 | pagehelper: 51 | helperDialect: mysql 52 | reasonable: true 53 | supportMethodsArguments: true 54 | params: count=countSql 55 | page-size-zero: true -------------------------------------------------------------------------------- /svc-example/src/main/resources/logback-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ${CONSOLE_LOG_PATTERN} 11 | utf-8 12 | 13 | 14 | 15 | 16 | ${LOG_PATH}/log_error.log 17 | 18 | ${LOG_PATH}/error/log-error-%d{yyyy-MM-dd}.%i.log 19 | 20 | 10MB 21 | 22 | 23 | true 24 | 25 | 26 | ${FILE_LOG_PATTERN} 27 | utf-8 28 | 29 | 30 | 31 | error 32 | ACCEPT 33 | DENY 34 | 35 | 36 | 37 | 38 | ${LOG_PATH}/log_all.log 39 | 40 | ${LOG_PATH}/total/log-all-%d{yyyy-MM-dd}.%i.log 41 | 42 | 10MB 43 | 44 | 45 | true 46 | 47 | 48 | ${FILE_LOG_PATTERN} 49 | utf-8 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /svc-example/src/test/java/work/eip/example/svc/questionaire/SvcQuestionaireApplicationTests.java: -------------------------------------------------------------------------------- 1 | package work.eip.example.svc.questionaire; 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 SvcQuestionaireApplicationTests { 11 | @Test 12 | public void contextLoads() { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /web-example/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /web-example/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM eipwork/nginx:1.0.0 2 | LABEL maintainer="shaohq@foxmail.com" 3 | 4 | COPY dist /usr/local/nginx/www 5 | COPY docker/nginx.80.conf /usr/local/nginx/conf.d/nginx.80.conf 6 | 7 | EXPOSE 80 8 | EXPOSE 443 9 | EXPOSE 9913 10 | 11 | ENV ENABLE_EUREKA_CLIENT=TRUE 12 | ENV eureka.name=web-admin 13 | ENV eureka.port=80 14 | ENV eureka.management.port=9913 15 | ENV eureka.serviceUrl.default=http://monitor-eureka:9000/eureka 16 | -------------------------------------------------------------------------------- /web-example/README.md: -------------------------------------------------------------------------------- 1 | # web-example 2 | 3 | ## Project setup 4 | ``` 5 | npm install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | npm run serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | npm run build 16 | ``` 17 | 18 | ### Run your tests 19 | ``` 20 | npm run test 21 | ``` 22 | 23 | ### Lints and fixes files 24 | ``` 25 | npm run lint 26 | ``` 27 | 28 | ### Customize configuration 29 | See [Configuration Reference](https://cli.vuejs.org/config/). 30 | -------------------------------------------------------------------------------- /web-example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /web-example/docker/nginx.80.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name localhost; 4 | 5 | #charset koi8-r; 6 | #access_log /var/log/nginx/host.access.log main; 7 | 8 | location / { 9 | root /usr/local/nginx/www; 10 | index index.html index.htm; 11 | } 12 | 13 | location /api/ { 14 | # Pinpoint Monitoring Proxy Server http://naver.github.io/pinpoint/1.8.3/proxyhttpheader.html 15 | set $pinpoint_proxy_header "t=$msec D=$request_time"; 16 | proxy_set_header Pinpoint-ProxyNginx $pinpoint_proxy_header; 17 | proxy_pass http://gateway-example:9201/; 18 | } 19 | 20 | error_page 500 502 503 504 /50x.html; 21 | location = /50x.html { 22 | root /usr/local/nginx/html; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /web-example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.19.0", 12 | "core-js": "^2.6.5", 13 | "date-fns": "^1.30.1", 14 | "element-ui": "^2.4.5", 15 | "vue": "^2.6.10" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.9.0", 19 | "@vue/cli-plugin-eslint": "^3.9.0", 20 | "@vue/cli-service": "^3.9.0", 21 | "babel-eslint": "^10.0.1", 22 | "eslint": "^5.16.0", 23 | "eslint-plugin-vue": "^5.0.0", 24 | "vue-cli-plugin-element": "^1.0.1", 25 | "vue-template-compiler": "^2.6.10" 26 | }, 27 | "eslintConfig": { 28 | "root": true, 29 | "env": { 30 | "node": true 31 | }, 32 | "extends": [ 33 | "plugin:vue/essential", 34 | "eslint:recommended" 35 | ], 36 | "rules": {}, 37 | "parserOptions": { 38 | "parser": "babel-eslint" 39 | } 40 | }, 41 | "postcss": { 42 | "plugins": { 43 | "autoprefixer": {} 44 | } 45 | }, 46 | "browserslist": [ 47 | "> 1%", 48 | "last 2 versions" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /web-example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/web-example/public/favicon.ico -------------------------------------------------------------------------------- /web-example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | web-example 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /web-example/src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | 18 | 28 | -------------------------------------------------------------------------------- /web-example/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eip-work/kuboard-example/6f2cc59150eff1324545366b3ede880f5b565491/web-example/src/assets/logo.png -------------------------------------------------------------------------------- /web-example/src/components/BookCreate.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 54 | 55 | 58 | -------------------------------------------------------------------------------- /web-example/src/components/BookList.vue: -------------------------------------------------------------------------------- 1 | 28 | 29 | 77 | 78 | 79 | 82 | -------------------------------------------------------------------------------- /web-example/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import './plugins/element.js' 4 | import createService from './service.js' 5 | 6 | Vue.config.productionTip = false 7 | 8 | Vue.prototype.$svc_example = createService('svc-example') 9 | 10 | new Vue({ 11 | render: h => h(App), 12 | }).$mount('#app') 13 | -------------------------------------------------------------------------------- /web-example/src/plugins/element.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Element from 'element-ui' 3 | import 'element-ui/lib/theme-chalk/index.css' 4 | 5 | Vue.use(Element) 6 | -------------------------------------------------------------------------------- /web-example/src/service.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios' 2 | 3 | axios.defaults.baseURL = '/api' 4 | 5 | function createService (serviceName) { 6 | const svc = axios.create({ 7 | baseURL: axios.defaults.baseURL + '/' + serviceName, 8 | timeout: 60000 9 | }) 10 | return svc 11 | } 12 | 13 | export default createService 14 | -------------------------------------------------------------------------------- /web-example/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | lintOnSave: false, 3 | devServer: { 4 | host: 'localhost', 5 | port: 9080, 6 | proxy: { 7 | '/api/svc-example': { 8 | target: 'http://localhost:9301/', 9 | changeOrigin: true, 10 | pathRewrite: { 11 | '^/api/svc-example': '' 12 | } 13 | } 14 | } 15 | }, 16 | 17 | publicPath: '', 18 | outputDir: undefined, 19 | assetsDir: undefined, 20 | runtimeCompiler: undefined, 21 | productionSourceMap: undefined, 22 | parallel: undefined, 23 | css: { 24 | extract: false 25 | } 26 | } 27 | --------------------------------------------------------------------------------