2V0-72-22 VMware Practice Questions
Prepare for 2V0-72-22 with more than an answer.
- Exam fee
- $250 USD
- Level
- Professional
- Valid for
- No expiration
Domains covered on the exam 6
- Spring Core25%
- Data Management20%
- Spring MVC20%
- Testing15%
- Security10%
- Spring Boot30%
- 1
A developer is writing an integration test for a service layer that interacts with a database. To ensure the test is isolated, they want to use an in-memory H2 database only for the test run. The main application uses PostgreSQL. What is the most idiomatic Spring Boot approach to achieve this?
Show answer details
Correct answer: B
This is the standard and simplest way in Spring Boot. If an embedded database driver (like H2) is found on the classpath with
testscope, Spring Boot'sDataSourceAutoConfigurationwill favor it over other configured datasources during the test phase, automatically setting up an in-memory database without needing explicit configuration files. - 2
A developer needs to inject a list of all beans that implement the
PaymentGatewayinterface into a service. Which of the following injection points correctly accomplishes this?Show answer details
Correct answer: D
Spring's dependency injection container has built-in support for collecting all beans of a certain type. By autowiring a
List, Spring will find all beans that implementInterfaceTypein the application context and inject them as a list into the field. - 3
A Spring Boot application is being deployed to a new environment where the HTTP port must be configured via an environment variable named
APP_PORT. Which entry inapplication.propertiesallows the application to use this environment variable, while defaulting to port 8080 if it's not set?Show answer details
Correct answer: A
This syntax correctly uses a property placeholder. Spring Boot will first look for an environment variable or system property named
APP_PORT. If it is not found, it will fall back to the default value of8080provided after the colon. - 4
Scenario
A logistics company is developing aShipmentTrackingService. This service consumes messages from an external system via an API, processes them, and updates the shipment status in a database. The processing logic is complex and can occasionally fail due to transient network issues or invalid data. The architects have decided to use Spring's AOP to implement a retry mechanism for the core processing method.Code
@Service public class ShipmentProcessor { @Transactional @Retryable(value = DataAccessException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000)) public void processShipment(ShipmentData data) { // ... database update logic ... if (isInvalid(data)) { throw new InvalidShipmentDataException("Invalid data"); } } }Requirements
- The method should retry up to 3 times if a
DataAccessExceptionoccurs. - If an
InvalidShipmentDataException(which is aRuntimeExceptionbut not aDataAccessException) is thrown, the method should NOT retry, and the transaction should be rolled back immediately. - The retry and transactional behaviors must work together correctly.
Question
Given the code and requirements, what is the expected behavior whenprocessShipmentis called with data that causes anInvalidShipmentDataException?Show answer details
Correct answer: B
This is the correct behavior. The
@Retryableannotation is configured to only retry onDataAccessException. SinceInvalidShipmentDataExceptionis not aDataAccessException(or a subclass of it), the retry advice will not trigger. Because it is an uncheckedRuntimeException, the default behavior of@Transactionalwill be to mark the transaction for rollback. Therefore, the method fails immediately, and the transaction is rolled back. - The method should retry up to 3 times if a
- 5
A service method in
ServiceAcalls a public method inServiceB. Both methods are annotated with@Transactional(propagation = Propagation.REQUIRES_NEW). What is the transactional behavior when the method inServiceAis invoked?sequenceDiagram participant Client participant ServiceA participant ServiceB participant DB as Database Client->>ServiceA: invokeMethodA() Note over ServiceA,DB: Start Transaction A ServiceA->>ServiceB: invokeMethodB() Note over ServiceA: Suspend Transaction A Note over ServiceB,DB: Start Transaction B ServiceB-->>ServiceA: return Note over ServiceB,DB: Commit/Rollback Transaction B Note over ServiceA: Resume Transaction A ServiceA-->>Client: return Note over ServiceA,DB: Commit/Rollback Transaction AShow answer details
Correct answer: C
Propagation.REQUIRES_NEWalways starts a new, independent transaction. If an existing transaction is active, it will be suspended. The inner transaction inServiceBcan commit or roll back without affecting the outcome of the outer transaction inServiceA. - 6
A development team is building a library of custom Spring Boot auto-configurations. To ensure a custom configuration
MyCustomAutoConfigurationis only activated when theThirdPartyService.classis present on the classpath, and a bean of typeDataSourcehas already been configured by another auto-configuration, which combination of annotations should be used on the configuration class?Show answer details
Correct answer: B
The correct approach is to use
@ConditionalOnClass(ThirdPartyService.class)to check for the presence of the class on the classpath, and@ConditionalOnBean(DataSource.class)to ensure aDataSourcebean is already present in the context before this configuration is applied.@Configurationis necessary to mark the class as a source of bean definitions. - 7
A developer is implementing an AOP aspect to log method executions. They notice that when a public method calls another public method within the same service bean, the advice is not triggered for the second, inner method call. What is the fundamental reason for this behavior in Spring's proxy-based AOP?
Show answer details
Correct answer: B
Spring AOP works by creating a proxy object that wraps the actual bean. External calls go through the proxy, allowing advices to be applied. However, an internal method call (
this.innerMethod()) is a direct invocation on the target object itself, completely bypassing the proxy and any associated AOP logic. This is known as the self-invocation problem. - 8
A financial application needs to perform a complex operation involving two separate database updates. The outer service method,
transferFunds(), is annotated with@Transactional(propagation = Propagation.REQUIRED). It calls an inner service method,logAudit(), which must commit its record regardless of whether thetransferFundsoperation succeeds or fails. Which propagation level should be applied to thelogAudit()method to achieve this behavior?Show answer details
Correct answer: D
REQUIRES_NEWstarts a new, independent transaction for thelogAudit()method. The existing transaction (fromtransferFunds()) is suspended. This allows the inner transaction to commit on its own, ensuring the audit log is saved even if the outer transaction fails and rolls back. - 9
A developer needs to configure a Spring Security setup for a REST API. The requirement is to allow unauthenticated access to
/api/public/**endpoints, while all other endpoints under/api/**must be authenticated. Which two of the followingHttpSecurityconfigurations correctly implement this requirement? (Select TWO)Show answer details
Correct answer: B, D
This configuration correctly uses the principle of ordering matchers from most specific to most general. It first permits all access to
/api/public/**and then requires authentication for all other/api/**paths.This is also a correct and common pattern. It permits access to the public endpoints and then uses
anyRequest().authenticated()as a catch-all to secure everything else. Since/api/public/**is matched first, it works as required. - 10
When writing a slice test for a Spring Data JPA repository using
@DataJpaTest, the test transaction will, by default, roll back at the end of each test method.Show answer details
Correct answer: A
The
@DataJpaTestannotation is meta-annotated with@Transactional. In a test context,@Transactionalensures that each test method runs in a transaction that is rolled back by default upon completion. This keeps tests isolated and prevents them from polluting the database state for subsequent tests.
