VMware Spring Certified Professional (2V0-72.22) — Questions and Answers
Question 1: Which interface should a custom Spring REST error response class implement to integrate with Spring's default error handling mechanism?
- HandlerExceptionResolver
- ResponseBodyAdvice
- ErrorAttributes
- ErrorResponse (Correct answer)
Correct answer: ErrorResponse
Implementing ErrorResponse allows a custom exception to carry RFC 9457 Problem Details fields, which Spring's exception handlers can serialize automatically.
Question 2: In a Spring Boot REST API, which property controls the base path for all Spring Data REST endpoints?
- spring.mvc.base-path
- spring.data.rest.base-path (Correct answer)
- spring.rest.root-path
- server.rest.base-path
Correct answer: spring.data.rest.base-path
Setting spring.data.rest.base-path in application.properties changes the root URL under which all Spring Data REST endpoints are registered.
Question 3: What is the purpose of `@Column(nullable = false)` in a JPA entity?
- Enables unique constraint on that column
- Adds a NOT NULL constraint to the database column (Correct answer)
- Marks the column as the primary key
- Sets a default value for the column
Correct answer: Adds a NOT NULL constraint to the database column
`nullable = false` instructs the schema generation tool to add a NOT NULL constraint to the mapped column.
Question 4: Which Spring Boot auto-configuration class is responsible for setting up the default error handling endpoint at /error?
- BasicErrorController
- ErrorMvcAutoConfiguration (Correct answer)
- DefaultExceptionHandlerAutoConfiguration
- ServerErrorAutoConfiguration
Correct answer: ErrorMvcAutoConfiguration
ErrorMvcAutoConfiguration registers the BasicErrorController, DefaultErrorViewResolver, and supporting beans that power the default /error endpoint in Spring Boot.
Question 5: What does @ExtendWith(SpringExtension.class) do in a JUnit 5 Spring test?
- Loads the full Spring Boot auto-configuration
- Replaces @RunWith from JUnit 4
- Enables Mockito annotations only
- Integrates the Spring TestContext Framework with JUnit 5 (Correct answer)
Correct answer: Integrates the Spring TestContext Framework with JUnit 5
@ExtendWith(SpringExtension.class) hooks the Spring TestContext Framework lifecycle into JUnit 5, enabling Spring context loading and dependency injection in tests.
Question 6: Which annotation is used to embed a non-entity object as columns inside an entity's table?
- @ElementCollection
- @SecondaryTable
- @OneToOne with shared PK
- @Embedded / @Embeddable (Correct answer)
Correct answer: @Embedded / @Embeddable
@Embeddable marks a class whose fields are stored in the owning entity's table, and @Embedded is placed on the field in the entity.
Question 7: In a Spring REST API, what is the correct way to return a 404 Not Found response when a resource does not exist?
- Return ResponseEntity.notFound().build() (Correct answer)
- Use @ResponseStatus(HttpStatus.OK) with an empty body
- Return null from the controller method
- Throw a RuntimeException
Correct answer: Return ResponseEntity.notFound().build()
ResponseEntity.notFound().build() creates a ResponseEntity with HTTP 404 status and no body, which is the idiomatic Spring way to signal a missing resource.
Question 8: Which callback interface allows a bean to receive a reference to the ApplicationContext it lives in?
- EnvironmentAware
- ApplicationContextAware (Correct answer)
- ResourceLoaderAware
- BeanNameAware
Correct answer: ApplicationContextAware
Implementing ApplicationContextAware causes Spring to inject the ApplicationContext into the bean via setApplicationContext().
Question 9: What does the @DataJpaTest annotation do by default regarding the database?
- Connects to the configured production datasource
- Uses an in-memory embedded database and rolls back each test (Correct answer)
- Disables all transaction management
- Starts a full Spring context including all beans
Correct answer: Uses an in-memory embedded database and rolls back each test
@DataJpaTest auto-configures an embedded in-memory database and wraps each test in a transaction that rolls back after the test.
Question 10: Which JPQL clause filters query results equivalent to SQL's WHERE keyword?
- ON
- HAVING
- FILTER
- WHERE (Correct answer)
Correct answer: WHERE
JPQL uses the WHERE clause just like SQL to filter result sets based on conditions.
Question 11: Which annotation marks a method as a bean producer inside a @Configuration class?
- @Produces
- @Component
- @Bean (Correct answer)
- @Service
Correct answer: @Bean
@Bean annotates methods in @Configuration classes so Spring registers the return value as a managed bean.
Question 12: A developer needs to write a test for a Spring MVC `@RestController` that focuses exclusively on the web layer. The test should verify request mappings, JSON serialization/deserialization, and exception handling without loading the service or repository layers. Which annotation is most suitable for this purpose?
- `@DataJpaTest`
- `@SpringBootTest`
- `@WebMvcTest(MyController.class)` (Correct answer)
- `@ExtendWith(MockitoExtension.class)`
Correct answer: `@WebMvcTest(MyController.class)`
`@WebMvcTest` is a test slice annotation that sets up an application context containing only the beans necessary for testing the web layer, such as controllers, filters, and MVC infrastructure. [7, 11, 12] It does not load `@Service` or `@Repository` beans, making it lightweight and fast for focused controller testing. [7, 18] `@SpringBootTest` loads the entire application context, `@DataJpaTest` focuses on the persistence layer, and `@ExtendWith(MockitoExtension.class)` is a general JUnit 5 extension for Mockito, not specific to Spring's web layer testing.
Question 13: In Spring, what does @DependsOn("beanA") guarantee when placed on beanB?
- beanA is initialized before beanB (Correct answer)
- beanA is injected into beanB automatically
- beanA proxies all calls to beanB
- beanA and beanB share the same scope
Correct answer: beanA is initialized before beanB
@DependsOn ensures the listed beans are fully initialized before the annotated bean is created.
Question 14: What is the effect of setting @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) on a request-scoped bean?
- The bean is created once and cached for all requests
- The bean bypasses Spring's dependency injection entirely
- A CGLIB proxy is injected so the singleton can delegate to the correct request-scoped instance at runtime (Correct answer)
- The bean is destroyed after each method call
Correct answer: A CGLIB proxy is injected so the singleton can delegate to the correct request-scoped instance at runtime
A scoped proxy wraps the short-lived bean so singletons can hold a reference without capturing a stale instance.
Question 15: What is the purpose of the @Sql annotation in Spring test support?
- Profiles slow SQL queries during tests
- Executes SQL scripts before or after a test method (Correct answer)
- Generates SQL schema from JPA entities
- Validates SQL query syntax at startup
Correct answer: Executes SQL scripts before or after a test method
@Sql allows you to specify SQL scripts to run against the database before or after a test method or class.
Question 16: Which of the following correctly combines two pointcut expressions with a logical AND?
- execution(* *.*(..)) | within(com.example.*)
- execution(* *.*(..)) AND within(com.example.*)
- execution(* *.*(..)) + within(com.example.*)
- execution(* *.*(..)) && within(com.example.*) (Correct answer)
Correct answer: execution(* *.*(..)) && within(com.example.*)
Pointcut expressions use Java-style && (and ||, !) for logical composition inside @Pointcut and advice annotations.
Question 17: Which method of UriComponentsBuilder is used to construct a URI for a newly created resource in a Spring REST response?
- fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri() (Correct answer)
- newUri().append(id).build()
- buildUri(id).toString()
- createPath(id).toUri()
Correct answer: fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri()
UriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(id).toUri() dynamically constructs the location URI from the current request context.
Question 18: What happens when you annotate a @RestController method parameter with @Valid and the validation fails?
- Spring silently ignores validation errors
- Spring returns HTTP 500
- Spring throws a NullPointerException
- Spring throws MethodArgumentNotValidException and returns HTTP 400 (Correct answer)
Correct answer: Spring throws MethodArgumentNotValidException and returns HTTP 400
When bean validation fails on a @RequestBody annotated with @Valid, Spring throws MethodArgumentNotValidException, which by default maps to a 400 Bad Request response.
Question 19: What does Spring's @Qualifier annotation allow you to do?
- Qualify a bean as thread-safe
- Reduce the bean's initialization priority
- Specify which bean to inject when multiple candidates exist (Correct answer)
- Restrict a bean to a specific environment profile
Correct answer: Specify which bean to inject when multiple candidates exist
@Qualifier combined with @Autowired narrows the injection to the bean with the matching qualifier name.
Question 20: What is CORS and why must it be configured in Spring Security?
- A method for encrypting HTTP headers in transit
- A token format used in Spring Security OAuth2 flows
- A caching strategy for REST APIs that Spring Security manages by default
- A browser security mechanism that blocks cross-origin requests unless the server explicitly allows them (Correct answer)
Correct answer: A browser security mechanism that blocks cross-origin requests unless the server explicitly allows them
CORS (Cross-Origin Resource Sharing) is enforced by browsers and requires the server to include Access-Control-Allow-Origin headers; Spring Security must be configured to allow CORS before its filters block preflight requests.
Question 21: Which file name pattern loads configuration only when the 'staging' profile is active?
- staging-application.properties
- application-staging.properties (Correct answer)
- config-staging.properties
- application.staging.properties
Correct answer: application-staging.properties
Profile-specific files follow the pattern application-{profile}.properties or application-{profile}.yml.
Question 22: What does the @Lazy annotation do when placed on a @Bean method?
- Defers bean initialization until first use (Correct answer)
- Creates the bean asynchronously
- Reduces bean memory footprint
- Marks the bean as optional
Correct answer: Defers bean initialization until first use
@Lazy delays instantiation of the bean until it is first requested from the context.
Question 23: When testing a @RestController with @WebMvcTest, how do you mock a service dependency?
- Override the bean in a @TestConfiguration class
- Both B and C work (Correct answer)
- Annotate the service field with @Mock
- Use @MockBean in the test class
Correct answer: Both B and C work
Both @MockBean and a @TestConfiguration with an @Bean definition can inject a mock service into the limited context loaded by @WebMvcTest.
Question 24: Which JoinPoint method returns the name of the method being advised?
- getSignature().getName() (Correct answer)
- getArgs()[0]
- getTarget()
- getThis().getClass().getName()
Correct answer: getSignature().getName()
JoinPoint.getSignature() returns a Signature object, and calling getName() on it gives the intercepted method's name.
Question 25: How can you add custom tags to every Micrometer metric emitted by your Spring Boot application?
- Define a MeterRegistryCustomizer bean that calls registry.config().commonTags() (Correct answer)
- Use @CommonTag on the main application class
- Annotate each metric with @MetricTags
- Set management.metrics.tags in application.properties
Correct answer: Define a MeterRegistryCustomizer bean that calls registry.config().commonTags()
A MeterRegistryCustomizer bean lets you apply common tags globally to all meters registered in the application.
Question 26: What is the role of the @PathVariable annotation in Spring REST controllers?
- Binds a URI template variable to a method parameter (Correct answer)
- Injects the servlet path info
- Reads a value from the request header
- Maps the entire request path to a String
Correct answer: Binds a URI template variable to a method parameter
@PathVariable extracts values from URI template placeholders (e.g., /users/{id}) and binds them to method parameters.
Question 27: Which annotation makes a class eligible to be detected as an aspect by Spring's component scan?
- @Pointcut
- @Aspect alone
- @AdviceType
- @Aspect combined with @Component (or another stereotype) (Correct answer)
Correct answer: @Aspect combined with @Component (or another stereotype)
@Aspect marks the class as an aspect, but @Component (or @Bean in a config class) is needed for Spring to detect and register it as a bean.
Question 28: Which annotation on a Spring service method ensures it runs within an existing transaction or creates a new one if none exists?
- @Transactional(propagation = Propagation.REQUIRED) (Correct answer)
- @Transactional(propagation = Propagation.NEVER)
- @Transactional(propagation = Propagation.SUPPORTS)
- @Transactional(propagation = Propagation.REQUIRES_NEW)
Correct answer: @Transactional(propagation = Propagation.REQUIRED)
Propagation.REQUIRED (the default) joins an active transaction or starts a new one, ensuring the method always runs transactionally.
Question 29: Which annotation is used to map HTTP PATCH requests to handler methods in Spring MVC?
- @ModifyMapping
- @UpdateMapping
- @PartialMapping
- @PatchMapping (Correct answer)
Correct answer: @PatchMapping
@PatchMapping is the dedicated Spring MVC annotation for handling HTTP PATCH requests, used for partial resource updates.
Question 30: What is the prefix for Thymeleaf in HTML?
- th:value
- th: (Correct answer)
- c:
- TH:
Correct answer: th:
The prefix used in HTML for Thmeleaf is th:
Question 31: What Java version is required for Spring Boot?
- Java 8 (Correct answer)
- Java 10
- Java 11
- Java 9
Correct answer: Java 8
Explanation: <br> As a minimum, Spring Boot v2.0 requires Java 8.0. Many new features in Java 8 include lambda expressions, functional interfaces, stream APIs, time APIs, default methods in interfaces, and so on. Many old programs are being updated to take advantage of the additional features in Java 8.
VMware Spring Certified Professional (2V0-72.22)
Industry-recognized certification validating expertise in building enterprise applications using the Spring Framework and Spring Boot, covering core container management, AOP, data persistence, RESTful services, reactive programming, and production-ready features.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds