Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the main Spring Boot application class.
Spring Boot
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class [1] { public static void main(String[] args) { SpringApplication.run([1].class, args); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name that does not match in the run method.
Forgetting the @SpringBootApplication annotation.
✗ Incorrect
The main class is usually named Application or similar. Here, 'Application' is the correct class name used in the run method.
2fill in blank
mediumComplete the code to declare a REST controller in Spring Boot.
Spring Boot
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.GetMapping; @RestController public class HelloController { @GetMapping("/hello") public String [1]() { return "Hello, World!"; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not reflect the HTTP method.
Missing the @GetMapping annotation.
✗ Incorrect
The method name can be anything, but 'getHello' clearly indicates a GET request handler for /hello.
3fill in blank
hardFix the error in the Spring Boot application.properties file to set the server port.
Spring Boot
server.[1]=8081
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'server.host' instead of 'server.port'.
Setting properties in the wrong file.
✗ Incorrect
The correct property to set the server port is 'server.port'.
4fill in blank
hardFill both blanks to create a simple service class and inject it into a controller.
Spring Boot
import org.springframework.stereotype.Service; @Service public class [1] { public String getMessage() { return "Service message"; } } import org.springframework.web.bind.annotation.RestController; import org.springframework.beans.factory.annotation.Autowired; @RestController public class MessageController { private final [2] service; @Autowired public MessageController([2] service) { this.service = service; } public String showMessage() { return service.getMessage(); } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching class names between service and controller.
Forgetting to annotate the service class with @Service.
✗ Incorrect
The service class is named 'MessageService' and injected into the controller as the same type.
5fill in blank
hardFill all three blanks to define a Spring Data JPA repository interface.
Spring Boot
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface [1] extends JpaRepository<[2], [3]> { }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using service class names instead of repository names.
Incorrect generic types in JpaRepository.
✗ Incorrect
The repository interface is named 'UserRepository', managing 'User' entities with 'Long' as ID type.