Springboot
Springboot
Question
Container
Question 1
Given the following Spring configuration file, what is the correct answer:
<bean class="com.spring.service.MyServiceImpl">
<property name="repository" ref="jpaDao"/>
</bean>
<bean class="com.spring.repository.JpaDao"/>
Question 2
Given the Spring configuration file, which are the correct statements?
<bean class="com.spring.service.BankServiceImpl"
p:bankName="NationalBank">
</bean>
Question 3
What the name of the bean defined in the following configuration class? Select a single answer.
@Configuration
public class ApplicationConfig {
@Autowired
private DataSource dataSource;
@Bean
ClientRepository clientRepository() {
ClientRepository accountRepository = new JpaClientRepository();
accountRepository.setDataSource(dataSource);
return accountRepository;
}
}
1. JpaClientRepository
2. jpaClientRepository
3. clientRepository
4. Two beans are defined: a data souce and a repository
Question 4
How could you externalize constants from a Spring configuration file or a Spring annotation into a
.properties file? Select one or more answers
Question 5
1. Constuctor and properties autowiring in the same bean are not compatible
2. A bean should have a default or a no-args constructor
3. The <constructor-arg> tag could take type, name and index to reduce ambiguity
4. None of the above
5. All of the above
Question 6
What are the right affirmations about the @PostConstruct, @Resource and the @PreDestroy
annotations?
Question 7
What is/are typically case(s) where you usually need to manually instantiated an ApplicationContext?
1. In a web application
2. In an integration test running with the SpringJUnit4ClassRunner
3. In a standalone application started with a main method
4. None of the above
Question 8
Select the right statement about referring a Spring configuration file inside the package
com.example.myapp in the below example?
ApplicationContext context = new
ClassPathXmlApplicationContext("classpath:/com.example.myapp.config.xml" );
Question 9
How to auto-inject into a field a Spring bean by its name? Select one or more answer choices.
Question 10
What are the main advantages of using interfaces when designing business services? Select one or
more answer choices.
Question 11
Select one or many correct answers about Spring bean life cycle.
1. The method annotated with @PostConstruct is called after bean instantiation and before
properties setting of the bean
2. The method @PreDestroy of a prototype bean is called when the bean is garbage collected
3. The init() method declared in the init-method attribute of a bean is called before the
afterPropertiesSet callback method of the InitializingBean interface
4. The method annotated with @PostConstruct is called before the afterPropertiesSet callback
method of the InitializingBean interface
Question 12
Given the following configuration class, what are the correct affirmations? Select one or more
answers.
@Autowired
public ApplicationConfig(DataSource dataSource) {
this.dataSource = dataSource;
}
@Bean(name="clientRepository")
ClientRepository jpaClientRepository() {
return new JpaClientRepository();
}
}
Question 13
What are the features of the XML <context:namespace? Select one or many answers.
Test
Question 14
Select one or more correct statements about developing integration test with Spring support.
Question 15
What are the main advantage(s) for using Spring when writing integration tests?
Question 16
What are the main advantage(s) for using Spring when writing unit tests?
Question 17
1. It provides an abstraction layer for the main open source mock frameworks
2. Provides the @Mock annotation
3. It dynamically generates mock objects
4. All of the above
5. None of the above
Question 18
Select correct statement(s) about transactional support of the Spring test module.
AOP
Question 19
Considering 2 classes AccountServiceImpl and ClientServiceImpl. Any of these 2 classes inherits from
each other. What is the result of the following pointcut expression?
execution(* *..AccountServiceImpl.update(..))
&& execution(* *..ClientServiceImpl.update(..))
Using the Spring AOP framework, what is the visibility of the method matches by the following join
point?
@Pointcut("execution(* *(..))")
private void anyOperation() {};
Question 21
1. AOP proxies are created by Spring in order to implement the aspect contracts
2. AOP proxies are always created with a JDK dynamic proxy
3. Only classes that implements a least one interface could be proxied
4. All methods could be proxied
5. Proxies are created by a BeanPostProcessor
Question 22
Question 23
Question 24
What is an advice? Select a unique answer.
Question 25
Question 26
execution(* com.test.service..*.*(*))
Question 27
What are the unique right answer about Spring AOP support?
Question 28
Using the Spring AOP framework, what are the joinpoint methods of the following pointcut
expressions?
execution(public * *(..))
Data Access
Question 29
Why is it a best practice to mark transaction as read-only when code does not write anything to the
database? Select one or more answers.
Question 30
What data access technology is supported by the Spring framework? Select one or more answers.
1. JDBC
2. NoSQL
3. Hibernate
4. JPA
Question 31
Question 32
Using JdbcTemplate, what is the Spring provided class you will use for result set parsing and merging
rows into a single object? Select a unique answer.
1. RowMapper
2. RowCallbackHandler
3. ResultSetExtractor
4. ResultSetMapper
Question 33
Transaction
Question 34
What is/are incorrect statements about XML declaration of the transaction manager bean? Select
one or more answers.
Question 35
Assuming @Transactional annotation support is enabled and the transferMoney method is called
through a Spring AOP proxy, what is the behavior of the following code sample?
@Transactional(propagation=Propagation.REQUIRED)
public void transferMoney(Account src, Account target, double amount) {
add(src, -amount);
add(src, amount);
}
@Transactional(propagation=Propagation.REQUIRES_NEW)
public void add(Account account, Double amount) {
// IMPLE MENTATION
}
Question 36
1. If a transaction exists, the current method should run within this transaction. Otherwise, it
should start a new transaction and run within its own transaction.
2. If a transaction is in progress, the current method should run within the nested transaction
of the existing transaction. Otherwise, a new transaction has to be started and run within its
own transaction.
3. The current method must start a new transaction and run within its own transaction. If there
is an existing transaction in progress, it is suspended.
4. None of the above
Question 38
Sping @MVC
Question 39
What could not return a Spring MVC controller? Select a single answer.
Question 40
Where do you cannot declare Spring MVC controller? Select one or more answers.
3. @RequestMapping("/displayAccount")
String displayAccount(@RequestParam("accountId") int id, Model model)
4. @RequestMapping("/displayAccount")
String displayAccount(@PathVariable("accountId") int id, Model model)
Spring Security
Question 42
How could you secure MVC controller with Spring Security? Select a unique answer.
Question 43
What are the possible mechanisms provided by Spring Security to store user details? Select one or
more correct answers.
1. Database
2. JAAS
3. LDAP
4. Properties file
Question 44
What is right about Spring Security configuration and the security namespace? Select one or more
correct answers.
1. The access attribute of the intercept-url tag support both EL and constants together.
2. The patterns declared into the intercept-url tag are analyzed from up to bottom. Winning is
the first that matches.
3. The patterns declared into the intercept-url tag use by default the java regex syntax.
4. Security rules may apply depending request parameter
REST
Question 45
@RestController
public class OwnerController {
Question 46
Microservice
Question 47
Question 48
Spring Boot
Question 49
Question 50
What is the name of the default environment configuration file of Spring Boot?
1. configuration.spring
2. configuration.yml
3. configuration.xml
4. application.properties
5. application.json
Response
Container
Question 1
Answer 2 is correct. Those beans are anonymous because no id is supplied explicitly. Thus Spring
container generates a unique id for that bean. It uses the fully qualified class name and appends a
number to them. However, if you want to refer to that bean by name, through the use of the ref
element you must provide a name (see Naming Beans section of the Spring reference manual). To be
correct, the 2nd bean has to declare a jpaDao id attribute in order to be reference by the
repository property of the first bean.
Question 2
1. To set bean’s property with the p:propertyName shortcut, you have to declare the
http://www.springframework.org/schema/p in your xml configuration file. No xsd is
required.
2. The bean is anonymous. Spring generates a unique id:
com.spring.service.BankServiceImpl#0
3. To reference another bean with the p namespace, you have to use the p:propertyName-ref
syntax
4. Due to the above explanation, NationalBank is not a bean reference, so it is a simple String
and thus a scalar value.
Question 3
Correct answer is 3.
The @Bean annotation defines a String bean with the id "clientRepository". JpaClientRepository is
the implementation class of the bean. The data source is injected and is not declared in this class.
Question 4
Question 5
The statements number 5 is right.
1. You may auto-wiring properties by constructor, setter or properties in the same bean
2. The <constructor-arg> tag helps to instanciated a bean without default or no-args
constructor
3. The <constructor-arg> tag could take type and index to reduce ambiguity, but not name
which requires debug symbols.
Question 6
1. The @PostConstruct, @PreDestroy and @Resource annotations are defined in the JSR-250
"Common Annotations"
2. They belong to the javax.annotation package. You should add an external jar to use them in
Java 5. Java 6 and above integrates them.
3. The <context:component-scan> automatically detects stereotyped classes and turns on the
<context:annotation-config>
4. The <context:annotation-config > activates the Spring infrastructure for various annotations
to be detected in bean classes, including the JSR-250 annotations
5. The CommonAnnotationBeanPostProcessor supports common Java annotations out of the
box, in particular the JSR-250 annotations.
Question 7
Question 8
Question 9
Answers number 3 and 4 are valid.
Question 10
1. With modern mock API like Mockito or EasyMock, interfaces are not mandatory for mocking
or stubbing the service. But using interface remains easier when you have to manually mock
the service in unit test.
2. Auto-injection is possible with class. Spring uses CGLIB.
3. Dependency checking is an advantage of dependencies injection.
4. The Inversion of Control pattern requires an interface to separate 2 classes. This pattern
provides code more flexible, unit testable, loosely coupled and maintainable.
Question 11
Correct answers: 4
1. In the bean lifecycle, method annotated with @PostConstruct is called after the properties
set step and the BeanPostProcessors#postProcessBeforeInitialization step
2. Destroy methods of prototype beans are never called
3. In the bean lifecycle, the afterPropertiesSet callback method of the InitializingBean is called
after the method annotated with the @PostConstruct annotation and before the init-method
declared in the XML configuration file.
4. In the bean lifecycle, the method annotated with the @PreDestroy annotation is called
before the destroy callback of the DisposableBean interface and before the destroy-method
declared in the XML configuration file.
Question 12
1. In order to be taken into account by Spring, the ApplicationConfig class has to be annotated
with the @Configuration annotation
2. Default or no-arg constructor is mandatory. Here, the provided constructor with a
dataSource parameter is not taken into account
3. The bean name is clientRepository. The name property of the @Bean annotation is specified
thus the method name jpaClientRepository is ignored.
4. Singleton is the scope of the jpaClientRepository bean.
Question 13
Test
Question 14
1. The Spring context is cached across tests unless you use the @DirtiesContext annotation
2. With the Spring test module, dependency injection is available in test case. So you may auto-
wired the bean you are testing.
3. By default, a @ContextConfiguration annotated class inherits the Spring context
configuration file locations defined by an annotated superclass. The inheritLocations of this
attribute allows to change this default behavior.
4. If no context configuration file is provided to the @ContextConfiguration annotation, Spring
uses a file convention naming. It tries to load a file named with the test class name and
suffices by "-context.xml" (i.e. MyDaoTest-context.xml)
Question 15
What are the main advantage(s) for using Spring when writing integration tests?
1. More than testing multiple classes together, integration test may allow to test your spring
configuration file and/or to reuse it.
2. Mocking or stubbing is more frequent in unit tests than in integration tests. And Spring does
not provide any implementation or abstraction of mock framework.
3. The framework may create and roll back a transaction for each test method. Default rollback
policy could be changed by using the @TransactionConfiguration annotation. And default
mode could be overridden by the @Rollback annotation.
4. DependencyInjectionTestExecutionListener provides support for dependency injection and
initialization of test instances.
Question 16
Question 17
Answer 5 is correct.
1. The spring test module does not provide an abstraction layer for open source mock
frameworks like EasyMock, JMock or Mockito
2. The @Mock annotations comes from the Mockito framework
3. The spring test module does not provide mechanism to generate mock objects at runtime
Question 18
AOP
Question 19
Considering 2 classes AccountServiceImpl and ClientServiceImpl. Any of these 2 classes inherits from
each other. What is the result of the pointcut expressions?
execution(* *..AccountServiceImpl.update(..))
&& execution(* *..ClientServiceImpl.update(..))
Poincut expression could not satisfied both first and second execution point. Do not confuse the &&
operator and || operator.
Question 20
Due to the proxy-based nature of Spring's AOP framework, protected methods are by definition not
intercepted, neither for JDK proxie nor for CGLIB proxies. As a consequence, any given pointcut will
be matched against public methods only!
To intercept private and protected methods, AspecJ weaving should be used instead of the Spring’s
proxy-bases AOP framework.
Question 21
1. An object created by the AOP framework in order to implement the aspect contracts
2. If the target object does not implement any interfaces, then a CGLIB proxy will be created.
You could also use CGLIB proxy instead of JDK dynamic proxy
3. If the target object does not implement any interfaces, then a CGLIB proxy will be created.
4. When CGLIB proxy is used, final methods cannot be advised, as they cannot be overridden.
5. AOP Proxies are created by the AbstractAutoProxyCreator#postProcessAfterInitialization
method.
Question 22
Question 23
Correct answer: 4
Question 24
Correct answer: 1
1. Definition of an advice
2. Definition of a joint point
3. Represents nothing
4. Definition of a point cut
Question 25
Correct answer: 2
1. Definition of an advice
2. Definition of a pointcut
3. Represents nothing
Question 26
Correct answers: 1, 3
execution(* com.test.service..*.*(*))
1. True
2. The pattern (*) matches a method taking one parameter of any type
3. The com.test.service.account sub-package matches the pointcut
4. False for the same reason as answer number 2.
Question 27
Correct answers: 2
1. Interception of constructors requires the use of Spring-driven native AspectJ weaving instead
of Spring's proxy-based AOP framework
2. The @annotation designator enables to select methods that are annotated by a given
annotation
3. The staticinitialization AspectJ designator is not supported by Spring AOP
4. Pointcut expressions can be combined using &&, || and !
Question 28
Correct answers: 1
Data Access
Question 29
Correct answers: 2, 4
Question 30
Correct answers: 1, 3, 4
Question 31
Correct answer: 1
Question 32
Correct answer: 3
1. RowMapper: result set parsing when needed to map each row into a custom object
2. RowCallbackHandler: result set parsing without returning a result to the JdbcTemplate caller
3. ResultSetExtractor: for result set parsing and merging rows into a single object
4. ResultSetMapper: this class does not exist
Question 33
Correct answer: 4
1. True using the annotedClasses property. For Hibernate 3.x, this property is available from the
AnnotationSessionFactoryBean child class.
2. True using the packagesToScan property. For Hibernate 3.x, this property is available from
the AnnotationSessionFactoryBean child class.
3. True using the mappingLocations property.
4. True
Transaction
Question 34
Correct answer: 2
1. <tx:jta-transaction-manager />
2. Id of the transaction manager bean could be customized (ie. txManager)
3. DataSourceTransactionManager is a transaction manager for a JDBC data source.
HibernateTransactionManager may be used to manage transaction with Hibernate.
4. The AbstractPlatformTransactionManager has a defaultTimeout property that could be
customized
Question 35
Correct answer: 2
In proxy mode, only external method calls coming in through the proxy are intercepted. In the code
snippet, the add() method is self-invocated. This means that, the @Transactional annotation of the
add() method is not interpreted. The REQUIRES_NEW propagation level is not taken into account.
To summary, when the transferMoney() methods calls add() method directly, the transaction
attributes of add() method are not used
Question 36
Correct answer: 1
Question 37
Correct answer: 3
1. PROPAGATION_REQUIRED
2. PROPAGATION_NESTED
3. PROPAGATION_REQUIRES_NEW
Question 38
Correct answer: 2
1. False.
2. True
3. False
4. False
Sping @MVC
Question 39
Correct answer: 1
Question 40
Correct answer: 2, 4
1. Spring MVC controllers are beans. So you can declare them into a Spring application context
XML configuration file that could be loaded by the DispatcherServlet.
2. In the web.xml, you may declarer and a ContextLoaderListener and a DispatcherServlet that
are in charge to load XML Spring configuration files. But you cannot declare controllers
directly in those files.
3. The @Controller annotation may be used to annotated Spring MVC Controller beans that
handle HTTP requests.
4. JSP is the View of the MVC Pattern. Thus this is not the right place to declare any controller.
Question 41
Correct answer: 3
4. The @PathVariable annotation has to be bound to a URI template variable. This is not the
case.
Sping Security
Question 42
Correct answer: 4
Question 43
Question 44
Correct answer: 2
REST
Question 45
Correct answers: 1, 4
1. Right: the HTTP GET method is used read (or retrieve) a representation of a resource. This is
the aim of the the findOwer method. Compared to the POST verb that is most-often used to
create new resources.
2. Wrong: the @PathParam annotation has the same purpose than the @PathVariable
annotation. But it belongs to JAX-RS. You cannot use it in Spring MVC but for instance in
Apache CXF or Jersey.
3. Wrong: the 201 HTTP status code means "Resource created”. It follows a POST command this
indicates success.
4. Right: the @RestController annotation marks the OwnerController class as a controller
where every method returns a domain object instead of a view. It’s shorthand for
@Controller and @ResponseBody rolled together. By annotating the controller class with
@RestController annotation, you no longer need to add @ResponseBody to all the request
mapping methods.
Question 46
Correct answers: 1
1. Right: starting from Spring Framework 4.2, the @ResponseStatus annotation is detected on
nested exceptions.
2. Wrong: this is the job of the ResponseStatusExceptionResolver class
3. Wrong: this is the opposite.
4. Wrong: @ResponseStatus annotation on a @RestController class is not supported
Microservices
Question 47
Correct answers: 1, 3, 4
1. Pro: a micro-service is responsible only for one thing. It requires less code than a monolith
application and has less risk of changes. A new developer becomes productive quickly.
2. Con: distributed system are harder to program. Developers have to consider a whole host
of concerns that they didn't with monolith: backwards compatibility, fault tolerance,
latency, asynchronicity, several message formats …
3. Pro: simple services are easier to deploy, and since they are autonomous, are less likely to
cause system failures when they go wrong. Starts the web container more quickly, so the
deployment is also faster.
4. Pro: if one microservice gets a lot of load you can scale just it, rather than the entire
application.
Question 48
Correct answers: 2, 4
1. Wrong: Spring Cloud supports Service Discovery solution as Eureka and Consul. But it does
not implement the Service Discovery pattern.
2. Right: the Spring Cloud Config project provides both a server and a client -side support for
externalized configuration in a distributed system.
3. Wrong: Spring Cloud does not support Docker out of the box
4. Right: Spring Cloud supports Netflix implementation of common microservices patterns:
Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client
Side Load Balancing (Ribbon).
Spring Boot
Question 49
Correct answers: 1, 3, 4
1. Right: using Undertow instead of Tomcat is very similar to using Jetty instead of Tomcat.
2. Wrong: unlike Spring Roo, one of the main goal of Spring Boot is to avoid code generation
3. Right: The auto-configuration part of Spring Boot can be achieved thanks to the conditionals
annotations. These annotations will activate different configurations depending on the
classes, beans, properties or resources that are detected in the classpath.
4. Right: this is Starter POMs
5. Wrong: Java-based and XML are supported. Spring Boot favors Java-based configuration.
Although it is possible to call SpringApplication.run() with an XML source and use the
@ImportResource annotation to import Spring XML configuration file. Instead of properties,
YAML is supported to externalize environment variables.
Question 50
Correct answer: 4
By default, SpringApplication will load properties from application.properties files. To support YAML,
the SnakeYAML library has to be add to the classpath.