0
0
Spring Bootframework~10 mins

Project structure walkthrough in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ASpringBootApp
BMainApp
CApplication
DMyApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name that does not match in the run method.
Forgetting the @SpringBootApplication annotation.
2fill in blank
medium

Complete 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'
AgetHello
Bhello
Cgreet
DsayHello
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that do not reflect the HTTP method.
Missing the @GetMapping annotation.
3fill in blank
hard

Fix 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'
Aport
Bhost
Caddress
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'server.host' instead of 'server.port'.
Setting properties in the wrong file.
4fill in blank
hard

Fill 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'
AMessageService
BMessageController
DHelloService
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching class names between service and controller.
Forgetting to annotate the service class with @Service.
5fill in blank
hard

Fill 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'
AUserRepository
BUser
CLong
DUserService
Attempts:
3 left
💡 Hint
Common Mistakes
Using service class names instead of repository names.
Incorrect generic types in JpaRepository.