2025 Correct Practice Tests of 2V0-72.22 Dumps with Practice Exam [Q35-Q60]

Share

2025 Correct Practice Tests of 2V0-72.22 Dumps with Practice Exam

Certification Sample Questions of 2V0-72.22 Dumps With 100% Exam Passing Guarantee

NEW QUESTION # 35
Which strategy is correct for configuring Spring Security to intercept particular URLs? (Choose the best answer.)

  • A. The URLs can be specified via configuration (using authorizeRequests () and request matchers), with the most specific rule first and the least specific last.
  • B. Spring Security can obtain URLs from Spring MVC controllers, the Spring Security configuration just needs a reference to the controller to be protected.
  • C. The URLs are specified in a special properties file, used by Spring Security.
  • D. The URLs can be specified via configuration (using authorizeRequests () and request matchers), with the least specific rule first and the most specific last.

Answer: A


NEW QUESTION # 36
Which two statements describe the ApplicationContext correctly? (Choose two.)

  • A. The ApplicationContext maintains singleton beans that are instantiated by the Spring runtime.
  • B. The ApplicationContext lazy initializes beans by default.
  • C. The ApplicationContext does not include all functionality of the BeanFactory.
  • D. The ApplicationContext is the root interface for accessing the Spring container.
  • E. The ApplicationContext can be created in a test environment, web application, and in a standalone application.

Answer: D,E


NEW QUESTION # 37
Which option is true about use of mocks in a Spring Boot web slice test? (Choose the best answer.)

  • A. Mocking a Spring Bean requires annotating it with @Mock annotation.
  • B. Mocking a Spring Bean requires annotating it with @MockBean annotation.
  • C. Mocks cannot be used in a Spring Boot web slice test.
  • D. If a Spring Bean already exists in the web slice test spring context, it cannot be mocked.

Answer: B

Explanation:
A web slice test is a type of test in Spring Boot that focuses on testing only the web layer of an application, without starting a full server or requiring a real database. To isolate the web layer from other dependencies, such as services or repositories, mocks can be used to simulate their behavior and return predefined responses. To create and inject a mock for an existing bean in the application context, the @MockBean annotation can be used on a field or a parameter in the test class. This annotation will replace any existing bean of the same type with a mock created by Mockito.


NEW QUESTION # 38
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.)

  • A. This syntax is invalid because the result of the getBean() method call should be cast to ClientService.
  • B. It will return a bean of the type ClientService regardless of its id or name.
  • C. This syntax is invalid because the bean id must be specified as a method parameter.
  • D. It will return a bean called ClientService regardless of its id or name.

Answer: B


NEW QUESTION # 39
Which two statements are true about @Controller annotated classes? (Choose two.)

  • A. The classes must be annotated together with @EnableMvcMappings to be discovered via component scanning.
  • B. @Controller is interchangeable with @RestController with no extra code changes for the methods inside the class.
  • C. The @Controller annotation is a stereotype annotation like @Component.
  • D. The @Controller annotated classes can only render views.
  • E. The classes are eligible for handling requests in Spring MVC.

Answer: C,E

Explanation:
B . The classes are eligible for handling requests in Spring MVC.
This is true because the @Controller annotation marks a class as a web request handler, and it is typically used with the @RequestMapping annotation to map specific URLs to methods1. The @Controller annotation also allows the class to be recognized as a Spring-managed component through the classpath scanning2.
E . The @Controller annotation is a stereotype annotation like @Component.
This is true because the @Controller annotation is a specialization of the generic stereotype @Component annotation, which allows a class to be recognized as a Spring-managed component3. The @Controller annotation extends the use-case of @Component and marks the annotated class as a business or presentation layer4.


NEW QUESTION # 40
Which two statements about the @Autowired annotation are true? (Choose two.)

  • A. @Autowired fields are injected after any config methods are invoked.
  • B. Multiple arguments can be injected into a single method using @Autowired.
  • C. @Autowired can be used to inject references into BeanPostProcessor and
  • D. By default, if a dependency cannot be satisfied with @Autowired, Spring throws a RuntimeException.
  • E. If @Autowired is used on a class, field injection is automatically performed for all dependencies.

