├── .gitattributes ├── LICENSE ├── Readme.md ├── SpringDataDemo ├── .gitignore ├── Readme.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── gl │ │ │ └── springDataDemo │ │ │ ├── UserManagementAppApplication.java │ │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── dto │ │ │ └── User.java │ │ │ ├── repository │ │ │ └── UserRepository.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── gl │ └── springDataDemo │ └── UserManagementAppApplicationTests.java ├── _config.yml ├── ppt ├── Documenting restful services with Swagger.pptx └── Spring data Jpa.pptx ├── profilesDemo ├── .gitignore ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── gl │ │ │ └── profilesDemo │ │ │ ├── AppConfig.java │ │ │ ├── EnvDetails.java │ │ │ └── ProfilesDemoApplication.java │ └── resources │ │ ├── application-dev.yaml │ │ ├── application-prod.yaml │ │ ├── application-test.yaml │ │ └── application.yaml │ └── test │ └── java │ └── com │ └── gl │ └── profilesDemo │ └── ProfilesDemoApplicationTests.java ├── propertiesDemo ├── .gitignore ├── Readme.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── gl │ │ │ └── propertiesDemo │ │ │ ├── MainController.java │ │ │ ├── PropertiesDemoApplication.java │ │ │ ├── User.java │ │ │ └── UserConfigDemo.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── gl │ └── propertiesDemo │ └── PropertiesDemoApplicationTests.java ├── userManagementApp ├── .gitignore ├── Readme.md ├── build.gradle ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── gl │ │ │ └── userManagementApp │ │ │ ├── UserManagementAppApplication.java │ │ │ ├── actuatorEndPoint │ │ │ ├── ActuatorSecurity.java │ │ │ ├── MyHealthIndicator.java │ │ │ ├── MyOwnControllerEndPoint.java │ │ │ ├── UserAppInfo.java │ │ │ └── UserAppInfoEndPoint.java │ │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ ├── dto │ │ │ └── User.java │ │ │ ├── repository │ │ │ └── UserRepository.java │ │ │ └── service │ │ │ ├── UserService.java │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── gl │ └── userManagementApp │ └── UserManagementAppApplicationTests.java └── yamlDemo ├── .gitignore ├── Readme.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── java │ └── com │ │ └── gl │ │ └── propertiesDemo │ │ ├── MainController.java │ │ ├── PropertiesDemoApplication.java │ │ ├── User.java │ │ └── UserConfigDemo.java └── resources │ └── application.yml └── test └── java └── com └── gl └── propertiesDemo └── PropertiesDemoApplicationTests.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Green Learner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | **[Table of Contents](http://tableofcontent.eu)** 2 | 3 | - [Few Details about microservices](#few-details-about-microservices) 4 | - [Features](#features) 5 | - [Note](#note) 6 | - [Spring data JPA](#spring-data-jpa) 7 | - [Communication among microservices in spring boot](#communication-among-microservices-in-spring-boot) 8 | - [RestTemplate](#resttemplate) 9 | - [Feign Client](#feign-client) 10 | 11 | 12 | ## Few Details about microservices 13 | 14 | * A workshop of software architects held near Venice in May 2011 used the term "microservice" to describe what the participants saw as a common architectural style that many of them had been recently exploring 15 | * A microservice is not a layer within a monolithic application (example, the web controller, or the backend-for-frontend[9]). 16 | * Rather it is a self-contained piece of business functionality with clear interfaces, and may, through its own internal components, 17 | implement a layered architecture. 18 | * Microservices is a specialization of an implementation approach for service-oriented architectures (SOA) used to build flexible, 19 | independently deployable software systems. 20 | * The microservices approach is a first realisation of SOA that followed the introduction of DevOps and is becoming more popular for building continuously deployed systems. 21 | * From a strategy perspective, microservices architecture essentially follows the Unix philosophy of "Do one thing and do it well". 22 | Martin Fowler describes a microservices-based architecture as having the following properties 23 | * Naturally enforces a modular structure. 24 | * Lends itself to a continuous delivery software development process. A change to a small part of the application only requires rebuilding and redeploying only one or a small number of services. 25 | * Adheres to principles such as fine-grained interfaces (to independently deployable services), business-driven development (e.g. domain-driven design). 26 | 27 | ## Features 28 | * It is quite common for such an architectural style to be adopted for 29 | * cloud-native applications, 30 | * and applications using lightweight container deployment 31 | * Robert C. Martin coined the term single responsibility principle which states “gather together those things that change for the same reason, 32 | and separate those things that change for different reasons.” 33 | * A microservices architecture takes this same approach and extends it to the loosely coupled services which can be developed, deployed, and maintained independently. Each of these services is responsible for discrete task and can communicate with other services through simple 34 | * APIs to solve a larger complex business problem. 35 | * Service Granularity 36 | * A key step in defining a microservice architecture is figuring out how big an individual microservice has to be. 37 | * There is no consensus or litmus test for this, as the right answer depends on the business and organizational context. 38 | * Amazon's policy is that the team implementing a microservice should be small enough that they can be fed by two pizzas. 39 | * Many organizations choose smaller "squads" - typically 6 to 8 developers. But the key decision hinges around how "clean" 40 | the service boundary can be. 41 | * Linguistic approach 42 | * A linguistic approach to the development of microservices, focuses on selecting a programming language that can easily represent a microservice as a single software artifact. 43 | * When effective, the gap between architecting a project and deploying it can be minimized 44 | 45 | * Technologies 46 | * Service Mesh 47 | 48 | ## Note 49 | * Open individual folder inside to know more. 50 | 51 | ## Spring data JPA 52 | * What is spring Data JPA, CRUDRepository - https://youtu.be/14YYI5DwObg 53 | 54 | * Writting custom query using @query annotation - https://youtu.be/oVKpNP3FcPc 55 | 56 | * What is sorting of data and how to sort in JPA - https://youtu.be/UkuzIjBkbWI 57 | 58 | * What is Paging, slicing and how to execute native sql queries - https://youtu.be/UkuzIjBkbWI 59 | 60 | ## Communication among microservices in spring boot 61 | 62 | There are below two ways with which REST services can communicate among themselves - 63 | * RestTemplate & 64 | * FeignClient 65 | 66 | ### RestTemplate 67 | * One place for all videos and example codes - https://github.com/greenlearner01/RestTemplate 68 | 69 | ### Feign Client 70 | * One place for all videos and example codes - https://github.com/greenlearner01/SpringOpenFeignClient 71 | 72 | ## Circuit Breaker 73 | * One place for all videos and example code - https://github.com/greenlearner01/CircuitBreaker 74 | 75 | ## Spring cloud 76 | 77 | What is spring cloud all about - https://youtu.be/8WGuLpDYx5E 78 | -------------------------------------------------------------------------------- /SpringDataDemo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /SpringDataDemo/Readme.md: -------------------------------------------------------------------------------- 1 | # Spring boot data JPA 2 | 3 | * Playlist - https://www.youtube.com/playlist?list=PLq3uEqRnr_2HoBCVtDb9-FYthkV5DHj_q 4 | 5 | ## Below are the videos to explain the spring data demo concept and code base in detail - 6 | 7 | * Part-1 Spring data demo basics - 8 | https://youtu.be/14YYI5DwObg 9 | 10 | * Part - 2 How to execute custom quries using @query annotation 11 | https://youtu.be/oVKpNP3FcPc 12 | 13 | * Part 3 - Soring data and @Lock annotation to get the lock on table 14 | https://youtu.be/UkuzIjBkbWI 15 | 16 | 17 | * Part4 - Pagination, Slicing in spring data demo and how to execute native sql queries 18 | https://youtu.be/c9t3SeSvWuE 19 | 20 | 21 | -------------------------------------------------------------------------------- /SpringDataDemo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.6.RELEASE' 3 | id 'java' 4 | } 5 | 6 | apply plugin: 'io.spring.dependency-management' 7 | 8 | group = 'com.gl' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '1.8' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | configurations { 17 | developmentOnly 18 | runtimeClasspath { 19 | extendsFrom developmentOnly 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation 'org.springframework.boot:spring-boot-starter-web' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | //developmentOnly("org.springframework.boot:spring-boot-devtools") 27 | 28 | //spring data 29 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 30 | 31 | //my sql connector 32 | compile 'mysql:mysql-connector-java:8.0.17' 33 | 34 | //swagger 35 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' 36 | implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' 37 | 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /SpringDataDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/SpringDataDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /SpringDataDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jul 20 14:31:55 IST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /SpringDataDemo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:firstName=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /SpringDataDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /SpringDataDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | rootProject.name = 'springDataDemo' 7 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/UserManagementAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class UserManagementAppApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(UserManagementAppApplication.class, args); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.RequestHandlerSelectors; 6 | import springfox.documentation.service.ApiInfo; 7 | import springfox.documentation.service.Contact; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | import java.util.ArrayList; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerConfig { 17 | 18 | @Bean 19 | public Docket swagConfig(){ 20 | return new Docket(DocumentationType.SWAGGER_2).select() 21 | .apis(RequestHandlerSelectors.basePackage("com.gl.springDataDemo.controller")) 22 | .build() 23 | .apiInfo(getApiInfo()); 24 | } 25 | 26 | private ApiInfo getApiInfo() { 27 | return new ApiInfo("User Management REST API : Spring boot + Spring data", 28 | "Documentation for springDataDemo for 3rd party", 29 | "1.0", 30 | "Terms of service for using springDataDemo", 31 | new Contact("Green Learner","https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA","greenlearner01@gmail.com"), 32 | "MIT Licence", 33 | "https://opensource.org/licenses/MIT", 34 | new ArrayList<>() 35 | ); 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.controller; 2 | 3 | import com.gl.springDataDemo.dto.User; 4 | import com.gl.springDataDemo.service.UserService; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.data.domain.Slice; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.*; 12 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 13 | 14 | import java.net.URI; 15 | import java.util.List; 16 | 17 | @RestController 18 | public class UserController { 19 | 20 | Logger logger = LoggerFactory.getLogger("UserManagementApp"); 21 | 22 | @Autowired 23 | private UserService userService; 24 | 25 | @GetMapping("/users") 26 | public List getAllUsers(){ 27 | logger.info("getting users.."); 28 | return userService.findAllUsers(); 29 | } 30 | 31 | @GetMapping("/user/{id}") 32 | public User getUser(@PathVariable String id){ 33 | return userService.findUserByName(new Long(id)); 34 | } 35 | 36 | @PostMapping("/user") 37 | public ResponseEntity addUser(@RequestBody User user){ 38 | userService.addUser(user); 39 | URI path = ServletUriComponentsBuilder.fromCurrentRequest() 40 | .path("/{id}") 41 | .buildAndExpand(user.getId()) 42 | .toUri(); 43 | 44 | return ResponseEntity.created(path).build(); 45 | 46 | } 47 | 48 | @DeleteMapping("/user/{id}") 49 | public String deleteUser(@PathVariable String id){ 50 | userService.deleteUserById(new Long(id)); 51 | return "User with Id " + id + " deleted"; 52 | } 53 | 54 | @GetMapping("/getAllUserByFirstName/{firstName}") 55 | public ListgetAllUsersByFirstName(@PathVariable String firstName){ 56 | return userService.getAllUserByFirstName(firstName); 57 | } 58 | 59 | @GetMapping("/getAllUserByGender/{gender}") 60 | public ListgetAllUsersByGender(@PathVariable String gender){ 61 | return userService.getUsersByGender(gender); 62 | } 63 | 64 | @PutMapping("/updateAddress/{id}/{newAddress}") 65 | public String updateAddress(@PathVariable String id, @PathVariable String newAddress){ 66 | userService.updateAddress(Long.parseLong(id), newAddress); 67 | return "address updated!!"; 68 | } 69 | 70 | @GetMapping("/getAllSortedUser/{sortedParam}") 71 | public ListgetAllSortedusers(@PathVariable String sortedParam){ 72 | return userService.findSortedUsers(sortedParam); 73 | } 74 | 75 | @GetMapping("/getAllUserByGender/{gender}/{sortedParam}") 76 | public ListgetAllUsersByGenderAndSort(@PathVariable String gender, @PathVariable String sortedParam){ 77 | return userService.getUsersByGenderAndSort(gender, sortedParam); 78 | } 79 | 80 | @GetMapping("/getAllUserByPages/{pageNumber}/{numberOfElementsPerPage}") 81 | public Page getAllUserByPages(@PathVariable String pageNumber, @PathVariable String numberOfElementsPerPage){ 82 | return userService.getAllUsersByPages(Integer.parseInt(pageNumber), Integer.parseInt(numberOfElementsPerPage)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.dto; 2 | 3 | import javax.persistence.*; 4 | 5 | @Entity 6 | @Table(name = "user") 7 | public class User { 8 | 9 | @Id 10 | @GeneratedValue(strategy = GenerationType.AUTO) 11 | private Long id; 12 | 13 | @Column(name = "first_name") 14 | private String firstName; 15 | 16 | @Column(name = "last_name") 17 | private String lastName; 18 | 19 | private String gender; 20 | 21 | //@Column(name = "home_address") 22 | private String address; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | public String getFirstName() { 33 | return firstName; 34 | } 35 | 36 | public void setFirstName(String firstName) { 37 | 38 | this.firstName = firstName; 39 | } 40 | 41 | public String getAddress() { 42 | return address; 43 | } 44 | 45 | public void setAddress(String address) { 46 | this.address = address; 47 | } 48 | 49 | public String getLastName() { 50 | return lastName; 51 | } 52 | 53 | public void setLastName(String lastName) { 54 | this.lastName = lastName; 55 | } 56 | 57 | public String getGender() { 58 | return gender; 59 | } 60 | 61 | public void setGender(String gender) { 62 | this.gender = gender; 63 | } 64 | 65 | @Override 66 | public String toString() { 67 | return "User{" + 68 | "id=" + id + 69 | ", firstName='" + firstName + '\'' + 70 | ", lastName='" + lastName + '\'' + 71 | ", gender='" + gender + '\'' + 72 | ", address='" + address + '\'' + 73 | '}'; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.repository; 2 | 3 | import com.gl.springDataDemo.dto.User; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.domain.Slice; 6 | import org.springframework.data.domain.Sort; 7 | import org.springframework.data.jpa.repository.JpaRepository; 8 | import org.springframework.data.jpa.repository.Lock; 9 | import org.springframework.data.jpa.repository.Modifying; 10 | import org.springframework.data.jpa.repository.Query; 11 | import org.springframework.data.repository.CrudRepository; 12 | import org.springframework.data.repository.PagingAndSortingRepository; 13 | import org.springframework.data.repository.query.Param; 14 | import org.springframework.stereotype.Repository; 15 | 16 | import javax.persistence.LockModeType; 17 | import javax.transaction.Transactional; 18 | import java.util.List; 19 | 20 | @Repository 21 | public interface UserRepository extends JpaRepository { 22 | 23 | //indexed query 24 | @Query("select u from User u where u.firstName=?1") 25 | List getAllUserByFirstName(String firstName); 26 | 27 | //named query 28 | 29 | @Query(value = "select u from User u where u.gender=:gender"/*, nativeQuery = true*/) 30 | List getUsersByGender(@Param("gender")String gender1); 31 | 32 | 33 | //@Lock(LockModeType.WRITE) 34 | @Transactional 35 | @Modifying 36 | @Query("update User u set u.address=?2 where u.id=?1") 37 | void updateAddress(Long id, String newAddress); 38 | 39 | //@Lock(LockModeType.READ) 40 | @Query("select u from User u where u.gender=:gender") 41 | List getUsersByGenderAndSort(@Param("gender")String gender1, Sort sort); 42 | } 43 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.service; 2 | 3 | import com.gl.springDataDemo.dto.User; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Slice; 6 | import org.springframework.data.domain.Sort; 7 | import org.springframework.data.repository.query.Param; 8 | 9 | import java.util.List; 10 | 11 | public interface UserService { 12 | List findAllUsers(); 13 | 14 | User findUserByName(Long id); 15 | 16 | void addUser(User user); 17 | 18 | void deleteUserById(Long id); 19 | 20 | List getAllUserByFirstName(String firstName); 21 | 22 | List getUsersByGender(String gender1); 23 | 24 | void updateAddress(Long id, String newAdress); 25 | 26 | List findSortedUsers(String paramForSorting); 27 | 28 | List getUsersByGenderAndSort(String gender1, String sortingParam); 29 | 30 | Page getAllUsersByPages(int pageNumber, int numberOfElementsPerPage); 31 | } 32 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/java/com/gl/springDataDemo/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo.service; 2 | 3 | import com.gl.springDataDemo.dto.User; 4 | import com.gl.springDataDemo.repository.UserRepository; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.domain.*; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | @Service 14 | public class UserServiceImpl implements UserService { 15 | 16 | Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); 17 | @Autowired 18 | private UserRepository userRepository; 19 | 20 | @Override 21 | public List findAllUsers() { 22 | List userList = (List) userRepository.findAll(); 23 | logger.info("User list from the DB - {} ", userList); 24 | return userList; 25 | } 26 | 27 | @Override 28 | public User findUserByName(Long id) { 29 | User user = userRepository.findById(id).get(); 30 | logger.info("User from the DB - {} ", user); 31 | return user; 32 | } 33 | 34 | @Override 35 | public void addUser(User user) { 36 | userRepository.save(user); 37 | logger.info("User added - {}", user); 38 | } 39 | 40 | @Override 41 | public void deleteUserById(Long id) { 42 | userRepository.deleteById(new Long(id)); 43 | logger.info("User with {} deleted from the DB", id); 44 | 45 | } 46 | 47 | @Override 48 | public List getAllUserByFirstName(String firstName) { 49 | return userRepository.getAllUserByFirstName(firstName); 50 | } 51 | 52 | @Override 53 | public List getUsersByGender(String gender1) { 54 | return userRepository.getUsersByGender(gender1); 55 | } 56 | 57 | @Override 58 | public void updateAddress(Long id, String newAdress) { 59 | userRepository.updateAddress(id, newAdress); 60 | } 61 | 62 | @Override 63 | public List findSortedUsers(String paramForSorting) { 64 | return (List) userRepository.findAll(Sort.by(paramForSorting)); 65 | } 66 | 67 | @Override 68 | public List getUsersByGenderAndSort(String gender1, String sortingParam) { 69 | 70 | return userRepository.getUsersByGenderAndSort(gender1, Sort.by(sortingParam)); 71 | } 72 | 73 | @Override 74 | public Page getAllUsersByPages(int pageNumber, int numberOfElementsPerPage) { 75 | return userRepository.findAll(PageRequest.of(pageNumber,numberOfElementsPerPage)); 76 | } 77 | 78 | public Slice getAllUsersBySlices(int pageNumber, int numberOfElementsPerPage) { 79 | Slice users = userRepository.findAll(PageRequest.of(pageNumber, numberOfElementsPerPage)); 80 | return users; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /SpringDataDemo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | servlet: 4 | context-path: /springDataDemo 5 | spring: 6 | application: 7 | name: spring-data-demo 8 | 9 | 10 | datasource: 11 | url: jdbc:mysql://localhost:3306/green?useSSL=false 12 | username: root 13 | password: tiger 14 | driver-class-name: com.mysql.cj.jdbc.Driver 15 | -------------------------------------------------------------------------------- /SpringDataDemo/src/test/java/com/gl/springDataDemo/UserManagementAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.springDataDemo; 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 UserManagementAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /ppt/Documenting restful services with Swagger.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/ppt/Documenting restful services with Swagger.pptx -------------------------------------------------------------------------------- /ppt/Spring data Jpa.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/ppt/Spring data Jpa.pptx -------------------------------------------------------------------------------- /profilesDemo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /profilesDemo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.6.RELEASE' 3 | id 'java' 4 | } 5 | 6 | apply plugin: 'io.spring.dependency-management' 7 | 8 | group = 'com.gl' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '1.8' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | -------------------------------------------------------------------------------- /profilesDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/profilesDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /profilesDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /profilesDemo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /profilesDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /profilesDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'profilesDemo' 2 | -------------------------------------------------------------------------------- /profilesDemo/src/main/java/com/gl/profilesDemo/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.profilesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.Profile; 7 | 8 | @Configuration 9 | public class AppConfig { 10 | 11 | @Autowired 12 | private EnvDetails envDetails; 13 | 14 | @Bean 15 | @Profile("dev") 16 | public EnvDetails devEnv() { 17 | System.out.println("Dev environment stuff"); 18 | System.out.println(envDetails); 19 | return envDetails; 20 | } 21 | 22 | @Bean 23 | @Profile("test") 24 | public EnvDetails testEnv() { 25 | System.out.println("Test environment stuff"); 26 | System.out.println(envDetails); 27 | return envDetails; 28 | } 29 | 30 | @Bean 31 | @Profile("prod") 32 | public EnvDetails prodEnv() { 33 | System.out.println("Prod environment stuff"); 34 | System.out.println(envDetails); 35 | return envDetails; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /profilesDemo/src/main/java/com/gl/profilesDemo/EnvDetails.java: -------------------------------------------------------------------------------- 1 | package com.gl.profilesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class EnvDetails { 8 | @Value("${app.server.name}") 9 | private String appServerName; 10 | @Value("${app.server.detail}") 11 | private String appServerDetail; 12 | @Value("${spring.datasource.url}") 13 | private String dbUrl; 14 | @Value("${spring.datasource.username}") 15 | private String dbUser; 16 | @Value("${spring.datasource.password}") 17 | private String dbPassword; 18 | 19 | public EnvDetails() { 20 | 21 | System.out.println(""); 22 | } 23 | 24 | public String getAppServerName() { 25 | return appServerName; 26 | } 27 | 28 | public void setAppServerName(String appServerName) { 29 | this.appServerName = appServerName; 30 | } 31 | 32 | public String getAppServerDetail() { 33 | return appServerDetail; 34 | } 35 | 36 | public void setAppServerDetail(String appServerDetail) { 37 | this.appServerDetail = appServerDetail; 38 | } 39 | 40 | public String getDbUrl() { 41 | return dbUrl; 42 | } 43 | 44 | public void setDbUrl(String dbUrl) { 45 | this.dbUrl = dbUrl; 46 | } 47 | 48 | public String getDbUser() { 49 | return dbUser; 50 | } 51 | 52 | public void setDbUser(String dbUser) { 53 | this.dbUser = dbUser; 54 | } 55 | 56 | public String getDbPassword() { 57 | return dbPassword; 58 | } 59 | 60 | public void setDbPassword(String dbPassword) { 61 | this.dbPassword = dbPassword; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "EnvDetails{" + 67 | "appServerName='" + appServerName + '\'' + 68 | ", appServerDetail='" + appServerDetail + '\'' + 69 | ", dbUrl='" + dbUrl + '\'' + 70 | ", dbUser='" + dbUser + '\'' + 71 | ", dbPassword='" + dbPassword + '\'' + 72 | '}'; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /profilesDemo/src/main/java/com/gl/profilesDemo/ProfilesDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.profilesDemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProfilesDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | 11 | SpringApplication.run(ProfilesDemoApplication.class, args); 12 | 13 | //StandardContext this; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /profilesDemo/src/main/resources/application-dev.yaml: -------------------------------------------------------------------------------- 1 | app: 2 | server: 3 | name: tomcat 4 | detail: this is tomcat for dev 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:hsql:hsql://localhost/enrolments 9 | username: dev 10 | password: 12345 11 | 12 | 13 | -------------------------------------------------------------------------------- /profilesDemo/src/main/resources/application-prod.yaml: -------------------------------------------------------------------------------- 1 | app: 2 | server: 3 | name: glashfish 4 | detail: this is glasfish for production 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:oracle:thin:@hostname:80:rocky 9 | username: oracle-prod 10 | password: heybabe 11 | 12 | -------------------------------------------------------------------------------- /profilesDemo/src/main/resources/application-test.yaml: -------------------------------------------------------------------------------- 1 | app: 2 | server: 3 | name: jboss 4 | detail: this is jboss for test 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/rock 9 | username: mysql 10 | password: arvsd 11 | 12 | -------------------------------------------------------------------------------- /profilesDemo/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8083 3 | 4 | app: 5 | server: 6 | name: geenral 7 | detail: this is general server 8 | 9 | spring: 10 | profiles: 11 | active: 12 | - test 13 | datasource: 14 | url: jdbc:hsqldb:hsql://localhost/geenral 15 | username: geenral-user 16 | password: 12345 17 | application: 18 | name: This is the demo project for spring profiles 19 | -------------------------------------------------------------------------------- /profilesDemo/src/test/java/com/gl/profilesDemo/ProfilesDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.profilesDemo; 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 ProfilesDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /propertiesDemo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /propertiesDemo/Readme.md: -------------------------------------------------------------------------------- 1 | ## Details about the project 2 | Watch youtube video - https://youtu.be/yHofNAFkiEI -------------------------------------------------------------------------------- /propertiesDemo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.6.RELEASE' 3 | id 'java' 4 | } 5 | 6 | apply plugin: 'io.spring.dependency-management' 7 | 8 | group = 'com.gl' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '1.8' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | -------------------------------------------------------------------------------- /propertiesDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/propertiesDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /propertiesDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /propertiesDemo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /propertiesDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /propertiesDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'propertiesDemo' 2 | -------------------------------------------------------------------------------- /propertiesDemo/src/main/java/com/gl/propertiesDemo/MainController.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class MainController { 9 | 10 | @Autowired 11 | private User user; 12 | 13 | @Autowired 14 | private UserConfigDemo userConfigDemo; 15 | 16 | @GetMapping("/user") 17 | public String getUsers(){ 18 | System.out.println(user.getSystemProps()); 19 | return user.toString(); 20 | } 21 | 22 | @GetMapping("/userConfig") 23 | public String getUserConfig(){ 24 | return userConfigDemo.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /propertiesDemo/src/main/java/com/gl/propertiesDemo/PropertiesDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.SerializationFeature; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | public class PropertiesDemoApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(PropertiesDemoApplication.class, args); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /propertiesDemo/src/main/java/com/gl/propertiesDemo/User.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | */ 12 | @Configuration 13 | public class User { 14 | @Value("${user.fb.name:defaultUser}") 15 | private String fbUser; 16 | @Value("${user.fb.password}") 17 | private String fbPassword; 18 | @Value("${user.gmail.name}") 19 | private String gmailUser; 20 | @Value("${user.gmail.password}") 21 | private String gmailPassword; 22 | 23 | @Value("#{'${list}'.split(',')}") 24 | private List listOfItem; 25 | 26 | @Value("${list}") 27 | private List arrayVal; 28 | 29 | @Value("#{${values.map}}") 30 | private Map mapValue; 31 | 32 | @Value("#{systemProperties}") 33 | private Map systemProps; 34 | 35 | public Map getSystemProps() { 36 | return systemProps; 37 | } 38 | 39 | public void setSystemProps(Map systemProps) { 40 | this.systemProps = systemProps; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "User{" + 46 | "fbUser='" + fbUser + '\'' + 47 | ", fbPassword='" + fbPassword + '\'' + 48 | ", gmailUser='" + gmailUser + '\'' + 49 | ", gmailPassword='" + gmailPassword + '\'' + 50 | ", listOfItem=" + listOfItem + 51 | ", arrayVal=" + arrayVal + 52 | ", mapValue=" + mapValue + 53 | '}'; 54 | } 55 | 56 | public List getArrayVal() { 57 | return arrayVal; 58 | } 59 | 60 | public void setArrayVal(List arrayVal) { 61 | this.arrayVal = arrayVal; 62 | } 63 | 64 | public String getFbUser() { 65 | return fbUser; 66 | } 67 | 68 | public void setFbUser(String fbUser) { 69 | this.fbUser = fbUser; 70 | } 71 | 72 | public String getFbPassword() { 73 | return fbPassword; 74 | } 75 | 76 | public void setFbPassword(String fbPassword) { 77 | this.fbPassword = fbPassword; 78 | } 79 | 80 | public String getGmailUser() { 81 | return gmailUser; 82 | } 83 | 84 | public void setGmailUser(String gmailUser) { 85 | this.gmailUser = gmailUser; 86 | } 87 | 88 | public String getGmailPassword() { 89 | return gmailPassword; 90 | } 91 | 92 | public void setGmailPassword(String gmailPassword) { 93 | this.gmailPassword = gmailPassword; 94 | } 95 | 96 | public List getListOfItem() { 97 | return listOfItem; 98 | } 99 | 100 | public void setListOfItem(List listOfItem) { 101 | this.listOfItem = listOfItem; 102 | } 103 | 104 | public Map getMapValue() { 105 | return mapValue; 106 | } 107 | 108 | public void setMapValue(Map mapValue) { 109 | this.mapValue = mapValue; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /propertiesDemo/src/main/java/com/gl/propertiesDemo/UserConfigDemo.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ConfigurationProperties(prefix="config") 8 | public class UserConfigDemo { 9 | 10 | private String host; 11 | private String port; 12 | private String userName; 13 | private ThirdParty thirdParty; 14 | 15 | public String getHost() { 16 | return host; 17 | } 18 | 19 | public void setHost(String host) { 20 | this.host = host; 21 | } 22 | 23 | public String getPort() { 24 | return port; 25 | } 26 | 27 | public void setPort(String port) { 28 | this.port = port; 29 | } 30 | 31 | public String getUserName() { 32 | return userName; 33 | } 34 | 35 | public void setUserName(String userName) { 36 | this.userName = userName; 37 | } 38 | 39 | public ThirdParty getThirdParty() { 40 | return thirdParty; 41 | } 42 | 43 | public void setThirdParty(ThirdParty thirdParty) { 44 | this.thirdParty = thirdParty; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "UserConfigDemo{" + 50 | "host='" + host + '\'' + 51 | ", port='" + port + '\'' + 52 | ", userName='" + userName + '\'' + 53 | ", thirdParty=" + thirdParty + 54 | '}'; 55 | } 56 | 57 | private static class ThirdParty { 58 | private String host; 59 | private String port; 60 | private String name; 61 | 62 | public String getHost() { 63 | return host; 64 | } 65 | 66 | public void setHost(String host) { 67 | this.host = host; 68 | } 69 | 70 | public String getPort() { 71 | return port; 72 | } 73 | 74 | public void setPort(String port) { 75 | this.port = port; 76 | } 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | public void setName(String name) { 83 | this.name = name; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return "ThirdParty{" + 89 | "host='" + host + '\'' + 90 | ", port='" + port + '\'' + 91 | ", name='" + name + '\'' + 92 | '}'; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /propertiesDemo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 2 | spring.application.name= properties demo 3 | 4 | 5 | #user.fb.name=sheldon 6 | user.fb.password=sheldon12 7 | user.gmail.name=raj 8 | user.gmail.password=raj123 9 | values.map={key1: '1', key2: '2', key3: '3'} 10 | list = {"a", "b", "1"} 11 | 12 | #config.host=172.32.43.189 13 | config.port=${random.int} 14 | config.userName=dummy 15 | config.thirdParty.host=109.43.32.43 16 | config.thirdParty.port=90 17 | config.thirdParty.name=user2 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /propertiesDemo/src/test/java/com/gl/propertiesDemo/PropertiesDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 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 PropertiesDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /userManagementApp/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /userManagementApp/Readme.md: -------------------------------------------------------------------------------- 1 | **[Table of Contents](http://tableofcontent.eu)** 2 | 3 | - [Design of the project](#design-of-the-project) 4 | - [Youtube video to explain the code base](#youtube-video-to-explain-the-code-base) 5 | - [How to run the project](#how-to-run-the-project) 6 | - [End point urls](#end-point-urls) 7 | 8 | 9 | ## Design of the project 10 | The design has been explained in following ppt - 11 | * https://github.com/greenlearner01/MyNotes/blob/master/ppt/Rest_application_with_spring_boot.pptx 12 | 13 | ## Youtube video to explain the code base 14 | 15 | * https://www.youtube.com/playlist?list=PLq3uEqRnr_2Hb9M-hz6GPVg_x9TUQ9PJA 16 | 17 | ## How to run the project 18 | * Clone it to local - git clone https://github.com/greenlearner01/Microservices.git and 19 | * Navigate to userManagementApp folder 20 | * Now there are two ways to run the project 21 | * First- running jar file 22 | * navigate to directory from command prompt 23 | * execute below command 24 | 25 | gradlew clean build 26 | 27 | this will create the jar file inside build/libs 28 | * go to /build/libs and execute > java -jar .jar 29 | * Sencond way - Directly running the main method 30 | * Open the project in IntelliJ Idea or eclipse 31 | * And run the main method inside UserManagementAppApplication.java 32 | * The app will run on port 8082 33 | 34 | ## End point urls 35 | 36 | * AddUser - Post method > http://localhost:8082/user 37 | 38 | Request body - 39 | { 40 | "id": "1234", 41 | "name": "green learner123", 42 | "address": "delhi" 43 | } 44 | 45 | * update user - Put method > http://localhost:8082/user 46 | 47 | Request body - 48 | { 49 | "id": "1234", 50 | "name": "green learner123-updated", 51 | "address": "delhi-updated" 52 | } 53 | 54 | * Get single user - GET method > http://localhost:8082/user/123 55 | * Get all the users - GET method > http://localhost:8082/users 56 | * Delete user - DELETE method > http://localhost:8082/user/123 57 | -------------------------------------------------------------------------------- /userManagementApp/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.6.RELEASE' 3 | id 'java' 4 | } 5 | 6 | apply plugin: 'io.spring.dependency-management' 7 | 8 | group = 'com.gl' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '1.8' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | configurations { 17 | developmentOnly 18 | runtimeClasspath { 19 | extendsFrom developmentOnly 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation 'org.springframework.boot:spring-boot-starter-web' 25 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 26 | developmentOnly("org.springframework.boot:spring-boot-devtools") 27 | compile('org.springframework.boot:spring-boot-starter-actuator') 28 | implementation('org.springframework.boot:spring-boot-starter-security') 29 | 30 | //swagger 31 | compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2' 32 | implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2' 33 | 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /userManagementApp/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/userManagementApp/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /userManagementApp/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Jul 20 14:31:55 IST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /userManagementApp/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /userManagementApp/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /userManagementApp/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | } 5 | } 6 | rootProject.name = 'userManagementApp' 7 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/UserManagementAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class UserManagementAppApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(UserManagementAppApplication.class, args); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/actuatorEndPoint/ActuatorSecurity.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.actuatorEndPoint; 2 | 3 | import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | @Configuration 9 | public class ActuatorSecurity extends WebSecurityConfigurerAdapter { 10 | 11 | @Override 12 | protected void configure(HttpSecurity http) throws Exception { 13 | http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests() 14 | .anyRequest().permitAll(); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/actuatorEndPoint/MyHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.actuatorEndPoint; 2 | 3 | import org.springframework.boot.actuate.health.Health; 4 | import org.springframework.boot.actuate.health.HealthIndicator; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | public class MyHealthIndicator implements HealthIndicator { 9 | 10 | @Override 11 | public Health health() { 12 | int errorCode = check(); // perform some specific health check 13 | if (errorCode != 0) { 14 | return Health.down().withDetail("Error Code", errorCode).build(); 15 | } 16 | return Health.up().build(); 17 | } 18 | 19 | /** 20 | * condition check for health 21 | * @return 22 | */ 23 | private int check() { 24 | //logic to check the health. this can be db hit or some other as per requirement 25 | // any value other than 0 is considered as health down 26 | return 0; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/actuatorEndPoint/MyOwnControllerEndPoint.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.actuatorEndPoint; 2 | 3 | import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | @Component 10 | @RestControllerEndpoint(id = "controllerEndPoint") 11 | public class MyOwnControllerEndPoint { 12 | 13 | @GetMapping("/message-from-solar") 14 | public ResponseEntity readEndPoint(){ 15 | return new ResponseEntity<>("This is Eagle!! Reporting from Jupiter", HttpStatus.OK); 16 | } 17 | } -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/actuatorEndPoint/UserAppInfo.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.actuatorEndPoint; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | 5 | import java.util.Map; 6 | 7 | @JsonInclude(JsonInclude.Include.NON_EMPTY) 8 | public class UserAppInfo { 9 | 10 | private Map healthDetails; 11 | 12 | public Map getHealthDetails() { 13 | return this.healthDetails; 14 | } 15 | 16 | public void setHealthDetails(Map healthDetails) { 17 | this.healthDetails = healthDetails; 18 | } 19 | } -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/actuatorEndPoint/UserAppInfoEndPoint.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.actuatorEndPoint; 2 | 3 | import org.springframework.boot.actuate.endpoint.annotation.*; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | @Component 10 | @Endpoint(id="userAppInfo") 11 | public class UserAppInfoEndPoint { 12 | 13 | @ReadOperation 14 | public UserAppInfo userAppInfo() { 15 | Map details = new LinkedHashMap<>(); 16 | details.put("App Location", "!!MARS!!"); 17 | details.put("Status", "Reporting From Mars. All Good!!"); 18 | UserAppInfo health = new UserAppInfo(); 19 | health.setHealthDetails(details); 20 | return health; 21 | } 22 | 23 | @ReadOperation 24 | public String userAppEndPointByName(@Selector String name) { 25 | return "This is user management application, reporting from Mars!! All OK !!" + name; 26 | } 27 | 28 | @WriteOperation 29 | public void writeOperation(@Selector String name) { 30 | //perform write operation 31 | // this is the POST type endpoint 32 | } 33 | @DeleteOperation 34 | public void deleteOperation(@Selector String name){ 35 | //delete operation 36 | // this is the DELETE type endpoint 37 | } 38 | } -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.RequestHandlerSelectors; 6 | import springfox.documentation.service.ApiInfo; 7 | import springfox.documentation.service.Contact; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | import java.util.ArrayList; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerConfig { 17 | 18 | @Bean 19 | public Docket swagConfig(){ 20 | return new Docket(DocumentationType.SWAGGER_2).select() 21 | .apis(RequestHandlerSelectors.basePackage("com.gl.userManagementApp.controller")) 22 | .build() 23 | .apiInfo(getApiInfo()); 24 | } 25 | 26 | private ApiInfo getApiInfo() { 27 | return new ApiInfo("User Management REST API", 28 | "Documentation for userManagementApp for 3rd party", 29 | "1.0", 30 | "Terms of service for using userManagementApp", 31 | new Contact("Green Learner","https://www.youtube.com/channel/UCaH2MTg94hrJZTolW01a3ZA","greenlearner01@gmail.com"), 32 | "MIT Licence", 33 | "https://opensource.org/licenses/MIT", 34 | new ArrayList<>() 35 | ); 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.controller; 2 | 3 | import com.gl.userManagementApp.dto.User; 4 | import com.gl.userManagementApp.service.UserService; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 11 | 12 | import java.net.URI; 13 | import java.util.List; 14 | 15 | @RestController 16 | public class UserController { 17 | 18 | Logger logger = LoggerFactory.getLogger("UserManagementApp"); 19 | 20 | @Autowired 21 | private UserService userService; 22 | 23 | @GetMapping("/users") 24 | public List getAllUsers(){ 25 | logger.info("getting users.."); 26 | return userService.getAllUsers(); 27 | } 28 | 29 | @GetMapping("/user/{id}") 30 | public User getUser(@PathVariable String id){ 31 | return userService.getUser(id); 32 | } 33 | 34 | @PostMapping("/user") 35 | public ResponseEntity addUser(@RequestBody User user){ 36 | userService.addUser(user); 37 | URI path = ServletUriComponentsBuilder.fromCurrentRequest() 38 | .path("/{id}") 39 | .buildAndExpand(user.getId()) 40 | .toUri(); 41 | 42 | return ResponseEntity.created(path).build(); 43 | 44 | } 45 | 46 | @PutMapping("/user") 47 | public User updateUser(@RequestBody User user){ 48 | return userService.updateUser(user); 49 | } 50 | 51 | @DeleteMapping("/user/{id}") 52 | public User deleteUser(@PathVariable String id){ 53 | return userService.deleteUser(id); 54 | } 55 | 56 | @GetMapping("/logs") 57 | public String logs(){ 58 | logger.trace("A TRACE Message"); 59 | logger.debug("A DEBUG Message"); 60 | logger.info("An INFO Message"); 61 | logger.warn("A WARN Message"); 62 | logger.error("An ERROR Message"); 63 | return "hey buddy see the console for different level of logs"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.dto; 2 | 3 | public class User { 4 | 5 | private String id; 6 | private String name; 7 | private String address; 8 | 9 | public String getId() { 10 | return id; 11 | } 12 | 13 | public void setId(String id) { 14 | this.id = id; 15 | } 16 | 17 | public String getName() { 18 | return name; 19 | } 20 | 21 | public void setName(String name) { 22 | 23 | this.name = "Mr." + name; 24 | } 25 | 26 | public String getAddress() { 27 | return address; 28 | } 29 | 30 | public void setAddress(String address) { 31 | this.address = address; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.repository; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | import com.gl.userManagementApp.dto.User; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | @Repository 12 | public class UserRepository { 13 | 14 | List userList = new ArrayList<>(); 15 | public List getAllUsers() { 16 | return userList; 17 | } 18 | 19 | public User getUser(String id) { 20 | Optional first = userList.stream() 21 | .filter(u -> u.getId().equals(id)) 22 | .findFirst(); 23 | if(first.isPresent()){ 24 | return first.get(); 25 | }else{ 26 | return new User(); 27 | } 28 | } 29 | 30 | public void addUser(User user) { 31 | userList.add(user); 32 | } 33 | 34 | public User updateUser(User user) { 35 | for(User u1 : userList){ 36 | if(u1.getId().equals(user.getId())){ 37 | u1.setName(user.getName()); 38 | u1.setAddress(user.getAddress()); 39 | return u1; 40 | } 41 | } 42 | return new User(); 43 | } 44 | 45 | public User deleteUser(String id) { 46 | Optional first = userList.stream() 47 | .filter(u -> u.getId().equals(id)) 48 | .findFirst(); 49 | if(first.isPresent()){ 50 | User user = first.get(); 51 | userList.remove(user); 52 | return user; 53 | }else{ 54 | return new User(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.service; 2 | 3 | import com.gl.userManagementApp.dto.User; 4 | 5 | import java.util.List; 6 | 7 | public interface UserService { 8 | List getAllUsers(); 9 | 10 | User getUser(String id); 11 | 12 | void addUser(User user); 13 | 14 | User updateUser(User user); 15 | 16 | User deleteUser(String id); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /userManagementApp/src/main/java/com/gl/userManagementApp/service/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp.service; 2 | 3 | import com.gl.userManagementApp.dto.User; 4 | import com.gl.userManagementApp.repository.UserRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | @Service 11 | public class UserServiceImpl implements UserService { 12 | 13 | @Autowired 14 | private UserRepository userRepository; 15 | @Override 16 | public List getAllUsers() { 17 | return userRepository.getAllUsers(); 18 | } 19 | 20 | @Override 21 | public User getUser(String id) { 22 | return userRepository.getUser(id); 23 | } 24 | 25 | @Override 26 | public void addUser(User user) { 27 | userRepository.addUser(user); 28 | } 29 | 30 | @Override 31 | public User updateUser(User user) { 32 | return userRepository.updateUser(user); 33 | } 34 | 35 | @Override 36 | public User deleteUser(String id) { 37 | return userRepository.deleteUser(id); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /userManagementApp/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8082 2 | 3 | #below property can have these values - always, never, when-authorized 4 | management.endpoint.health.show-details=always 5 | 6 | info.app.encoding=UTF-8 7 | info.app.java.source=1.8 8 | info.app.java.target=1.8 9 | info.name.of.app=user mangement applciation 10 | 11 | #management.endpoints.web.base-path=/userApp 12 | 13 | #management.endpoint.health.enabled=false 14 | #management.endpoints.enabled-by-default=true 15 | 16 | management.endpoints.web.exposure.include=* 17 | 18 | spring.security.user.name=green 19 | spring.security.user.password=learner 20 | 21 | 22 | ## logging related properties 23 | logging.level.root=trace 24 | logging.file=userApp.log 25 | 26 | -------------------------------------------------------------------------------- /userManagementApp/src/test/java/com/gl/userManagementApp/UserManagementAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.userManagementApp; 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 UserManagementAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /yamlDemo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/** 6 | !**/src/test/** 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | out/ 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /yamlDemo/Readme.md: -------------------------------------------------------------------------------- 1 | ## Details about the project 2 | Watch youtube video - https://youtu.be/Vonxkq5ELhE -------------------------------------------------------------------------------- /yamlDemo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'org.springframework.boot' version '2.1.6.RELEASE' 3 | id 'java' 4 | } 5 | 6 | apply plugin: 'io.spring.dependency-management' 7 | 8 | group = 'com.gl' 9 | version = '0.0.1-SNAPSHOT' 10 | sourceCompatibility = '1.8' 11 | 12 | repositories { 13 | mavenCentral() 14 | } 15 | 16 | dependencies { 17 | implementation 'org.springframework.boot:spring-boot-starter-web' 18 | testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 | } 20 | -------------------------------------------------------------------------------- /yamlDemo/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codefarm0/Microservices/61fe4b67b2275b8b25fabbbfea3f47f1af616c77/yamlDemo/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /yamlDemo/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /yamlDemo/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /yamlDemo/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /yamlDemo/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'propertiesDemo' 2 | -------------------------------------------------------------------------------- /yamlDemo/src/main/java/com/gl/propertiesDemo/MainController.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class MainController { 9 | 10 | @Autowired 11 | private User user; 12 | 13 | @Autowired 14 | private UserConfigDemo userConfigDemo; 15 | 16 | @GetMapping("/user") 17 | public String getUsers(){ 18 | System.out.println(user.getSystemProps()); 19 | return user.toString(); 20 | } 21 | 22 | @GetMapping("/userConfig") 23 | public String getUserConfig(){ 24 | return userConfigDemo.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /yamlDemo/src/main/java/com/gl/propertiesDemo/PropertiesDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.SerializationFeature; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.context.annotation.Bean; 8 | 9 | @SpringBootApplication 10 | public class PropertiesDemoApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(PropertiesDemoApplication.class, args); 14 | } 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /yamlDemo/src/main/java/com/gl/propertiesDemo/User.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | /** 10 | * 11 | */ 12 | @Configuration 13 | public class User { 14 | @Value("${user.fb.name:defaultUser}") 15 | private String fbUser; 16 | @Value("${user.fb.password}") 17 | private String fbPassword; 18 | @Value("${user.gmail.name}") 19 | private String gmailUser; 20 | @Value("${user.gmail.password}") 21 | private String gmailPassword; 22 | 23 | @Value("#{'${list}'.split(',')}") 24 | private List listOfItem; 25 | 26 | @Value("${list}") 27 | private List arrayVal; 28 | 29 | @Value("#{${values.map}}") 30 | private Map mapValue; 31 | 32 | @Value("#{systemProperties}") 33 | private Map systemProps; 34 | 35 | public Map getSystemProps() { 36 | return systemProps; 37 | } 38 | 39 | public void setSystemProps(Map systemProps) { 40 | this.systemProps = systemProps; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return "User{" + 46 | "fbUser='" + fbUser + '\'' + 47 | ", fbPassword='" + fbPassword + '\'' + 48 | ", gmailUser='" + gmailUser + '\'' + 49 | ", gmailPassword='" + gmailPassword + '\'' + 50 | ", listOfItem=" + listOfItem + 51 | ", arrayVal=" + arrayVal + 52 | ", mapValue=" + mapValue + 53 | '}'; 54 | } 55 | 56 | public List getArrayVal() { 57 | return arrayVal; 58 | } 59 | 60 | public void setArrayVal(List arrayVal) { 61 | this.arrayVal = arrayVal; 62 | } 63 | 64 | public String getFbUser() { 65 | return fbUser; 66 | } 67 | 68 | public void setFbUser(String fbUser) { 69 | this.fbUser = fbUser; 70 | } 71 | 72 | public String getFbPassword() { 73 | return fbPassword; 74 | } 75 | 76 | public void setFbPassword(String fbPassword) { 77 | this.fbPassword = fbPassword; 78 | } 79 | 80 | public String getGmailUser() { 81 | return gmailUser; 82 | } 83 | 84 | public void setGmailUser(String gmailUser) { 85 | this.gmailUser = gmailUser; 86 | } 87 | 88 | public String getGmailPassword() { 89 | return gmailPassword; 90 | } 91 | 92 | public void setGmailPassword(String gmailPassword) { 93 | this.gmailPassword = gmailPassword; 94 | } 95 | 96 | public List getListOfItem() { 97 | return listOfItem; 98 | } 99 | 100 | public void setListOfItem(List listOfItem) { 101 | this.listOfItem = listOfItem; 102 | } 103 | 104 | public Map getMapValue() { 105 | return mapValue; 106 | } 107 | 108 | public void setMapValue(Map mapValue) { 109 | this.mapValue = mapValue; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /yamlDemo/src/main/java/com/gl/propertiesDemo/UserConfigDemo.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | @Configuration 7 | @ConfigurationProperties(prefix="config") 8 | public class UserConfigDemo { 9 | 10 | private String host; 11 | private String port; 12 | private String userName; 13 | private ThirdParty thirdParty; 14 | 15 | public String getHost() { 16 | return host; 17 | } 18 | 19 | public void setHost(String host) { 20 | this.host = host; 21 | } 22 | 23 | public String getPort() { 24 | return port; 25 | } 26 | 27 | public void setPort(String port) { 28 | this.port = port; 29 | } 30 | 31 | public String getUserName() { 32 | return userName; 33 | } 34 | 35 | public void setUserName(String userName) { 36 | this.userName = userName; 37 | } 38 | 39 | public ThirdParty getThirdParty() { 40 | return thirdParty; 41 | } 42 | 43 | public void setThirdParty(ThirdParty thirdParty) { 44 | this.thirdParty = thirdParty; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "UserConfigDemo{" + 50 | "host='" + host + '\'' + 51 | ", port='" + port + '\'' + 52 | ", userName='" + userName + '\'' + 53 | ", thirdParty=" + thirdParty + 54 | '}'; 55 | } 56 | 57 | private static class ThirdParty { 58 | private String host; 59 | private String port; 60 | private String name; 61 | 62 | public String getHost() { 63 | return host; 64 | } 65 | 66 | public void setHost(String host) { 67 | this.host = host; 68 | } 69 | 70 | public String getPort() { 71 | return port; 72 | } 73 | 74 | public void setPort(String port) { 75 | this.port = port; 76 | } 77 | 78 | public String getName() { 79 | return name; 80 | } 81 | 82 | public void setName(String name) { 83 | this.name = name; 84 | } 85 | 86 | @Override 87 | public String toString() { 88 | return "ThirdParty{" + 89 | "host='" + host + '\'' + 90 | ", port='" + port + '\'' + 91 | ", name='" + name + '\'' + 92 | '}'; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /yamlDemo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | config: 2 | port: ${random.int} 3 | thirdParty: 4 | host: 109.43.32.43 5 | name: user2 6 | port: 90 7 | userName: dummy 8 | list: '{"a", "b", "1"}' 9 | server: 10 | port: 8081 11 | spring: 12 | application: 13 | name: properties demo 14 | user: 15 | fb: 16 | password: sheldon12 17 | gmail: 18 | name: raj 19 | password: raj123 20 | values: 21 | map: '{key1: ''1'', key2: ''2'', key3: ''3''}' 22 | -------------------------------------------------------------------------------- /yamlDemo/src/test/java/com/gl/propertiesDemo/PropertiesDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.gl.propertiesDemo; 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 PropertiesDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------