VMware certification · Exam 2V0-72.22

2V0-72.22 Mock Exam

Professional Develop VMware Spring

Find out if you're ready for 2V0-72.22. Take the free timed mock exam and get your score in minutes, or study the free 2V0-72.22 questions below with answers and explanations.

20 questions · 33 minutes · free, no sign-up

Free 2V0-72.22 questions

1–10 of 23 free
Question 1 Choose 1
Refer to the exhibit.

How can a response status code be set for No Content (204)? (Choose the best answer.)
Show answerHide answer

Correct answer: B Annotate the update() handler method with @ResponseStatus(HttpStatus.NO_CONTENT).

Explanation

Explanation:

In Spring MVC, to set a fixed HTTP status code for a handler method (such as 204 No Content), you use the @ResponseStatus annotation at the method level.

@ResponseStatus(HttpStatus.NO_CONTENT) tells Spring to respond with HTTP 204 when the method completes successfully, regardless of the return type (including void).

204 No Content is commonly used for PUT, POST, or DELETE requests where the server successfully processes the request but has no response body to return.

❌ Why the others are incorrect

A – @PutMapping does not accept a status code as an argument. The @RequestMapping variants (like @PutMapping) only accept path, headers, produces/consumes, etc. Putting HttpStatus.NO_CONTENT there is syntactically invalid.

C – @ResponseEntity is a class, not an annotation. Returning new ResponseEntity<>(HttpStatus.NO_CONTENT) would work, but @ResponseEntity(204) is not valid annotation syntax. The question asks for annotating the method, not returning a specific type.

D – False. A handler method can return void (e.g., when using @ResponseStatus), and Spring still sends the correct status code. Returning ResponseEntity is one option but not required.

📘 Reference

Spring Framework Documentation — @ResponseStatus annotation: "Marks a method or exception class with the status code and reason that should be returned."

HTTP 204: Successful request, no content to send in response body.
Question 2 Choose 1
Refer to the exhibit.

How can a Spring Bean be created from this LegacySingleton class?
Show answerHide answer

Correct answer: A Call LegacySingleton.getInstance() from within a @Bean method and return the instance.

Explanation

Explanation

The LegacySingleton class (from the exhibit — assumed to have a private constructor and a static getInstance() method, typical of a classic Singleton pattern) cannot be instantiated with the new keyword from outside the class.

Spring can still manage it as a bean by using a @Bean method that calls the static factory method getInstance() and returns that instance. Spring will then register that returned object as a singleton bean in its IoC container.

❌ Why the others are incorrect

B – Incorrect because if the constructor is private (as in typical Singleton), new LegacySingleton() will cause a compilation error. The question’s “LegacySingleton” strongly implies a classic Singleton with a private constructor.

C – False. You can create a Spring bean without modifying the class, by using a factory method (@Bean wrapping getInstance()). Modifying the class is not necessary.

D – False. Adding @Autowired to the instance variable does nothing to create a bean from the class. @Autowired is for dependency injection, not bean definition. The class would still need a way to be instantiated by Spring (which it doesn’t have without modification).

📘 Reference

Spring Framework Documentation — Instantiating beans via static factory method: “You can also use the @Bean method to call a static factory method and return the object.”

This approach is commonly used to integrate legacy code or third-party classes that control their own instantiation.
Question 3 Choose 1
Refer to the exhibit.

It is a Java code fragment from a Spring application. Which statement is true with regard to the above example? (Choose the best answer.)
Show answerHide answer

Correct answer: D It will return a bean of the type ClientService regardless of its id or name.

Explanation

Explanation:

The method context.getBean(ClientService.class) uses Spring’s BeanFactory.getBean(Class requiredType) overload. This variant retrieves a bean by type, not by name. It returns any bean whose runtime type matches ClientService (including subclasses or implementations), regardless of its bean ID or name. If exactly one matching bean exists, it is returned successfully. If zero beans match, Spring throws NoSuchBeanDefinitionException. If multiple beans of the same type exist (and none is marked @Primary), Spring throws NoUniqueBeanDefinitionException.

This syntax is valid and type-safe, requiring no explicit cast, unlike the older getBean(String) method.

❌ Why other options are incorrect:

A – False. No cast is needed because getBean(Class) returns T directly. Casting would be redundant and unnecessary.