Answer: B,D

Explanation:
BeanFactoryPostProcessor.
Explanation:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Autowired.html B . Multiple arguments can be injected into a single method using @Autowired.
This is true because the @Autowired annotation can be applied to methods with arbitrary names and multiple arguments, as shown in the example in Using @Autowired.
C . By default, if a dependency cannot be satisfied with @Autowired, Spring throws a RuntimeException.
This is true because the @Autowired annotation has a required attribute that is true by default, meaning that the dependency is mandatory. If Spring cannot find a matching bean to inject, it will throw a BeanCreationException, which is a subclass of RuntimeException. To avoid this exception, we can set the required attribute to false, which will allow Spring to skip the injection if no matching bean is found


NEW QUESTION # 41
Which three types can be used as @Controller method arguments? (Choose three.)

  • A. Session
  • B. HttpSession
  • C. Principal
  • D. Language
  • E. Locale
  • F. Request

Answer: B,C,E

Explanation:
A . Locale
This is true because the Locale argument can be used to resolve the current locale that the client is using, based on the Accept-Language header or a cookie1.
B . Principal
This is true because the Principal argument can be used to access the currently authenticated user, if any1.
F . HttpSession
This is true because the HttpSession argument can be used to access the current session, if any1. Note that this argument is not required and will be null if a session does not exist.


NEW QUESTION # 42
Refer to the exhibit.

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

  • A. The Java configuration can be profile specific by adding a @Profile annotation.
  • B. The bean is of type clientService and by default will be a Singleton.
  • C. The clientService bean declared will have prototype scope by default.
  • D. The name of the clientService() method is invalid and will throw an error.
  • E. The clientService bean will be lazy initialized the first time accessed.

Answer: A,B


NEW QUESTION # 43
Which two statements are true concerning constructor injection? (Choose two.)

  • A. Constructor injection only allows one value to be injected.
  • B. Field injection is preferred over constructor injection from a unit testing standpoint.
  • C. Construction injection can be used with multiple constructors without @Autowired annotation.
  • D. Constructor injection is preferred over field injection to support unit testing.
  • E. If there is only one constructor the @Autowired annotation is not required.

Answer: B,D


NEW QUESTION # 44
Which dependency enables an automatic restart of the application as code is changed during development of a Spring boot configuration on a web application? (Choose the best answer.)

  • A. spring-boot-restart
  • B. spring-boot-devtools
  • C. spring-boot-initializr
  • D. spring-boot-starter-devtools

Answer: D

Explanation:
Spring Boot provides a set of tools for improving the development experience, such as automatic restart, live reload, remote debugging, etc. These tools are included in the spring-boot-starter-devtools dependency, which can be added to the project's pom.xml or build.gradle file. The automatic restart feature will monitor the classpath for changes and trigger a restart of the application when necessary.


NEW QUESTION # 45
If a class is annotated with @Component, what should be done to have Spring automatically detect the annotated class and load it as a bean? (Choose the best answer.)

  • A. Ensure a valid @ComponentScan annotation in the Java configuration is specified.
  • B. Ensure a valid @Scope for the class is specified.
  • C. Ensure a valid @Bean for the class is specified.
  • D. Ensure a valid bean name in the @Component annotation is specified.

Answer: D


NEW QUESTION # 46
Which statement is true? (Choose the best answer.)

  • A. @ActiveProfiles is a class-level annotation that is used to declare which bean definition profiles should be active when loaded an ApplicationContext for an integration test.
  • B. @ActiveProfiles is a class-level annotation that is used to instruct the Spring TestContext Framework to record all application events that are published in the ApplicationContext during the execution of a single test.
  • C. @ActiveProfiles is a class-level annotation that you can use to configure how the Spring TestContext Framework is bootstrapped.
  • D. @ActiveProfiles is a class-level annotation that you can use to configure the locations of properties files and inlined properties to be added to the set of PropertySources in the Environment for an ApplicationContext loaded for an integration test.

