This is a simple Kotlin Spring Boot assignment to experiment with Drop Project.
In this assignment you will create a small Spring Boot application that uses dependency injection. You will implement two classes:
- A service that builds greeting messages.
- A command-line runner that uses that service to print a greeting when the application starts.
Your project must be a maven project and use the following versions and dependencies:
- Java: 17
- Kotlin: 1.9.25
- Spring Boot: 3.5.10
- Build tool: Maven
Dependencies:
spring-boot-starterkotlin-reflectkotlin-stdlib
Important: Your pom.xml must match these versions and dependencies exactly, otherwise Drop Project will not be
able to compile and test your submission.
-
Create a Kotlin Spring Boot project in your IDE with the package
org.dropproject.samples.samplekotlinspringassignment. Start by creating a file calledSampleKotlinSpringAssignmentApplication.ktin that package with the following code:package org.dropproject.samples.samplekotlinspringassignment import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @SpringBootApplication class SampleKotlinSpringAssignmentApplication fun main(args: Array<String>) { runApplication<SampleKotlinSpringAssignmentApplication>(*args) }
This is the entry point of your Spring Boot application. Do not modify it.
-
Create a file called
GreetingService.ktin the package above and implement a class calledGreetingService. This class must:-
Be annotated with
@Service(fromorg.springframework.stereotype.Service), so that Spring registers it as a bean. -
Contain a function with the following signature:
fun greet(name: String): StringThis function must return the string
"Hello, <name>!", where<name>is replaced by the argument. For example,greet("World")must return"Hello, World!"andgreet("Kotlin")must return"Hello, Kotlin!".
-
-
Create a file called
HelloRunner.ktin the package above and implement a class calledHelloRunner. This class must:- Be annotated with
@Component(fromorg.springframework.stereotype.Component). - Implement the
CommandLineRunnerinterface (fromorg.springframework.boot.CommandLineRunner). - Receive a
GreetingServiceinstance through constructor injection. - In its
runmethod, use the injectedGreetingServiceto print"Hello, World!"to the standard output (i.e., callgreetingService.greet("World")and print the result usingprintln).
- Be annotated with
-
Create an
AUTHORS.txtfile in the root of your project with your student (github) id and name. For example:<github_id>;John Doe
The idea of this file is to allow group project submissions.
- Create a zip file of your project and drop it on the area above these instructions. In a few seconds, Drop Project will give you a report with some metrics about your project.