B – False. The method does not look up a bean by its name (“ClientService”). It looks up by type (the ClientService class). A bean named differently (e.g., clientServiceImpl) but of the correct type would still be returned.

C – False. The bean ID is not required as a method parameter. The Class parameter is the only required argument for this overload. The string-based name lookup is a different method: getBean(String name).

📚 References

Spring Framework 5.x API Documentation – BeanFactory.getBean(Class requiredType):
“Return an instance, which may be shared or independent, of the specified bean. This method allows a Spring-style lookup by type.”

Spring Core Documentation – BeanFactory APIs:
“The getBean(Class) method is type-safe and resolves a single bean matching the given type, irrespective of the bean name.”
Question 4 Choose 1
Refer to the exhibit.

Which statement is true? (Choose the best answer.)
Show answerHide answer

Correct answer: C An implementation of this repository can be automatically generated by Spring Data JPA.

Explanation

Explanation:

CustomerRepository extends CrudRepository, which is a Spring Data marker interface. When Spring Data JPA (or Spring Data JDBC) is on the classpath and @EnableJpaRepositories (or equivalent) is used, Spring Data automatically generates a proxy implementation of this interface at runtime. The developer does not write an implementation class — Spring creates it dynamically, including basic CRUD methods, query derivation, and @Query handling.

❌ Why other options are incorrect:

A – False. In Spring Data, repositories must be interfaces. Concrete classes are not supported for automatic proxy generation. The interface is the correct design.

B – False. For Spring Data JDBC specifically, JPA annotations (like @Entity, @Id) are not required. Spring Data JDBC uses its own lightweight persistence model (e.g., @Id from Spring Data Commons, not JPA). JPA annotations are optional or irrelevant here.

D – False. No manual implementation class is needed. Spring Data generates the implementation automatically at runtime and registers it as a Spring bean. Writing a custom implementation would defeat the purpose of Spring Data.

📚 References

Spring Data JPA Documentation – "Using Repositories":
“Spring Data JPA provides an implementation of the repository interface automatically. You only need to write the interface definition.”

Spring Data Commons – CrudRepository JavaDoc:
“Central interface in Spring Data repository abstraction. Implemented by Spring Data modules automatically at runtime.”
Question 5 Choose 3
Which three dependencies are provided by the spring-boot-starter-test? (Choose three.)
Show answerHide answer

Correct answer: B, C, D Hamcrestspring-testJunit

Explanation

Explanation

The spring-boot-starter-test starter POM is designed to provide a comprehensive set of testing libraries for Spring Boot applications. According to the official Spring Boot documentation, this starter includes JUnit, Spring Test & Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, JsonPath, and Awaitility .

B. Hamcrest – Included as a library of matcher objects (constraints or predicates) that allow expressive assertThat style assertions in tests .

C. spring-test – Included as part of Spring Test & Spring Boot Test modules, providing utilities and integration test support for Spring applications .

D. Junit – JUnit 5 (JUnit Jupiter) is included as the de-facto standard for unit testing Java applications. The starter also includes the vintage engine for backward compatibility with JUnit 4 tests .

❌ Why other options are incorrect:

A. Cucumber – Not included in spring-boot-starter-test. Cucumber is a separate BDD (Behavior-Driven Development) framework that must be added as an explicit dependency if needed.

E. EasyMock – Not included. While spring-boot-starter-test provides Mockito as its mocking framework, EasyMock is a different mocking library that requires a separate dependency .

F. PowerMock – Not included. PowerMock is an advanced mocking framework that extends other mocking libraries like Mockito or EasyMock. It is not part of the starter and must be added separately.

📚 Valid References

Spring Boot Official Documentation – "Test Scope Dependencies":
"The spring-boot-starter-test starter (in the test scope) contains the following provided libraries: JUnit 5, Spring Test & Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, JsonPath, Awaitility"

Spring Boot Reference Guide (1.2.1.RELEASE) – Section 35.1:
"If you use the spring-boot-starter-test 'Starter POM', you will find the following provided libraries: Spring Test, JUnit, Hamcrest and Mockito"
Question 6 Choose 2
Refer to the exhibit.

AppConfig is a Java configuration class. Which two statements are true? (Choose two.)
Show answerHide answer

Correct answer: D, E The bean is of type clientService and by default will be a Singleton.The Java configuration can be profile specific by adding a @Profile annotation.

Explanation

Explanation:

Bean Type and Scope (Option D):
The method signature returns a ClientService object, making that the registered bean type. In Spring, all beans declared via the @Bean annotation default to singleton scope. The IoC container creates exactly one instance, caching it for all subsequent requests during the application lifecycle.

Profile Configuration (Option E):
The @Profile annotation can be placed at the class level of a @Configuration class (or directly on @Bean methods). This instructs Spring to only register these beans when the specified environment profile (e.g., dev, prod) is active.

Why the Other Options Are Incorrect

A is incorrect:
Spring beans are singletons by default. A prototype scope (which creates a new instance every time the bean is requested) must be explicitly configured using @Scope("prototype").

B is incorrect:
The method name clientService() is perfectly valid. In Spring Java configuration, the method name serves automatically as the default bean identifier (id).

C is incorrect:
Singleton beans are eagerly initialized at application startup to catch configuration errors early. To make a bean initialize only when first requested, you must explicitly annotate it with @Lazy.

References

Spring Framework Core Documentation: Section 1.12.1: Declaring a Bean – States that the return type dictates the bean type and the method name serves as the bean ID.

Spring Framework Core Documentation: Section 1.5: Bean Scopes – Confirms that the singleton scope is the default fallback for all Spring beans.
Question 7 Choose 1
Refer to the exhibit.

What statement is true about @DirtiesContext?
Show answerHide answer

Correct answer: B It will close the existing cached ApplicationContext and recreate a new one after the test method.

Explanation

Explanation:

@DirtiesContext is a Spring Test annotation that indicates the ApplicationContext should be marked as "dirty" after the test method (or test class) has been executed. When a context is dirty, Spring Test will close the existing cached ApplicationContext and recreate a new one for any subsequent tests that require a fresh context.

By default, @DirtiesContext recreates the context after the test method runs. This ensures that any side effects from the test (e.g., modified beans, changed database state, altered system properties) do not leak into other tests that share the same context.

❌ Why other options are incorrect:

A – False.Before the test method is too early. The default behavior is after the test method, not before. However, @DirtiesContext(methodMode = BEFORE_METHOD) exists as an option, but the default (and most common usage) is after.

C – False. @DirtiesContext does not revert changes within the same context. Instead, it discards the entire context and creates a new one. Reverting changes without recreation is not how this annotation works.

D – False. Spring does not selectively recreate only modified beans. The entire ApplicationContext is closed and rebuilt, which is more expensive but guarantees a completely fresh state.

📚 References

Spring Framework Testing Documentation – @DirtiesContext:
“Annotation indicating that the ApplicationContext associated with a test is dirty and should be closed. It will be removed from the context cache and recreated for subsequent tests.”

Spring Test Context Framework – Context caching:
“By default, the context is marked dirty after the test method. The next test requiring a context of the same configuration will trigger a new context to be built.”
Question 8 Choose 2
Which two statements are true about Spring AOP? (Choose two.)
Show answerHide answer

Correct answer: A, D The @After advice type is invoked regardless of whether a method successfully returned or an exception was thrown.Examples of cross-cutting concerns include security, caching, transaction.

Explanation

Explanation

@After Advice Behavior (Option A):
Often referred to as "after (finally)" advice, @After mirrors a standard Java finally block. It executes immediately after a matched method completes its runtime execution, whether that completion is a normal return or an abrupt exit due to an uncaught exception.

Cross-Cutting Concerns (Option D):
These represent system-wide auxiliary functionalities that span across multiple, distinct layers of an application. Instead of duplicating logic like security checks, performance caching, or database transaction management inside every business service method, Aspect-Oriented Programming (AOP) modularizes them into clean, reusable aspects.

Why the Other Options Are Incorrect

B is incorrect:
Spring AOP utilizes a pure proxy-based architecture, meaning it only supports method execution join points. Property/field access interception is not supported by Spring AOP (it requires a full AspectJ framework setup).

C is incorrect:
Spring AOP integrates and directly uses AspectJ's pointcut expression language parser for matching pointcuts. It uses annotations like @Pointcut("execution(...)" directly out of the box.

