0
0
Spring Bootframework~10 mins

Why enterprise patterns matter in Spring Boot - Test Your Understanding

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

Complete the code to define a Spring Boot main application class.

Spring Boot
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.[1](Application.class, args);
    }
}
Drag options to blanks, or click blank then click option'
Arun
Bstart
Claunch
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'launch' instead of 'run' causes errors.
Forgetting to call a method to start the app.
2fill in blank
medium

Complete the code to declare a Spring component for dependency injection.

Spring Boot
import org.springframework.stereotype.[1];

@[1]
public class Service {
    // service logic
}
Drag options to blanks, or click blank then click option'
AComponent
BService
CRepository
DController
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Service or @Repository when a generic component is needed.
Forgetting to annotate the class for Spring to detect it.
3fill in blank
hard

Fix the error in the code to inject a repository into a service using constructor injection.

Spring Boot
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserService {
    private final UserRepository userRepository;

    @Autowired
    public UserService([1] userRepository) {
        this.userRepository = userRepository;
    }
}
Drag options to blanks, or click blank then click option'
AUserService
BUserRepository
CRepository
DUserRepo
Attempts:
3 left
💡 Hint
Common Mistakes
Using the service class type as parameter causes errors.
Using incorrect or undefined types for injection.
4fill in blank
hard

Fill both blanks to create a REST controller method that handles GET requests and returns a list.

Spring Boot
import org.springframework.web.bind.annotation.[1];
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class ItemController {

    @[2]("/items")
    public List<String> getItems() {
        return List.of("apple", "banana", "cherry");
    }
}
Drag options to blanks, or click blank then click option'
AGetMapping
BPostMapping
CRequestMapping
DDeleteMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping or @DeleteMapping for GET requests.
Importing a different annotation than the one used.
5fill in blank
hard

Fill all three blanks to define a Spring Data JPA repository interface for an entity User with Long id.

Spring Boot
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.[1];

@[1]
public interface UserRepository extends JpaRepository<[2], [3]> {
}
Drag options to blanks, or click blank then click option'
ARepository
BUser
CLong
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Service instead of @Repository.
Mixing up entity and ID types in JpaRepository.