Answer: A


NEW QUESTION # 47
Refer to the exhibit.

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

  • A. A class that implements CustomerRepository must be implemented and declared as a Spring Bean.
  • B. JPA annotations are required on the Customer class to successfully use Spring Data JDBC.
  • C. CustomerRepository should be a class, not an interface.
  • D. An implementation of this repository can be automatically generated by Spring Data JPA.

Answer: D


NEW QUESTION # 48
Which two statements are true regarding Spring Security? (Choose two.)

  • A. In the authorization configuration, the usage of permitAll () allows bypassing Spring security completely.
  • B. It provides a strict implementation of the Java EE Security specification.
  • C. A special Java Authentication and Authorization Service (JAAS) policy file needs to be configured.
  • D. Authentication data can be accessed using a variety of different mechanisms, including databases and LDAP.
  • E. Access control can be configured at the method level.

Answer: A,E


NEW QUESTION # 49
Which two statements are true regarding Spring and Spring Boot Testing? (Choose two.)

  • A. EasyMock is supported out of the box.
  • B. The spring-test dependency provides annotations such as @Mock and @MockBean.
  • C. Integration and slice testing are both supported.
  • D. @SpringBootTest or @SpringJUnitConfig can be used for creating an ApplicationContext.
  • E. Mockito spy is not supported in Spring Boot testing by default.

Answer: C,D

Explanation:
Spring and Spring Boot provide various annotations and utilities to support testing of different layers of the application. To create an ApplicationContext for integration tests, we can use either @SpringBootTest or @SpringJUnitConfig annotations. The former is a specialized annotation that also provides additional features such as auto-configuration, web environment emulation, and test properties management. The latter is a general-purpose annotation that combines @ContextConfiguration and @ExtendWith(SpringExtension.class) annotations.
To perform slice testing, which focuses on testing a specific layer or feature of the application in isolation, we can use annotations such as @WebMvcTest, @DataJpaTest, @RestClientTest, etc. These annotations will only load the relevant beans for the tested slice and mock or stub the other dependencies.


NEW QUESTION # 50
Refer to the exhibit.

Based on the default Spring behavior, choose the correct answer. (Choose the best answer.)

  • A. One AccountRepository bean will be instantiated since the default scope is singleton.
  • B. Many AccountRepository beans will be instantiated, depending how often accountRepository(), transferService() and accountService() are called.
  • C. Three AccountRepository beans will be instantiated as the accountRepository() method will be called three times.
  • D. Two AccountRepository beans will be instantiated as the accountRepository() method will be called two times.

Answer: A

Explanation:
This is true because the default scope of a bean in Spring is singleton, which means that only one instance of the bean will be created and shared by the entire application context. The @Bean annotation on the accountRepository() method indicates that this method will return a bean that will be managed by Spring. However, this method will not be called every time the bean is needed, but only once when the bean is first created. Therefore, only one AccountRepository bean will be instantiated and injected into the TransferService and AccountService beans.


NEW QUESTION # 51
Which three statements are advantages of using Spring's Dependency Injection? (Choose three.)

  • A. Dependency injection creates tight coupling between components.
  • B. Dependency injection facilitates loose coupling between components.
  • C. Dependencies between application components can be managed external to the components.
  • D. Configuration can be externalized and centralized in a small set of files.
  • E. Dependency injection reduces the start-up time of an application.
  • F. Dependency injection can make code easier to trace because it couples behavior with construction.

Answer: A,D,E


NEW QUESTION # 52
In which three ways are Security filters used in Spring Security? (Choose three.)

  • A. To provide risk governance.
  • B. To drive authentication.
  • C. To provide a logout capability.
  • D. To enforce authorization (access control).
  • E. To manage application users.
  • F. To encrypt data.