E is incorrect:
There are 5 types of advice in Spring AOP, not 4. The missing type is @Around, which is the most powerful advice type capable of wrapping around the entire target method execution.

References

Spring Framework Documentation: Core Technologies - Aspect Oriented Programming with Spring:

Section 5.2.1 (AOP Concepts): Outlines the 5 advice types (including Around) and defines cross-cutting concerns.
Question 9 Choose 1
Refer to the exhibit.

Assume that the application is using Spring transaction management which uses Spring AOP internally.

Choose the statement that describes what is happening when the update1 method is called? (Choose the best answer.)
Show answerHide answer

Correct answer: D There is only one transaction initiated by update1() because the call to update2() does not go through the proxy.

Explanation

Explanation:

In Spring transaction management using proxy-based AOP (the default), transactional behavior is applied only when a method is called through the Spring proxy. When update1() calls update2() internally using this.update2(), the call bypasses the proxy entirely — it is a direct Java method invocation on the actual object, not on the proxy. Therefore, update2()'s @Transactional(propagation = REQUIRES_NEW) annotation is ignored. Only the transaction started by update1() (if any) is active. No new transaction is created for update2().

❌ Why other options are incorrect:

A – False. REQUIRES_NEW would start a new transaction only if the call is made through the proxy. With internal this call, it does not. The statement assumes correct proxy invocation, which is not the case here.

B – False. Spring does not throw an exception when trying to start a new transaction within an existing one via REQUIRES_NEW (when properly proxied). Even if it fails due to proxy issues, no such exception is defined.

C – False.REQUIRES_NEW never uses an active transaction. Its semantics are: suspend any existing transaction and always start a new one. This option misdescribes REQUIRES_NEW regardless of proxy issues.

References

Spring Framework Documentation – Transaction Management (Proxy limitations):
“Only external method calls coming in through the proxy are intercepted. Self-invocation (calling a method within the same target object) does not lead to an actual transaction at runtime.” — Spring Core documentation, "Using @Transactional"
Question 10 Choose 2
Refer to the exhibit.

Which two statements are correct regarding the HelloAutoConfig auto-configuration class when it is specified in the META-INF/spring.factories file? (Choose two.)
Show answerHide answer

Correct answer: B, D A HelloService bean will be created from the helloService() method only when there is no other HelloService bean in the ApplicationContext.This auto-configuration class is used only when the HelloService.class is on the classpath.

Explanation

Explanation

This auto-configuration class follows Spring Boot's conditional auto-configuration pattern. When specified in META-INF/spring.factories (or META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports in Spring Boot 2.7+), it participates in auto-configuration with two conditional checks:

@ConditionalOnClass(HelloService.class) – The configuration class is only loaded if HelloService.class is present on the classpath. Otherwise, the entire HelloAutoConfig is ignored.

@ConditionalOnMissingBean(HelloService.class) – The helloService() @Bean method is only invoked if no bean of type HelloService already exists in the ApplicationContext.

Thus:

D is correct – Auto-configuration class is used only when HelloService.class is on the classpath.

B is correct – The bean is created only when there is no other HelloService bean already defined.

❌ Why other options are incorrect:

A – False. @ConditionalOnClass requires HelloService.class to be present. If not on classpath, the configuration is not processed, and no bean is created.

C – False. This is the opposite of @ConditionalOnClass behavior. The class is used when the class is present, not when absent.

E – False. @ConditionalOnMissingBean prevents bean creation if one already exists. It does not replace existing beans. To replace, you would need @ConditionalOnMissingBean with custom logic or @Primary, but not this.

📚 References

Spring Boot Auto-configuration Documentation:
"Auto-configuration is conditional using @ConditionalOnClass and @ConditionalOnMissingBean to control when configuration applies and when beans are created."

@ConditionalOnClass JavaDoc:
"Condition that only matches when the specified classes are on the classpath."
Full mock exam

Sit the 2V0-72.22 exam before exam day

Full-length mocks with the same number of questions and the same time limit as the real 2V0-72.22 exam. Every attempt draws a new set of questions from the full bank, so you can keep going until you pass comfortably.

Get full 2V0-72.22 mock exam
  • 65questions per mock
  • 105 mintime limit
  • 79questions in the bank
  • Newmock on every attempt