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.)
C
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.
Spring puts each bean instance in a scope. What is the default scope? (Choose the best answer.)
B
Explanation:
Spring supports different scopes for bean instances, such as singleton, prototype, request, session,
etc. The scope determines how many instances of a bean are created and how they are shared
among other components. The default scope is singleton, which means that only one instance of a
bean is created per application context and it is shared by all components that depend on it.
Reference: https://stackoverflow.com/questions/17599216/spring-bean-scopes
Refer to the exhibit.
Which option is a valid way to retrieve the account id? (Choose the best answer.)
B
Which strategy is correct for configuring Spring Security to intercept particular URLs? (Choose the
best answer.)
A
Explanation:
Spring Security provides a fluent API for configuring web security based on URL patterns and request
matchers. The authorizeRequests() method returns an expression that allows specifying access rules
for different URLs using methods such as antMatchers(), regexMatchers(), mvcMatchers(), etc. The
order of these rules matters, as they are evaluated from top to bottom. Therefore, it is
recommended to put the most specific rules first and the least specific ones last.
Reference: https://www.baeldung.com/security-none-filters-none-access-permitAll
In which three ways are Security filters used in Spring Security? (Choose three.)
BDE
Explanation:
Spring Security uses a filter-based architecture to provide security services for web applications. A
filter is an object that intercepts HTTP requests and responses and performs some logic before or
after the request is processed by the servlet. Spring Security provides a number of filters for different
purposes, such as:
Authentication: Filters that handle the authentication process, such as
UsernamePasswordAuthenticationFilter, BasicAuthenticationFilter,
RememberMeAuthenticationFilter, etc.
User management: Filters that manage the user details and roles, such as
SecurityContextPersistenceFilter, AnonymousAuthenticationFilter, ConcurrentSessionFilter, etc.
Logout: Filters that handle the logout process, such as LogoutFilter and
SecurityContextLogoutHandler.
Authorization: Filters that enforce access control rules based on the user’s authentication and roles,
such as FilterSecurityInterceptor, ExceptionTranslationFilter, etc.
Reference: https://www.javadevjournal.com/spring-security/spring-security-filters/
Refer to the exhibit.
The above code shows a conditional @Bean method for the creation of a JdbcTemplate bean. Which
two statements correctly describe the code behavior? (Choose two.)
AE
Explanation:
The @Bean annotation is used to declare a method that returns an object that should be registered
as a bean in the application context. The @ConditionalOnBean annotation is used to specify a
condition for the bean creation based on the presence or absence of other beans in the application
context. The name attribute of this annotation can be used to specify the bean name or names that
must be present or absent for the condition to match. However, this approach is less flexible than
using the value or type attribute, which can specify the bean class or classes that must be present or
absent for the condition to match. Therefore, it is recommended to use
@ConditionalOnBean(DataSource.class) instead of @ConditionalOnBean(name= “dataSource”) for
greater flexibility.
The JdbcTemplate class is a Spring class that simplifies the use of JDBC and helps to avoid common
errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. To
create a JdbcTemplate object, we need to pass a DataSource object as a constructor argument. The
DataSource interface is a Java interface that represents a factory of connection objects. In this code,
the jdbcTemplate() method takes a DataSource object as a parameter and returns a new
JdbcTemplate object. This method is annotated with @Bean and @ConditionalOnBean(name=
“dataSource”), which means that it will only create a JdbcTemplate bean when there is already a
bean named dataSource in the application context.
What is a Spring Boot starter dependency? (Choose the best answer.)
D
Explanation:
A Spring Boot starter dependency is a special type of dependency that provides a convenient way to
add multiple, coordinated dependencies related to a specific technology or feature, such as web,
JDBC, security, etc. A starter dependency usually has a name that starts with spring-boot-starter-
followed by the name of the technology or feature. For example, spring-boot-starter-web is a starter
dependency that includes all the dependencies needed for creating web applications with Spring
MVC and RESTful services.
Reference: https://developer.ibm.com/tutorials/j-spring-boot-basics-perry/
Which two are required to use transactions in Spring? (Choose two.)
AB
Explanation:
Transactions are units of work that ensure data consistency and integrity by enforcing atomicity,
consistency, isolation, and durability (ACID) properties. Spring provides an abstraction layer for
transaction management that supports various transaction APIs such as JDBC, JPA, Hibernate, etc. To
use transactions in Spring, we need to do two things:
Enable transaction management by adding @EnableTransactionManagement annotation to a Java
configuration class or
tx:annotation-driven/
element to an XML configuration file.
Declare transactional boundaries by annotating a class, an interface, or individual methods with the
@Transactional annotation. This annotation indicates that the execution of the annotated element
should be wrapped in a transaction.
Reference: 5
Reference: https://www.baeldung.com/transaction-configuration-with-jpa-and-spring
Which two statements are true regarding the RestTemplate class? (Choose two.)
BC
Explanation:
The RestTemplate class is a Spring class that provides an easy way to communicate with RESTful
web services from within an application. It offers several convenience methods for performing HTTP
requests and handling HTTP responses, such as getForObject(), postForEntity(), exchange(), etc. It
also supports automatic conversion of Java objects to and from JSON or XML using
HttpMessageConverter instances.
Reference: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html
Which statement is true? (Choose the best answer.)
D
Explanation:
A bean definition profile is a named logical grouping of bean definitions that can be activated or
deactivated in different environments. For example, we can define different profiles for
development, testing, and production environments. Spring provides the @Profile annotation to
mark a bean definition or a configuration class as belonging to a specific profile. To activate a profile,
we can use the spring.profiles.active property or the ConfigurableEnvironment.setActiveProfiles()
method.
The @ActiveProfiles annotation is a class-level annotation that is used in conjunction with the Spring
TestContext Framework to declare which profiles should be active when loading an
ApplicationContext for an integration test. This annotation can be applied to any class annotated
with @ContextConfiguration or a meta-annotation that is composed of @ContextConfiguration.
Reference: https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/integration-testing.html