10 free sample questions from a bank of 77, with the correct answers and explanations. No signup required — start practising right now.
1If 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.)
Ensure a valid bean name in the @Component annotation is specified.
Ensure a valid @ComponentScan annotation in the Java configuration is specified.
Ensure a valid @Scope for the class is specified.
Ensure a valid @Bean for the class is specified.
Answer: B
2Given an ApplicationContext containing three bean definitions of type Foo with bean ids foo1, foo2, and foo3, which three @Autowired scenarios are valid and will allow the ApplicationContext to initialize successfully? (Choose three.)
@Autowired public void setFoo (Foo foo) {…}
@Autowired @Qualifier (“foo3”) Foo foo;
@Autowired public void setFoo (@Qualifier (“foo1”) Foo foo) {…}
@Autowired private Foo foo;
@Autowired private Foo foo2;
@Autowired public void setFoo(Foo foo2) {…}
Answer:
3Which 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.)
spring-boot-devtools
spring-boot-initializr
spring-boot-starter-devtools
spring-boot-restart
Answer: A
4Spring puts each bean instance in a scope. What is the default scope? (Choose the best answer.)
prototype
singleton
request
session
Answer: B
5Refer to the exhibit. Which option is a valid way to retrieve the account id? (Choose the best answer.)
Add @PathVariable(“id”) String accountId argument to the update() handler method.
Add @PathVariable long accountId argument to the update() handler method.
Add @RequestParam long accountId argument to the update() handler method.
Add @RequestParam(“id”) String accountId argument to the update() handler method.
Answer: A
6Which strategy is correct for configuring Spring Security to intercept particular URLs? (Choose the best answer.)
The URLs can be specified via configuration (using authorizeRequests () and request matchers), with the most specific rule first and the least specific last.
Spring Security can obtain URLs from Spring MVC controllers, the Spring Security configuration just needs a reference to the controller to be protected.
The URLs are specified in a special properties file, used by Spring Security.
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
7In which three ways are Security filters used in Spring Security? (Choose three.)
To provide risk governance.
To drive authentication.
To manage application users.
To provide a logout capability.
To enforce authorization (access control).
To encrypt data.
Answer:
8Refer 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.)
@ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnBean (DataSource.class) for greater flexibility.
@ConditionalOnBean(name= “dataSource”) should be replaced with @ConditionalOnMissingBean (DataSource.class) for greater flexibility.
The @Bean annotation should be removed.
A JdbcTemplate bean will be created when the DataSource class is in the classpath but there is no DataSource bean.
A JdbcTemplate bean will be created when a bean named dataSource has already been created.
Answer:
9What is a Spring Boot starter dependency? (Choose the best answer.)
A setting for specifying which code you want Spring Boot to generate for you.
A specific POM which you must build to control Spring Boot’s opinionated runtime.
A pre-existing model project you can download and use as the basis of your project.
An easy way to include multiple, coordinated dependencies related to a specific technology, like web or JDBC.
Answer: D
10Which two are required to use transactions in Spring? (Choose two.)
Add @EnableTransactionManagement to a Java configuration class.
Annotate a class, an interface, or individual methods requiring a transaction with the @Transactional annotation.
A class must be annotated with @Service and @Transaction.
A class requiring a transaction must implement the TransactionInterceptor interface.
Write a Spring AOP advice to implement transactional behavior.