2V0-72-22 Sample Questions

2V0-72-22 Sample Questions & Answers

Spring Boot's own features, properties and actuator carry the most weight, next to the core framework, Java config and profiles, Spring's JDBC layer and transactions, putting together web and REST endpoints, testing via MockMVC, and basic security setup.

Launch the full 2V0-72-22 simulator →

Showing 10 of 20 free samples.

  1. Question 1Beginner

    Spring Boot · Spring Boot Properties and Autoconfiguration

    A Spring Boot application needs to connect to a database whose credentials are provided via environment variables DB_URL, DB_USER, and DB_PASS. The application.properties file contains the following entries:

    spring.datasource.url=${DB_URL:jdbc:h2:mem:defaultdb}
    spring.datasource.username=${DB_USER:sa}
    spring.datasource.password=${DB_PASS:}

    If the DB_USER environment variable is NOT set, but DB_URL and DB_PASS are, what value will be used for the datasource username?

    Show answer & explanation

    Correct answer: B

    The syntax ${PROPERTY:defaultValue} is used for property placeholders. If the PROPERTY (in this case, the DB_USER environment variable) is not found, the defaultValue (sa) will be used instead.

  2. Question 2Intermediate

    Spring MVC · REST Applications

    An architect is designing a REST API using Spring MVC. The API needs to return different JSON representations of a User object depending on the endpoint. For example, /api/users/{id} should return all user fields, but /api/users/summary should return only the id and username. What is the most appropriate Spring feature to implement this requirement without creating separate DTOs (Data Transfer Objects) for each view?

    Show answer & explanation

    Correct answer: C

    Jackson's @JsonView annotation, which is well-integrated with Spring MVC, is designed for this exact purpose. It allows you to define multiple 'views' (e.g., public, internal) on a single model object and then specify which view to use for serialization at the controller method level, enabling different JSON outputs from the same object.

  3. Question 3Intermediate

    Spring Core · Spring Bean Lifecycle

    A developer needs to create a Spring bean that calculates a value based on other beans, but this calculation only needs to happen once at startup. The result should then be cached and injected into other components. Which combination of annotations and lifecycle callbacks is most suitable for this scenario?

    Show answer & explanation

    Correct answer: D

    This is the ideal approach. A singleton bean is created only once. Injecting dependencies via the constructor ensures they are available when the bean is initialized. The @PostConstruct annotation guarantees the calculation method runs after dependency injection is complete but before the bean is made available to other components. The result can be stored in a field for subsequent use.

  4. Question 4Intermediate

    Data Management · Introduction to Spring JDBC

    A Spring Boot application uses a JdbcTemplate to perform database queries. During a code review, a senior developer points out a potential SQL injection vulnerability in the following code snippet:

    String status = "ACTIVE";
    String sql = "SELECT * FROM users WHERE status = '" + status + "'";
    jdbcTemplate.query(sql, userRowMapper);

    What is the best way to refactor this code to prevent the SQL injection vulnerability?

    Show answer & explanation

    Correct answer: C

    The correct and standard way to prevent SQL injection is to use parameterized queries (prepared statements). The JdbcTemplate supports this by using ? as a placeholder in the SQL string and passing the actual values as separate arguments to the query method. This ensures user input is treated as data, not executable code. The refactored code would be: String sql = "SELECT * FROM users WHERE status = ?"; jdbcTemplate.query(sql, new Object[]{status}, userRowMapper);

  5. Question 5Advanced

    Spring Boot · Spring Boot Actuator

    Company Background
    A large e-commerce company, "ShopFast", is modernizing its monolithic backend. They are adopting a microservices architecture and have chosen Spring Boot for new services. One of the first services being built is the OrderProcessingService. This service needs to be highly available and observable.

    Current Situation
    The development team has built the core logic for the OrderProcessingService. It exposes several REST endpoints for creating and querying orders. The service interacts with a PostgreSQL database and a RabbitMQ message queue. The company has a centralized Prometheus server for metrics collection and Grafana for dashboarding. The security team mandates that all management endpoints must be secured and only accessible by administrators.

    Requirements

    1. The service must expose its operational status, including database connectivity and message queue health.
    2. Key business metrics, such as orders_created and order_processing_time, must be exposed in a format compatible with Prometheus.
    3. All management and monitoring endpoints must be exposed on a separate port from the main application port (8080) for security reasons.
    4. Access to these management endpoints must be restricted to users with the ADMIN role.

    Question
    Which set of configurations in application.properties and dependencies in pom.xml will satisfy all the stated requirements?

    Show answer & explanation

    Correct answer: D

    This solution correctly addresses all requirements. spring-boot-starter-actuator provides the health and metrics endpoints. micrometer-registry-prometheus ensures metrics are in the Prometheus format. management.server.port=9090 isolates the management endpoints. management.endpoints.web.exposure.include=* exposes all endpoints, including the required health and prometheus ones. Finally, adding spring-boot-starter-security and configuring HttpSecurity allows for role-based access control to the actuator path, fulfilling the security requirement.

  6. Question 6Advanced

    Spring Core · Properties and Profiles

    A developer is using Spring Expression Language (SpEL) to conditionally create a bean. The goal is to create the EmailService bean only if the application profile is 'production' AND a system property named 'email.enabled' is set to 'true'. Which @ConditionalOnExpression annotation is correct?

    Show answer & explanation

    Correct answer: A

    This SpEL expression is correct. environment.acceptsProfiles('production') is the proper way to check the active profile within a SpEL context. systemProperties['email.enabled'] == 'true' correctly accesses the system property and performs a string comparison. The and operator combines the two conditions as required.

  7. Question 7Advanced

    Security · Define Method-level Security

    A developer wants to implement method-level security on a service method. The requirement is that only users who have the role 'ADMIN' OR are the owner of the account can invoke the getAccountDetails method. The method signature is getAccountDetails(String username). How should the @PreAuthorize annotation be written to enforce this rule?

    Show answer & explanation

    Correct answer: D

    This SpEL expression correctly implements the logic. hasRole('ADMIN') checks for the required role. The or operator provides the alternative condition. authentication.name accesses the username of the currently authenticated principal, and #username refers to the username argument passed to the method, allowing for the ownership check.

  8. Question 8BeginnerSelect 2

    Spring MVC · Web Applications with Spring Boot

    Which of the following statements accurately describe the differences between @RestController and @Controller in Spring MVC? (Select TWO)

    Show answer & explanation

    Correct answers: A, D

    This is the primary definition of @RestController. It is a stereotype annotation that implies both @Controller (making it a candidate for component scanning and web request handling) and @ResponseBody (indicating that the return value of every handler method should be written directly to the response body).

    By default, the return value of a method in a @Controller class is interpreted as a view name to be resolved by a ViewResolver. In contrast, because @RestController implies @ResponseBody on all methods, their return values are serialized (e.g., to JSON) and sent in the response body.

  9. Question 9Intermediate

    Spring Boot · Spring Boot Actuator

    A developer needs to create a custom health indicator for a Spring Boot application that checks the status of an external REST service. Which interface must the developer implement to create this custom health check?

    Show answer & explanation

    Correct answer: B

    To create a custom health check that integrates with the Spring Boot Actuator's /health endpoint, a developer must implement the HealthIndicator interface and override its health() method. The implementation should return a Health object indicating the status (e.g., UP, DOWN).

  10. Question 10Intermediate

    Spring Core · Spring Bean Lifecycle

    True or False: A BeanPostProcessor allows you to modify the bean definition, such as changing its scope or property values, before the bean is instantiated.

    Show answer & explanation

    Correct answer: A

    This statement is false. A BeanPostProcessor operates on bean instances after they have been created. It cannot modify the bean definition itself. The component responsible for modifying bean definitions before instantiation is the BeanFactoryPostProcessor.

Ready for the real thing?

The full 2V0-72-22 simulator has every exam-style question, timed mode, and instant scoring.