Answer: B,C,D


NEW QUESTION # 53
Which two statements are true regarding @DataJpaTest? (Choose two.)

  • A. It can be used for testing JdbcTemplate.
  • B. TestEntityManager provides all methods that are provided by EntityManager and more.
  • C. It can be used for testing both JPA components and NoSQL components.
  • D. It auto-configures a TestEntityManager bean.
  • E. If an embedded database is on the classpath, it will be used to configure a DataSource by default.

Answer: D,E


NEW QUESTION # 54
Which two statements are correct when @SpringBootApplication is annotated on a class? (Choose two.)

  • A. Methods in the class annotated with @Bean will be ignored.
  • B. Component scanning will start from the package of the class.
  • C. All other annotations on the class will be ignored.
  • D. It causes Spring Boot to enable auto-configuration by default.
  • E. A separate ApplicationContext will be created for each class annotated with

Answer: D,E

Explanation:
@SpringBootApplication.


NEW QUESTION # 55
Refer to the exhibit.

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

  • A. Annotate the update() handler method with @ResponseStatus(HttpStatus.NO_CONTENT).
  • B. Annotate the update() handler method with @ResponseEntity(204).
  • C. The update() handler method cannot return a void type, it must return a ResponseEntity type.
  • D. Annotate the update() handler method with @PutMapping("/store/orders/{id"}", HttpStatus.NO_CONTENT).

Answer: A

Explanation:
http://effcode.com/spring/returning-no-content-204-from-spring-controller/


NEW QUESTION # 56
Which two statements are correct regarding the Health Indicator status? (Choose two.)

  • A. The severity order cannot be changed due to security reasons.
  • B. The last status in a sorted list of HealthIndicators is used to derive the final system health.
  • C. Custom status values can be created.
  • D. The built-in status values are DOWN, OUT_OF_SERVICE, UNKNOWN, and UP in decreasing order of severity.
  • E. The status with the least severity is used as the top-level status.

Answer: C,D


NEW QUESTION # 57
Which two statements are true about REST? (Choose two.)

  • A. REST is Reliable.
  • B. REST is Interoperable.
  • C. REST is Stateful.
  • D. REST is Relative.
  • E. REST is a Protocol.

Answer: B,E


NEW QUESTION # 58
Which two statements are true regarding @WebMvcTest? (Choose two.)

  • A. Typically it is used in combination with @MockBean when there is a dependency bean to be mocked.
  • B. It is used for testing Spring MVC components such as @Controller with a running server.
  • C. It is typically used with @ExtendWith(MockitoExtension.class) in JUnit 5.
  • D. It auto-configures a MockMvc.
  • E. It will only scan for @Controller beans in the source code.

Answer: A,D


NEW QUESTION # 59
Which two use cases can be addressed by the method level security annotation @PreAuthorize? (Choose two.)

  • A. Allow access to a method based on HTTP method.
  • B. Allow access to a method based on roles.
  • C. Allow access to a method based on the returned object.
  • D. Allow access to a method based on request URL.
  • E. Allow access to a method based on user identity.

Answer: B,E

Explanation:
A . Allow access to a method based on user identity.
This is true because the @PreAuthorize annotation can use the principal object to access the user identity and check if it matches a certain condition. For example, we can use the following expression to allow access only to the user with the username "admin":
@PreAuthorize("principal.username == 'admin'")
E . Allow access to a method based on roles.
This is true because the @PreAuthorize annotation can use the hasRole, hasAnyRole, or hasAuthority methods to check if the user has a certain role or authority. For example, we can use the following expression to allow access only to users who have the role "ADMIN" or "USER":
@PreAuthorize("hasAnyRole('ADMIN', 'USER')")


NEW QUESTION # 60
......

2V0-72.22 Sample Practice Exam Questions 2025 Updated Verified: https://examsboost.validbraindumps.com/2V0-72.22-exam-prep.html