├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── Procfile ├── README.md ├── app.json ├── build.gradle ├── config └── checkstyle │ └── checkstyle.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── docker │ └── Dockerfile ├── java │ └── com │ │ └── liuwill │ │ └── demo │ │ └── kotlinboot │ │ └── controllers │ │ └── ShowController.java ├── kotlin │ └── com │ │ └── liuwill │ │ └── demo │ │ └── kotlinboot │ │ ├── SpringBootKotlinApplication.kt │ │ └── controllers │ │ ├── DataController.kt │ │ └── HomeController.kt └── resources │ ├── config │ ├── application.properties │ └── front.properties │ └── templates │ └── index.ftl └── test ├── java └── com │ └── liuwill │ └── demo │ └── kotlinboot │ └── test │ └── integration │ ├── DataControllerStandaloneTest.java │ └── ShowControllerStandaloneTest.java └── kotlin └── com └── liuwill └── demo └── kotlinboot └── test ├── acceptence └── HomeControllerWebTest.kt └── integration ├── HomeControllerMvcTest.kt └── HomeControllerStandaloneTest.kt /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build 4 | SpringBootKotlin.iml 5 | SpringBootKotlin.ipr 6 | SpringBootKotlin.iws -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: java:openjdk-8 2 | 3 | stages: 4 | - test 5 | - deploy 6 | before_script: 7 | - apt-get update -y 8 | test_async: 9 | stage: test 10 | script: 11 | - pwd 12 | - cd /usr/lib 13 | - curl -fl https://downloads.gradle.org/distributions/gradle-3.4.1-bin.zip -o gradle-bin.zip 14 | - unzip "gradle-bin.zip" 15 | - ln -s "/usr/lib/gradle-3.4.1/bin/gradle" /usr/bin/gradle 16 | - rm "gradle-bin.zip" 17 | - GRADLE_HOME=/usr/lib/gradle 18 | - PATH=$PATH:$GRADLE_HOME/bin 19 | - cd /builds/techartisan/SpringBootKotlin 20 | - gradle test --info 21 | tags: 22 | - docker 23 | 24 | staging: 25 | type: deploy 26 | script: 27 | - apt-get update -qy 28 | - apt-get install -y ruby-dev rubygems 29 | - gem install dpl 30 | - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY 31 | only: 32 | - deploy 33 | tags: 34 | - docker -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | before_script: 7 | # Change Gradle wrapper permissions 8 | - chmod +x gradlew 9 | 10 | script: 11 | - ./gradlew clean build --info 12 | 13 | after_success: 14 | - ./gradlew jacocoTestReport coveralls -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: java -jar build/libs/boot-kotlin-app-0.1.0.jar --port $PORT 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/liuwill-projects/SpringBootKotlin.svg)](https://travis-ci.org/liuwill-projects/SpringBootKotlin) [![Coverage Status](https://coveralls.io/repos/github/liuwill-projects/SpringBootKotlin/badge.svg?branch=master)](https://coveralls.io/github/liuwill-projects/SpringBootKotlin?branch=master) 2 | 3 | # Spring Boot Kotlin 4 | 5 | > 用kotlin实现的一个spring boot脚手架 6 | 7 | ## 相关技术 8 | - kotlin 9 | - gradle 10 | - docker 11 | - spring boot 12 | 13 | ## gradle命令 14 | ```$shell 15 | gradle idea 16 | gradle bootRun 17 | gradle buildDocker 18 | gradle test 19 | 20 | ``` -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Getting Started with Gradle on Heroku", 3 | "description": "A bare-bones Gradle app, which can easily be deployed to Heroku.", 4 | "image": "heroku/gradle" 5 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.groupName = 'liuwill' 3 | ext.kotlin_version = '1.1.0' 4 | ext.junit_version = '4.12' 5 | ext.freemarker_version = '2.3.23' 6 | ext.spring_boot_version = '1.5.2.RELEASE' 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | classpath('se.transmode.gradle:gradle-docker:1.2') 14 | classpath("org.freemarker:freemarker:$freemarker_version") 15 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 16 | classpath("org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version") 17 | 18 | classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1' 19 | } 20 | } 21 | 22 | group 'liuwill' 23 | version '1.0-SNAPSHOT' 24 | 25 | apply plugin: 'java' 26 | apply plugin: 'idea' 27 | apply plugin: 'application' 28 | apply plugin: "kotlin" 29 | apply plugin: 'findbugs' 30 | apply plugin: 'pmd' 31 | apply plugin: 'checkstyle' 32 | apply plugin: "jacoco" 33 | apply plugin: 'docker' 34 | apply plugin: 'org.springframework.boot' 35 | 36 | apply plugin: 'com.github.kt3k.coveralls' 37 | 38 | sourceCompatibility = 1.8 39 | targetCompatibility = 1.8 40 | 41 | repositories { 42 | mavenCentral() 43 | maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} 44 | maven{ url 'http://maven.oschina.net/content/groups/public/'} 45 | jcenter() 46 | } 47 | 48 | dependencies { 49 | // tag::jetty[] 50 | compile("org.springframework.boot:spring-boot-starter-web") { 51 | exclude module: "spring-boot-starter-tomcat" 52 | } 53 | compile("org.springframework.boot:spring-boot-starter-freemarker") 54 | compile("org.springframework.boot:spring-boot-starter-jetty") 55 | // end::jetty[] 56 | // tag::actuator[] 57 | compile("org.springframework.boot:spring-boot-starter-actuator") 58 | 59 | compile "org.freemarker:freemarker:$freemarker_version" 60 | 61 | // https://mvnrepository.com/artifact/com.alibaba/fastjson 62 | compile group: 'com.alibaba', name: 'fastjson', version: '1.2.23' 63 | 64 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 65 | compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" 66 | 67 | testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" 68 | testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" 69 | testCompile group: 'junit', name: 'junit', version: '4.12' 70 | testCompile("org.springframework.boot:spring-boot-starter-test") 71 | } 72 | 73 | jar { 74 | baseName = 'boot-kotlin-app' 75 | version = '0.1.0' 76 | } 77 | 78 | bootRepackage { 79 | mainClass = 'com.liuwill.demo.kotlinBoot.SpringBootKotlinApplicationKt' 80 | } 81 | 82 | mainClassName = 'com.liuwill.demo.kotlinBoot.SpringBootKotlinApplicationKt' 83 | 84 | task buildDocker(type: Docker, dependsOn: build, group: "custom") { 85 | push = true 86 | applicationName = jar.baseName 87 | dockerfile = file('src/main/docker/Dockerfile') 88 | doFirst { 89 | copy { 90 | from jar 91 | into stageDir 92 | } 93 | } 94 | } 95 | 96 | task runDocker(type:Exec,group: "custom"){ 97 | println "$groupName/$jar.baseName" 98 | commandLine "bash","src/scripts/runDocker.sh","$groupName","$jar.baseName" 99 | //commandLine "docker","run -p 8080:8080 -t $group/$jar.baseName" 100 | //store the output instead of printing to the console: 101 | standardOutput = new ByteArrayOutputStream() 102 | 103 | //extension method stopTomcat.output() can be used to obtain the output: 104 | ext.output = { 105 | return standardOutput.toString() 106 | } 107 | } 108 | 109 | sourceSets{ 110 | main{ 111 | java {srcDir "src/main/java"} 112 | kotlin {srcDir "src/main/kotlin"} 113 | resources {srcDir "src/main/resources"} 114 | } 115 | test{ 116 | java {srcDir "src/test/java"} 117 | kotlin {srcDir "src/test/kotlin"} 118 | resources {srcDir "src/test/resources"} 119 | } 120 | } 121 | 122 | compileKotlin { 123 | kotlinOptions.suppressWarnings = true 124 | } 125 | 126 | tasks.withType(JavaCompile) { 127 | options.encoding = 'UTF-8' 128 | } 129 | 130 | task createJavaProject { 131 | doLast { 132 | sourceSets*.java.srcDirs*.each { it.mkdirs() } 133 | sourceSets*.kotlin.srcDirs*.each { it.mkdirs() } 134 | sourceSets*.resources.srcDirs*.each { it.mkdirs()} 135 | } 136 | } 137 | 138 | /* 139 | test { 140 | //exclude 'com.liuwill.text.tools.*' 141 | filter { 142 | //include all integration tests 143 | includeTestsMatching "*Test" 144 | 145 | //include all tests from package 146 | includeTestsMatching "com.liuwill.kata.test.*" 147 | } 148 | }*/ 149 | 150 | // [ FindBugs Start**/ 151 | findbugs{ 152 | ignoreFailures=true 153 | findbugsTest.enabled=false 154 | } 155 | 156 | tasks.withType(FindBugs) { 157 | reports { 158 | xml.enabled = false 159 | html.enabled = true 160 | } 161 | } 162 | // ] FindBugs End**/ 163 | 164 | task stage(group: "custom"){ 165 | dependsOn "build" 166 | } 167 | 168 | checkstyle{ 169 | toolVersion = '7.8.2' 170 | } 171 | 172 | tasks.withType(Checkstyle) { 173 | reports { 174 | // xml.enabled = false 175 | // html.enabled = true 176 | // html.stylesheet resources.text.fromFile('config/xsl/checkstyle-custom.xsl') 177 | } 178 | configFile = file('config/checkstyle/checkstyle.xml') 179 | } 180 | 181 | jacoco{ 182 | toolVersion = "0.7.9" 183 | // reportsDir = file("$buildDir/customJacocoReportDir") 184 | } 185 | 186 | jacocoTestReport { 187 | reports{ 188 | xml.enabled = true 189 | html.enabled = true 190 | csv.enabled = false 191 | // html.destination = "${buildDir}/jacocoHtml" 192 | } 193 | } 194 | 195 | jacocoTestCoverageVerification { 196 | violationRules { 197 | rule { 198 | limit { 199 | minimum = 0.85 200 | } 201 | } 202 | 203 | rule { 204 | enabled = false 205 | element = 'CLASS' 206 | includes = ['com.liuwill.*'] 207 | 208 | limit { 209 | counter = 'LINE' 210 | value = 'TOTALCOUNT' 211 | maximum = 0.3 212 | } 213 | } 214 | } 215 | } -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 70 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 102 | 103 | 104 | 106 | 107 | 108 | 109 | 111 | 112 | 113 | 114 | 116 | 117 | 118 | 119 | 121 | 122 | 123 | 124 | 125 | 127 | 128 | 129 | 130 | 132 | 133 | 134 | 135 | 137 | 138 | 139 | 140 | 142 | 143 | 144 | 145 | 147 | 149 | 151 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuwill-projects/SpringBootKotlin/a406e70a19a14dfd607db2bcb061b1787745d1f6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 17 23:46:41 CST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-bin.zip -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then 166 | cd "$(dirname "$0")" 167 | fi 168 | 169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 170 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'SpringBootKotlin' 2 | 3 | -------------------------------------------------------------------------------- /src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | #FROM frolvlad/alpine-oraclejdk8:slim 2 | #FROM java:openjdk-9 3 | FROM java:openjdk-8-alpine 4 | VOLUME /tmp 5 | ADD boot-kotlin-app-0.1.0.jar app.jar 6 | RUN sh -c 'touch /app.jar' 7 | ENV JAVA_OPTS="" 8 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] -------------------------------------------------------------------------------- /src/main/java/com/liuwill/demo/kotlinboot/controllers/ShowController.java: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.controllers; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.http.MediaType; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * Created by liu will on 2017/3/16. 14 | */ 15 | @RestController 16 | @RequestMapping(value = "v1/api/data") 17 | public class ShowController { 18 | @RequestMapping( 19 | value = "", 20 | method = {RequestMethod.PUT}, 21 | consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE}) 22 | public Map index(@RequestBody HashMap reqBody) { 23 | return reqBody; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/kotlin/com/liuwill/demo/kotlinboot/SpringBootKotlinApplication.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot 2 | 3 | import org.springframework.boot.SpringApplication 4 | import org.springframework.boot.autoconfigure.SpringBootApplication 5 | 6 | /** 7 | * Created by liuwill on 2017/3/15. 8 | */ 9 | @SpringBootApplication 10 | open class SpringBootKotlinApplication 11 | 12 | fun main(args: Array) { 13 | SpringApplication.run(SpringBootKotlinApplication::class.java, *args) 14 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/liuwill/demo/kotlinboot/controllers/DataController.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.controllers 2 | 3 | import org.springframework.http.MediaType 4 | import org.springframework.web.bind.annotation.RequestBody 5 | import org.springframework.web.bind.annotation.RequestMapping 6 | import org.springframework.web.bind.annotation.RequestMethod 7 | import org.springframework.web.bind.annotation.RestController 8 | 9 | /** 10 | * Created by liuwill on 2017/3/15. 11 | */ 12 | @RestController 13 | @RequestMapping(value = "/api/data") 14 | class DataController { 15 | 16 | @RequestMapping(value = "", method = arrayOf(RequestMethod.GET, RequestMethod.PUT)) 17 | fun index(): Map { 18 | val resultMap = HashMap() 19 | 20 | resultMap["status"] = true 21 | resultMap["code"] = "100010" 22 | resultMap["msg"] = "success" 23 | resultMap["data"] = "data" 24 | return resultMap 25 | } 26 | 27 | @RequestMapping(value = "show", method = arrayOf(RequestMethod.PUT), consumes = arrayOf(MediaType.APPLICATION_JSON_UTF8_VALUE)) 28 | fun test(@RequestBody reqMap: Map): Map { 29 | return reqMap 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/kotlin/com/liuwill/demo/kotlinboot/controllers/HomeController.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.controllers 2 | 3 | import org.springframework.stereotype.Controller 4 | import org.springframework.ui.ModelMap 5 | import org.springframework.web.bind.annotation.RequestMapping 6 | import org.springframework.web.bind.annotation.RequestMethod 7 | 8 | /** 9 | * Created by liuwill on 2017/3/17. 10 | */ 11 | @Controller 12 | @RequestMapping(value = "/") 13 | class HomeController { 14 | @RequestMapping(value = "/index", method = arrayOf(RequestMethod.GET)) 15 | fun index(pageModal: ModelMap): String { 16 | pageModal["data"] = "success" 17 | return "index" 18 | } 19 | 20 | @RequestMapping(value = "/", method = arrayOf(RequestMethod.GET)) 21 | fun home(pageModal: ModelMap): String { 22 | pageModal["data"] = "success" 23 | return "index" 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/resources/config/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | #local.server.port = 8888 3 | 4 | spring.resources.chain.strategy.content.enabled=true 5 | spring.resources.chain.strategy.content.paths=/static/** 6 | spring.mvc.static-path-pattern=/static/** # Path pattern used for static resources. 7 | 8 | spring.freemarker.cache=false 9 | spring.freemarker.charset=UTF-8 10 | spring.freemarker.check-template-location=true 11 | spring.freemarker.content-type=text/html 12 | spring.freemarker.expose-request-attributes=true 13 | spring.freemarker.expose-session-attributes=true 14 | spring.freemarker.request-context-attribute=request 15 | spring.freemarker.settings.classic_compatible=true 16 | -------------------------------------------------------------------------------- /src/main/resources/config/front.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liuwill-projects/SpringBootKotlin/a406e70a19a14dfd607db2bcb061b1787745d1f6/src/main/resources/config/front.properties -------------------------------------------------------------------------------- /src/main/resources/templates/index.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | Spring Boot Kotlin 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/com/liuwill/demo/kotlinboot/test/integration/DataControllerStandaloneTest.java: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.test.integration; 2 | 3 | /** 4 | * Created by liuwill on 2017/3/17. 5 | */ 6 | 7 | import com.liuwill.demo.kotlinboot.controllers.DataController; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 13 | import org.springframework.http.MediaType; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | import org.springframework.test.web.servlet.MockMvc; 16 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 17 | import org.springframework.web.context.WebApplicationContext; 18 | 19 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 20 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 22 | 23 | @RunWith(SpringRunner.class) 24 | @WebMvcTest(DataController.class) 25 | public class DataControllerStandaloneTest { 26 | 27 | 28 | private WebApplicationContext wac; 29 | @Autowired 30 | private MockMvc mvc; 31 | 32 | @Before 33 | public void setUp() throws Exception { 34 | //mvc = MockMvcBuilders.standaloneSetup(new DataController()).build(); 35 | } 36 | 37 | @Test 38 | public void getData() throws Exception { 39 | String expectStr = "{\"msg\":\"success\",\"code\":\"100010\",\"data\":\"data\",\"status\":true}"; 40 | mvc.perform(MockMvcRequestBuilders.get("/api/data") 41 | .accept(MediaType.APPLICATION_JSON)) 42 | .andExpect(status().isOk()) 43 | .andExpect(content().json(expectStr)); 44 | } 45 | 46 | @Test 47 | public void getDataShow() throws Exception { 48 | String expectStr = "{\"msg\":\"hello\"}"; 49 | mvc.perform( 50 | MockMvcRequestBuilders.put("/api/data/show") 51 | .contentType(MediaType.APPLICATION_JSON) 52 | .content(expectStr) 53 | .accept(MediaType.APPLICATION_JSON) 54 | ) 55 | .andExpect(status().isOk()) 56 | .andExpect(content().json(expectStr)) 57 | .andDo(print()); 58 | } 59 | } -------------------------------------------------------------------------------- /src/test/java/com/liuwill/demo/kotlinboot/test/integration/ShowControllerStandaloneTest.java: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.test.integration; 2 | 3 | /** 4 | * Created by liuwill on 2017/3/17. 5 | */ 6 | 7 | import com.liuwill.demo.kotlinboot.controllers.ShowController; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 13 | import org.springframework.http.MediaType; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | import org.springframework.test.web.servlet.MockMvc; 16 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 17 | import org.springframework.web.context.WebApplicationContext; 18 | 19 | import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 20 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 22 | 23 | @RunWith(SpringRunner.class) 24 | @WebMvcTest(ShowController.class) 25 | public class ShowControllerStandaloneTest { 26 | 27 | 28 | private WebApplicationContext wac; 29 | @Autowired 30 | private MockMvc mvc; 31 | 32 | @Before 33 | public void setUp() throws Exception { 34 | //mvc = MockMvcBuilders.standaloneSetup(new DataController()).build(); 35 | } 36 | 37 | @Test 38 | public void getData() throws Exception { 39 | String expectStr = "{\"msg\":\"hello\"}"; 40 | mvc.perform( 41 | MockMvcRequestBuilders.put("/v1/api/data") 42 | .contentType(MediaType.APPLICATION_JSON) 43 | .content(expectStr) 44 | .accept(MediaType.APPLICATION_JSON) 45 | ) 46 | .andExpect(status().isOk()) 47 | .andExpect(content().json(expectStr)) 48 | .andDo(print()); 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/liuwill/demo/kotlinboot/test/acceptence/HomeControllerWebTest.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.test.acceptence 2 | 3 | import com.liuwill.demo.kotlinboot.SpringBootKotlinApplication 4 | import org.hamcrest.Matchers.* 5 | import org.junit.Assert.assertThat 6 | import org.junit.runner.RunWith 7 | import org.springframework.boot.test.context.SpringBootTest 8 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 9 | import org.springframework.boot.context.embedded.LocalServerPort 10 | import org.springframework.boot.test.web.client.TestRestTemplate 11 | import org.springframework.beans.factory.annotation.Autowired 12 | import org.junit.Before 13 | import org.junit.Test 14 | import java.net.URL 15 | 16 | /** 17 | * Created by liuwill on 2017/3/17. 18 | */ 19 | @RunWith(SpringJUnit4ClassRunner::class) // SpringJUnit支持,由此引入Spring-Test框架支持! 20 | @SpringBootTest(classes = arrayOf(SpringBootKotlinApplication::class), webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 21 | class HomeControllerWebTest { 22 | @LocalServerPort 23 | private val port: Int = 0 24 | 25 | private var base: URL? = null 26 | 27 | @Autowired 28 | private val restTemplate: TestRestTemplate? = null 29 | 30 | @Before 31 | @Throws(Exception::class) 32 | fun setUp() { 33 | this.base = URL("http://localhost:$port/index.html") 34 | } 35 | 36 | @Test 37 | @Throws(Exception::class) 38 | fun getIndex() { 39 | val response = restTemplate?.getForEntity(base.toString(), String::class.java) 40 | assertThat(response?.statusCodeValue, equalTo(200)) 41 | assertThat(response?.body, containsString("Spring Boot Kotlin")) 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/liuwill/demo/kotlinboot/test/integration/HomeControllerMvcTest.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.test.integration 2 | 3 | import com.liuwill.demo.kotlinboot.SpringBootKotlinApplication 4 | import org.junit.runner.RunWith 5 | import org.springframework.boot.test.context.SpringBootTest 6 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 7 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.model 8 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.view 9 | import org.springframework.test.web.servlet.setup.MockMvcBuilders 10 | import org.junit.Before 11 | import org.junit.Test 12 | import org.springframework.test.web.servlet.MockMvc 13 | import org.springframework.web.context.WebApplicationContext 14 | import org.springframework.beans.factory.annotation.Autowired 15 | import org.springframework.http.MediaType 16 | 17 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get 18 | import org.springframework.test.web.servlet.result.MockMvcResultHandlers.print 19 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* 20 | 21 | 22 | /** 23 | * Created by liuwill on 2017/3/17. 24 | */ 25 | @RunWith(SpringJUnit4ClassRunner::class) // SpringJUnit支持,由此引入Spring-Test框架支持! 26 | @SpringBootTest(classes = arrayOf(SpringBootKotlinApplication::class), webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 27 | class HomeControllerMvcTest { 28 | @Autowired 29 | private val wac: WebApplicationContext? = null 30 | 31 | private var mvc: MockMvc? = null 32 | 33 | @Before 34 | @Throws(Exception::class) 35 | fun setUp() { 36 | mvc = MockMvcBuilders.webAppContextSetup(wac!!).build() 37 | } 38 | 39 | @Test 40 | @Throws(Exception::class) 41 | fun index() { 42 | this.mvc!!.perform(get("/index") 43 | .accept(MediaType.TEXT_HTML)) 44 | .andExpect(status().isOk()) 45 | .andExpect(view().name("index")) 46 | .andExpect(model().attributeExists("data")) 47 | .andExpect(model().attribute("data", "success")) 48 | .andDo(print()) 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/kotlin/com/liuwill/demo/kotlinboot/test/integration/HomeControllerStandaloneTest.kt: -------------------------------------------------------------------------------- 1 | package com.liuwill.demo.kotlinboot.test.integration 2 | 3 | import com.liuwill.demo.kotlinboot.controllers.HomeController 4 | import org.hamcrest.CoreMatchers.containsString 5 | import org.junit.Before 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | import org.springframework.beans.factory.annotation.Autowired 9 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest 10 | import org.springframework.http.MediaType 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner 12 | import org.springframework.test.web.servlet.MockMvc 13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders 14 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* 15 | 16 | @RunWith(SpringJUnit4ClassRunner::class) 17 | @WebMvcTest(HomeController::class) 18 | class HomeControllerStandaloneTest { 19 | 20 | //private val wac: WebApplicationContext? = null 21 | 22 | @Autowired 23 | private var mvc: MockMvc? = null 24 | 25 | @Before 26 | @Throws(Exception::class) 27 | fun setUp() { 28 | //mvc = MockMvcBuilders.standaloneSetup(HomeController()).build() 29 | } 30 | 31 | @Test 32 | @Throws(Exception::class) 33 | fun indexTest() { 34 | mvc!!.perform(MockMvcRequestBuilders.get("/").accept(MediaType.TEXT_HTML)) 35 | .andExpect(status().isOk) 36 | .andExpect(model().attributeExists("data")) 37 | .andExpect { content().string(containsString("Spring Boot Kotlin")) } 38 | } 39 | } --------------------------------------------------------------------------------