Kotlin Web Development Tutorial "one" from zero build Kotlin and Spring boot development environment

Source: Internet
Author: User

Idea Chinese Input method's smart cue box does not follow the cursor problem I use the development tool is ideas this version of ideas has a problem; the Chinese input method of the smart box does not follow the cursor to solve the problem is very simple, only in the installation directory to change the JRE folder name, or just delete it. After doing so, idea will automatically use your system's JRE environment my system is jdk1.8.0_131; If you don't set your environment variable, you can now set it up: First add a Java_home variable to the system variable, Point to your JDK directory and then add the following record in the path variable so that the Chinese input method can follow the cursor; It is not recommended to use jdk9.0.1 (I have stepped on the pit on this, remember is gradle not recognize this version of the JDK, had to roll back to the JDK1.8) using the Spring boot website tools to build the project open: http://start.spring.io/ Choose to create a Gradle project using the Kotlin programming language using the highest 2.0.0 spring The group general format of the boot Framework project is as follows: Com.baidu.projectname Engineering's artifact generally directly fill in the project name dependencies are important, and our project uses the following dependencies:
    • Web: Contains all the things Spring Mvc,tomcat needs (Spring boot is based on spring MVC);
    • devtools:srping boot development tools, such as "Hot deployment", etc.
    • Jpa:orm Frame
    • Mysql:mysql's JDBC Driver
    • Actuator: Application configuration and application monitoring tools
    • Freemarker: page template engine, somewhat similar to ASP. NET MVC Razor
The result of the final selection is as follows: then click on Build Project, then you will get a compressed package decompression, open the Extract directory with idea and idea will download a bunch of libraries and then get the following project: NOTE: If you run the above project, idea will prompt an error message.
Cannot determine embedded database driver class for database type NONE
This is mostly not good configuration work caused by the Gradle configuration first look at the gradle configuration file: Build.gradle (under the project root) where the dependencies section is a dependency configuration: note: The following code is automatically generated without any modification, here is just a description of the configuration
dependencies {
compile(‘org.springframework.boot:spring-boot-starter-actuator‘)
compile(‘org.springframework.boot:spring-boot-starter-data-jpa‘)
compile(‘org.springframework.boot:spring-boot-starter-freemarker‘)
compile(‘org.springframework.boot:spring-boot-starter-web‘)
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8")
compile("org.jetbrains.kotlin:kotlin-reflect")
runtime(‘org.springframework.boot:spring-boot-devtools‘)
runtime(‘mysql:mysql-connector-java‘)
testCompile(‘org.springframework.boot:spring-boot-starter-test‘)
}
Let's take a brief look:
    • Spring-boot-starter-actuator:springboot of the Health inspection Monitoring component
    • SPRING-BOOT-STARTER-DATA-JPA:JPA Starter
    • Spring-boot-starter-freemarker:freemarker Starter
    • Kotlin-stdlib-jre8:kotlin based on the Jre8 standard library
    • Kotlin-reflect:kotlin Reflection Library
    • Spring-boot-devtools:spring-boot developer tools such as "Hot deployment", etc.
    • Mysql-connector-java:java's MySQL link tool
    • Spring-boot-starter-test:spring-boot Test Tool Launcher
Application.properties Configuration Then we open the Application.properties (under the Src/main/resources directory) and add the following code:
#data source
spring.datasource.url=jdbc:mysql://******.mysql.rds.aliyuncs.com:3306/yourDBName?characterEncoding=utf8&characterSetResults=utf8
spring.datasource.username=******
spring.datasource.password=******

spring.jpa.database=mysql
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=updateserver.port=8000spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.validation-query= Select 1
The first four sentences are mainly the database link string after the three sentence is set for JPA content Server.port is the description of what the service will run on what port to run again [YourName] Application.kt Debug area There will be a lot of debugging information if there is no problem, the last line of debugging information is as follows
2017-12-23 12:24:43.220  INFO 460 --- [  restartedMain] com.ysl.jna.jna.JnaApplicationKt         : Started JnaApplicationKt in 7.447 seconds (JVM running for 8.208)
Indicates that your app has started successfully; the second-to-last line of debugging information is as follows:
2017-12-23 13:30:39.642  INFO 6788 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ‘‘
You will see spring boot help you launch Tomcat, (you installed spring boot, he comes with you a Tomcat, save your own outfit) write a controller even if you finish the above configuration, but you visit Http://localhost:8000/, Still not getting any useful information.
Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Dec 24 17:14:43 CST 2017
There was an unexpected error (type=Not Found, status=404).
No message available
Note: your [projectname] Application.kt This file must be in the root directory of the package directory: as shown: (Otherwise you can not get the above error message) below we create the controller package and add the Hellocontroller class, the code is as follows:
package com.ysl.jna.controller

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HelloController{
@GetMapping(value = *arrayOf("/hello","/"))
fun hello():Any{
return "hello"
}
}
Then recompile the project re-visit http://localhost:8000/you will get the output you want
hello


Kotlin Web Development Tutorial "one" from zero build Kotlin and Spring boot development environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.