diff --git a/README.adoc b/README.adoc index f3148bd..ac03eb1 100644 --- a/README.adoc +++ b/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. - . let the default "Maven Project" or select "Gradle Project" depending on which build topl you want to use - . Click "Switch to the full version" and enter the following artifact coordinates: - - **Artifact:** `blog` - - **Package Name:** `blog` + . Let the default "Maven Project" or select "Gradle Project" depending on which build tool you want to use + . Enter the following artifact coordinates: `blog` . Add the following dependencies: - Web - Mustache - JPA - H2 + - Devtools . Click "Generate Project". image::./images/initializr.png[] @@ -46,7 +45,7 @@ You can use the Initializr HTTP API https://docs.spring.io/initializr/docs/curre [source] ---- $ 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. @@ -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: - - Package name: "blog" - Artifact: "blog" - Type: Maven project or Gradle Project - Language: Kotlin - Name: "Blog" - - Dependencies: "Web", "Mustache", JPA" and "H2" + - Dependencies: "Web", "Mustache", JPA", "H2" and "Devtool" [[reveal-gradle]] [.reveal-gradle] @@ -142,6 +140,7 @@ dependencies { implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' implementation 'org.jetbrains.kotlin:kotlin-reflect' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + runtimeOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'com.h2database:h2' 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 kotlin-stdlib-jdk8 + + org.springframework.boot + spring-boot-devtools + runtime + com.h2database h2 @@ -266,7 +270,7 @@ Notice also that Kotlin compiler is configured to generate Java 8 bytecode (Java `src/main/kotlin/blog/BlogApplication.kt` [source,kotlin] ---- -package blog +package com.example.blog import org.springframework.boot.autoconfigure.SpringBootApplication 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` [source,kotlin] ---- -package blog +package com.example.blog import org.springframework.stereotype.Controller import org.springframework.ui.Model diff --git a/build.gradle b/build.gradle index 5b7f806..6220217 100644 --- a/build.gradle +++ b/build.gradle @@ -57,7 +57,8 @@ dependencies { implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' 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' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude module: 'junit' diff --git a/images/initializr.png b/images/initializr.png index 5ea82ea..4c8b160 100644 Binary files a/images/initializr.png and b/images/initializr.png differ diff --git a/pom.xml b/pom.xml index c8c00bc..1209460 100644 --- a/pom.xml +++ b/pom.xml @@ -50,12 +50,17 @@ org.jetbrains.kotlin kotlin-reflect + + + org.springframework.boot + spring-boot-devtools + runtime + com.h2database h2 runtime - org.springframework.boot spring-boot-starter-test diff --git a/src/main/kotlin/blog/BlogConfiguration.kt b/src/main/kotlin/blog/BlogConfiguration.kt deleted file mode 100644 index 76f10d4..0000000 --- a/src/main/kotlin/blog/BlogConfiguration.kt +++ /dev/null @@ -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 - )) - } -} diff --git a/src/main/kotlin/blog/BlogApplication.kt b/src/main/kotlin/com/example/blog/BlogApplication.kt similarity index 93% rename from src/main/kotlin/blog/BlogApplication.kt rename to src/main/kotlin/com/example/blog/BlogApplication.kt index e1741b7..e9f7593 100644 --- a/src/main/kotlin/blog/BlogApplication.kt +++ b/src/main/kotlin/com/example/blog/BlogApplication.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.context.properties.EnableConfigurationProperties diff --git a/src/main/kotlin/com/example/blog/BlogConfiguration.kt b/src/main/kotlin/com/example/blog/BlogConfiguration.kt new file mode 100644 index 0000000..d878c54 --- /dev/null +++ b/src/main/kotlin/com/example/blog/BlogConfiguration.kt @@ -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 + )) + } +} diff --git a/src/main/kotlin/blog/BlogProperties.kt b/src/main/kotlin/com/example/blog/BlogProperties.kt similarity index 93% rename from src/main/kotlin/blog/BlogProperties.kt rename to src/main/kotlin/com/example/blog/BlogProperties.kt index 84a8341..46f4a0b 100644 --- a/src/main/kotlin/blog/BlogProperties.kt +++ b/src/main/kotlin/com/example/blog/BlogProperties.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.springframework.boot.context.properties.ConfigurationProperties diff --git a/src/main/kotlin/blog/Entities.kt b/src/main/kotlin/com/example/blog/Entities.kt similarity index 95% rename from src/main/kotlin/blog/Entities.kt rename to src/main/kotlin/com/example/blog/Entities.kt index 97ae319..e32543e 100644 --- a/src/main/kotlin/blog/Entities.kt +++ b/src/main/kotlin/com/example/blog/Entities.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import java.time.LocalDateTime import javax.persistence.* diff --git a/src/main/kotlin/blog/Extensions.kt b/src/main/kotlin/com/example/blog/Extensions.kt similarity index 97% rename from src/main/kotlin/blog/Extensions.kt rename to src/main/kotlin/com/example/blog/Extensions.kt index 682b9e3..e458eca 100644 --- a/src/main/kotlin/blog/Extensions.kt +++ b/src/main/kotlin/com/example/blog/Extensions.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import java.time.LocalDateTime import java.time.format.DateTimeFormatterBuilder diff --git a/src/main/kotlin/blog/HtmlController.kt b/src/main/kotlin/com/example/blog/HtmlController.kt similarity index 97% rename from src/main/kotlin/blog/HtmlController.kt rename to src/main/kotlin/com/example/blog/HtmlController.kt index 380b1c9..045e066 100644 --- a/src/main/kotlin/blog/HtmlController.kt +++ b/src/main/kotlin/com/example/blog/HtmlController.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.springframework.stereotype.Controller import org.springframework.ui.Model diff --git a/src/main/kotlin/blog/HttpControllers.kt b/src/main/kotlin/com/example/blog/HttpControllers.kt similarity index 96% rename from src/main/kotlin/blog/HttpControllers.kt rename to src/main/kotlin/com/example/blog/HttpControllers.kt index 60d4aec..67601b8 100644 --- a/src/main/kotlin/blog/HttpControllers.kt +++ b/src/main/kotlin/com/example/blog/HttpControllers.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.springframework.web.bind.annotation.* diff --git a/src/main/kotlin/blog/Repositories.kt b/src/main/kotlin/com/example/blog/Repositories.kt similarity index 92% rename from src/main/kotlin/blog/Repositories.kt rename to src/main/kotlin/com/example/blog/Repositories.kt index a95b66d..5ed2fc8 100644 --- a/src/main/kotlin/blog/Repositories.kt +++ b/src/main/kotlin/com/example/blog/Repositories.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.springframework.data.repository.CrudRepository diff --git a/src/test/kotlin/blog/BlogApplicationTests.kt b/src/test/kotlin/com/example/blog/BlogApplicationTests.kt similarity index 87% rename from src/test/kotlin/blog/BlogApplicationTests.kt rename to src/test/kotlin/com/example/blog/BlogApplicationTests.kt index f70f0b0..c95fcaf 100644 --- a/src/test/kotlin/blog/BlogApplicationTests.kt +++ b/src/test/kotlin/com/example/blog/BlogApplicationTests.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.junit.jupiter.api.Test import org.springframework.boot.test.context.SpringBootTest diff --git a/src/test/kotlin/blog/HttpControllersTests.kt b/src/test/kotlin/com/example/blog/HttpControllersTests.kt similarity index 98% rename from src/test/kotlin/blog/HttpControllersTests.kt rename to src/test/kotlin/com/example/blog/HttpControllersTests.kt index c189620..cee0a4d 100644 --- a/src/test/kotlin/blog/HttpControllersTests.kt +++ b/src/test/kotlin/com/example/blog/HttpControllersTests.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import com.ninjasquad.springmockk.MockkBean import io.mockk.every diff --git a/src/test/kotlin/blog/IntegrationTests.kt b/src/test/kotlin/com/example/blog/IntegrationTests.kt similarity index 98% rename from src/test/kotlin/blog/IntegrationTests.kt rename to src/test/kotlin/com/example/blog/IntegrationTests.kt index f645b84..af2de22 100644 --- a/src/test/kotlin/blog/IntegrationTests.kt +++ b/src/test/kotlin/com/example/blog/IntegrationTests.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.assertj.core.api.Assertions.* import org.junit.jupiter.api.AfterAll diff --git a/src/test/kotlin/blog/RepositoriesTests.kt b/src/test/kotlin/com/example/blog/RepositoriesTests.kt similarity index 98% rename from src/test/kotlin/blog/RepositoriesTests.kt rename to src/test/kotlin/com/example/blog/RepositoriesTests.kt index 65cadd6..a714a32 100644 --- a/src/test/kotlin/blog/RepositoriesTests.kt +++ b/src/test/kotlin/com/example/blog/RepositoriesTests.kt @@ -1,4 +1,4 @@ -package blog +package com.example.blog import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test