Update start.spring.io and change package
This commit is contained in:
22
README.adoc
22
README.adoc
@@ -23,15 +23,14 @@ First we need to create a Spring Boot application, which can be done in a number
|
|||||||
|
|
||||||
Visit https://start.spring.io and choose the Kotlin language. Or visit https://start.spring.io/#!language=kotlin to preselect Kotlin.
|
Visit https://start.spring.io and choose the Kotlin language. Or visit https://start.spring.io/#!language=kotlin to preselect Kotlin.
|
||||||
|
|
||||||
. let the default "Maven Project" or select "Gradle Project" depending on which build topl you want to use
|
. Let the default "Maven Project" or select "Gradle Project" depending on which build tool you want to use
|
||||||
. Click "Switch to the full version" and enter the following artifact coordinates:
|
. Enter the following artifact coordinates: `blog`
|
||||||
- **Artifact:** `blog`
|
|
||||||
- **Package Name:** `blog`
|
|
||||||
. Add the following dependencies:
|
. Add the following dependencies:
|
||||||
- Web
|
- Web
|
||||||
- Mustache
|
- Mustache
|
||||||
- JPA
|
- JPA
|
||||||
- H2
|
- H2
|
||||||
|
- Devtools
|
||||||
. Click "Generate Project".
|
. Click "Generate Project".
|
||||||
|
|
||||||
image::./images/initializr.png[]
|
image::./images/initializr.png[]
|
||||||
@@ -46,7 +45,7 @@ You can use the Initializr HTTP API https://docs.spring.io/initializr/docs/curre
|
|||||||
[source]
|
[source]
|
||||||
----
|
----
|
||||||
$ mkdir blog && cd blog
|
$ mkdir blog && cd blog
|
||||||
$ curl https://start.spring.io/starter.zip -d language=kotlin -d style=web,mustache,jpa,h2 -d packageName=blog -d name=Blog -o blog.zip
|
$ curl https://start.spring.io/starter.zip -d language=kotlin -d style=web,mustache,jpa,h2,devtools -d packageName=com.example.blog -d name=Blog -o blog.zip
|
||||||
----
|
----
|
||||||
|
|
||||||
Add `-d type=gradle-project` if you want to use Gradle.
|
Add `-d type=gradle-project` if you want to use Gradle.
|
||||||
@@ -60,12 +59,11 @@ To access the wizard, go to File | New | Project, and select Spring Initializr.
|
|||||||
|
|
||||||
Follow the steps of the wizard to use the following parameters:
|
Follow the steps of the wizard to use the following parameters:
|
||||||
|
|
||||||
- Package name: "blog"
|
|
||||||
- Artifact: "blog"
|
- Artifact: "blog"
|
||||||
- Type: Maven project or Gradle Project
|
- Type: Maven project or Gradle Project
|
||||||
- Language: Kotlin
|
- Language: Kotlin
|
||||||
- Name: "Blog"
|
- Name: "Blog"
|
||||||
- Dependencies: "Web", "Mustache", JPA" and "H2"
|
- Dependencies: "Web", "Mustache", JPA", "H2" and "Devtool"
|
||||||
|
|
||||||
[[reveal-gradle]]
|
[[reveal-gradle]]
|
||||||
[.reveal-gradle]
|
[.reveal-gradle]
|
||||||
@@ -142,6 +140,7 @@ dependencies {
|
|||||||
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
|
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||||
|
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
runtimeOnly 'com.h2database:h2'
|
runtimeOnly 'com.h2database:h2'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
}
|
}
|
||||||
@@ -248,6 +247,11 @@ Notice also that Kotlin compiler is configured to generate Java 8 bytecode (Java
|
|||||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
@@ -266,7 +270,7 @@ Notice also that Kotlin compiler is configured to generate Java 8 bytecode (Java
|
|||||||
`src/main/kotlin/blog/BlogApplication.kt`
|
`src/main/kotlin/blog/BlogApplication.kt`
|
||||||
[source,kotlin]
|
[source,kotlin]
|
||||||
----
|
----
|
||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
@@ -298,7 +302,7 @@ Let's create a simple controller to display a simple web page.
|
|||||||
`src/main/kotlin/blog/HtmlController.kt`
|
`src/main/kotlin/blog/HtmlController.kt`
|
||||||
[source,kotlin]
|
[source,kotlin]
|
||||||
----
|
----
|
||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.ui.Model
|
import org.springframework.ui.Model
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ dependencies {
|
|||||||
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
|
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||||
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
implementation 'org.jetbrains.kotlin:kotlin-reflect'
|
||||||
runtime 'com.h2database:h2'
|
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
|
||||||
|
runtimeOnly 'com.h2database:h2'
|
||||||
kapt 'org.springframework.boot:spring-boot-configuration-processor'
|
kapt 'org.springframework.boot:spring-boot-configuration-processor'
|
||||||
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
testImplementation('org.springframework.boot:spring-boot-starter-test') {
|
||||||
exclude module: 'junit'
|
exclude module: 'junit'
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 74 KiB |
7
pom.xml
7
pom.xml
@@ -50,12 +50,17 @@
|
|||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-reflect</artifactId>
|
<artifactId>kotlin-reflect</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package blog
|
|
||||||
|
|
||||||
import org.springframework.boot.ApplicationRunner
|
|
||||||
import org.springframework.context.annotation.Bean
|
|
||||||
import org.springframework.context.annotation.Configuration
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
class BlogConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
fun databaseInitializer(userRepository: UserRepository,
|
|
||||||
articleRepository: ArticleRepository) = ApplicationRunner {
|
|
||||||
|
|
||||||
val smaldini = userRepository.save(User("smaldini", "Stéphane", "Maldini"))
|
|
||||||
articleRepository.save(Article(
|
|
||||||
title = "Reactor Bismuth is out",
|
|
||||||
headline = "Lorem ipsum",
|
|
||||||
content = "dolor sit amet",
|
|
||||||
author = smaldini
|
|
||||||
))
|
|
||||||
articleRepository.save(Article(
|
|
||||||
title = "Reactor Aluminium has landed",
|
|
||||||
headline = "Lorem ipsum",
|
|
||||||
content = "dolor sit amet",
|
|
||||||
author = smaldini
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||||
28
src/main/kotlin/com/example/blog/BlogConfiguration.kt
Normal file
28
src/main/kotlin/com/example/blog/BlogConfiguration.kt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package com.example.blog
|
||||||
|
|
||||||
|
import org.springframework.boot.ApplicationRunner
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Configuration
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class BlogConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun databaseInitializer(userRepository: UserRepository,
|
||||||
|
articleRepository: ArticleRepository) = ApplicationRunner {
|
||||||
|
|
||||||
|
val smaldini = userRepository.save(User("smaldini", "Stéphane", "Maldini"))
|
||||||
|
articleRepository.save(Article(
|
||||||
|
title = "Reactor Bismuth is out",
|
||||||
|
headline = "Lorem ipsum",
|
||||||
|
content = "dolor sit amet",
|
||||||
|
author = smaldini
|
||||||
|
))
|
||||||
|
articleRepository.save(Article(
|
||||||
|
title = "Reactor Aluminium has landed",
|
||||||
|
headline = "Lorem ipsum",
|
||||||
|
content = "dolor sit amet",
|
||||||
|
author = smaldini
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import javax.persistence.*
|
import javax.persistence.*
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatterBuilder
|
import java.time.format.DateTimeFormatterBuilder
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller
|
import org.springframework.stereotype.Controller
|
||||||
import org.springframework.ui.Model
|
import org.springframework.ui.Model
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*
|
import org.springframework.web.bind.annotation.*
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository
|
import org.springframework.data.repository.CrudRepository
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.springframework.boot.test.context.SpringBootTest
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import com.ninjasquad.springmockk.MockkBean
|
import com.ninjasquad.springmockk.MockkBean
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions.*
|
import org.assertj.core.api.Assertions.*
|
||||||
import org.junit.jupiter.api.AfterAll
|
import org.junit.jupiter.api.AfterAll
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package blog
|
package com.example.blog
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
Reference in New Issue
Block a user