Core Spring 4.2 Certification Mock Exam

Description

Free mock exam for the Spring Professional certification based on the Spring Core 4.2 course
Tharaka Dinesh Wijesooriya
Quiz by Tharaka Dinesh Wijesooriya, updated more than 1 year ago More Less
antoine.rey
Created by antoine.rey almost 9 years ago
Tharaka Dinesh Wijesooriya
Copied by Tharaka Dinesh Wijesooriya over 7 years ago
37
0

Resource summary

Question 1

Question
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"/>
Answer
  • The first declared bean MyServiceImpl is missing an id must be named myService
  • The second declared bean JpaDao is missing an id must be named jpaDao
  • Answers 1 and 2 are both rights
  • Answers 1 and 2 are both wrong

Question 2

Question
Given the Spring configuration file, which are the correct statements? <bean class="com.spring.service.BankServiceImpl" p:bankName="NationalBank"> </bean>
Answer
  • The p namespace has to be declared
  • Bean id is bankServiceImpl
  • The BankServiceImpl references a NationalBank bean
  • NationalBank is a scalar value

Question 3

Question
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; } }
Answer
  • JpaClientRepository
  • jpaClientRepository
  • clientRepository
  • Two beans are defined: a data souce and a repository

Question 4

Question
How could you externalize constants from a Spring configuration file or a Spring annotation into a .properties file? Select one or more answers
Answer
  • By using the <util:constant /> tag
  • By declaring the ConstantPlaceholderConfigurer bean post processor
  • By using the <context:property-placeholder /> tag
  • By using the c: namespace

Question 5

Question
What statement is not correct in live environment? Select a unique answer.
Answer
  • Constuctor and properties autowiring in the same bean are not compatible
  • A bean should have a default or a no-args constructor
  • The <constructor-arg> tag could take type, name and index to reduce ambiguity
  • None of the above
  • All of the above

Question 6

Question
What are the right affirmations about the @PostConstruct, @Resource and the @PreDestroy annotations?
Answer
  • Those annotations are specified in the JSR-250
  • The Spring Framework embedded those annotations
  • The <context:component-scan> tag enable them
  • The <context:annotation-config > tag enable them
  • Declaring the CommonAnnotationBeanPostProcessor enable them

Question 7

Question
What is/are typically case(s) where you usually need to manually instantiated an ApplicationContext?
Answer
  • In a web application
  • In an integration test running with the SpringJUnit4ClassRunner
  • In a standalone application started with a main method
  • None of the above

Question 8

Question
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");
Answer
  • The classpath: prefix could be omitted
  • Package name using the dot character is not well formatted
  • The slash character preceding com.example could be omit
  • All of the above
  • None of the above

Question 9

Question
How to auto-inject into a field a Spring bean by its name? Select one or more answer choices.
Answer
  • With the name attribute of the @Autowired annotation
  • By using the single @Qualifier annotation
  • By using both the @Autowired and the @Qualifier Spring annotations
  • By using the @Autowired annotation and naming the field with the bean name

Question 10

Question
What are the main advantages of using interfaces when designing business services? Select one or more answer choices.
Answer
  • Mocking or stubbing the service
  • Be able to use the Spring auto-injection
  • Can do dependency checking
  • Loosely coupled code

Question 11

Question
Select one or many correct answers about Spring bean life cycle.
Answer
  • The method annotated with @PostConstruct is called after bean instantiation and before properties setting of the bean
  • The method @PreDestroy of a prototype bean is called when the bean is garbage collected
  • 1. The init() method declared in the init-method attribute of a bean is called before the afterPropertiesSet callback method of the InitializingBean interface
  • 1. The method annotated with @PostConstruct is called before the afterPropertiesSet callback method of the InitializingBean interface

Question 12

Question
Given the following configuration class, what are the correct affirmations? Select one or more answers. public class ApplicationConfig { private DataSource dataSource; @Autowired public ApplicationConfig(DataSource dataSource) { this.dataSource = dataSource; } @Bean(name="clientRepository") ClientRepository jpaClientRepository() { return new JpaClientRepository(); } }
Answer
  • Configuration annotation is missing
  • Default or no-arg constructor is missing
  • @Bean name is ambiguous
  • @Bean scope is prototype

Question 13

Question
What are the features of the XML <context:namespace? Select one or many answers.
Answer
  • @Transactional annotation scanning
  • @Aspect annotation detection enabling
  • @Autowired annotation enabling
  • @Component annotation scanning

Question 14

Question
Select one or more correct statements about developing integration test with Spring support.
Answer
  • A new Spring context is created for each test class
  • To get a reference on the bean you want to test, you have to call the getBean() method of the Spring context
  • Spring context configuration could be inherited from the super class
  • 1. The Spring context configuration file has to be provided to the @ContextConfiguration annotation

Question 15

Question
What are the main advantage(s) for using Spring when writing integration tests?
Answer
  • Reuse Spring configuration files of the application
  • Create mock or stub
  • Be able to use the rollback after the test pattern
  • Use dependency injection

Question 16

Question
What are the main advantage(s) for using Spring when writing unit tests?
Answer
  • Reuse Spring configuration files of the application
  • Use dependency injection
  • Provide some mocks for servlet classes
  • All of the above
  • None of the above

Question 17

Question
What is right about the Spring test module?
Answer
  • It provides an abstraction layer for the main open source mock frameworks
  • Provides the @Mock annotation
  • It dynamically generates mock objects
  • All of the above
  • None of the above

Question 18

Question
Select correct statement(s) about transactional support of the Spring test module.
Answer
  • Transaction manager could be set within the @TransactionConfiguration annotation
  • Method annotated with @Before is executed outside of the test’s transaction
  • Spring test may rollback the transaction of a service configured with the REQUIRES_NEW propagation
  • The transaction of a method annotated with the @Rollback annotation with its default values is rolled back after the method has completed

Question 19

Question
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(..))
Answer
  • Matches public update methods of the 2 classes, whatever the arguments
  • Matches any update methods of the 2 classes, whatever the arguments and method visibility
  • Matches any update methods of the 2 classes, with one more arguments and whatever method visibility
  • No joint point is defined

Question 20

Question
Using the Spring AOP framework, what is the visibility of the method matches by the following join point? @Pointcut("execution(* *(..))") private void anyOperation() {};
Answer
  • All methods, whereas their visibility
  • All methods, except private method
  • Protected and public methods
  • Public methods

Question 21

Question
What are the 2 correct statements about AOP proxy?
Answer
  • AOP proxies are created by Spring in order to implement the aspect contracts
  • AOP proxies are always created with a JDK dynamic proxy
  • Only classes that implements a least one interface could be proxied
  • All methods could be proxied
  • Proxies are created by a BeanPostProcessor

Question 22

Question
What is an after throwing advice? Select a unique answer.
Answer
  • Advice that could throw an exception
  • Advice to be executed if a method exits by throwing an exception
  • Advice that executes before a join point
  • Spring does not provide this type of advice

Question 23

Question
What is an after returning advice? Select a unique answer.
Answer
  • Advice to be executed regardless of the means by which a join point exits
  • Advice that surrounds a method invocation and can perform custom behavior before and after the method invocation
  • Advice to be executed before method invocation
  • Advice to be executed after a join point completes without throwing an exception

Question 24

Question
What is an advice? Select a unique answer.
Answer
  • An action taken by an aspect at a particular join point
  • A point during the execution of a program
  • An aspect and a pointcut
  • A predicate that matches join points

Question 25

Question
What is a pointcut? Select the single answer.
Answer
  • Code to execute at a join point
  • An expression to identify joinpoints
  • An advice and a jointpoint
  • None of the above

Question 26

Question
Select method’s signatures that match with the following pointcut: execution(* com.test.service..*.*(*))
Answer
  • void com.test.service.MyServiceImpl#transfert(Money amount)
  • void com.test.service.MyServiceImpl#transfert(Account account, Money amount)
  • void com.test.service.account.MyServiceImpl#transfert(Money amount)
  • void com.test.service.account.MyServiceImpl#transfert(Account account, Money amount)
  • None of the above

Question 27

Question
What are the unique right answer about Spring AOP support?
Answer
  • An advice could proxied a constructor’s class
  • A pointcut could select methods that have a custom annotation
  • Static initialization code could be targeted by a point cut
  • Combination of pointcuts by &&, || and the ! operators is not supported

Question 28

Question
Using the Spring AOP framework, what are the joinpoint methods of the following pointcut expressions? execution(public * *(..))
Answer
  • The execution of all public method
  • The execution of all public method returning a value
  • The execution of all public method having at least one parameter
  • The execution of all public method in class belonging to the default java package

Question 29

Question
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.
Answer
  • It is mandatory for using Spring exception translation mechanism
  • May be improve performance when using Hibernate
  • Spring optimizes its transaction interceptor
  • Provides safeguards with Oracle and some other databases

Question 30

Question
What data access technology is supported by the Spring framework? Select one or more answers.
Answer
  • JDBC
  • NoSQL
  • Hibernate
  • JPA

Question 31

Question
What is not provided by the JdbcTemplate? Select a unique answer.
Answer
  • Data source access
  • Open/close data source connection
  • JDBC exception wrapping into DataAccess Exception
  • JDBC statement execution

Question 32

Question
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.
Answer
  • RowMapper
  • RowCallbackHandler
  • ResultSetExtractor
  • ResultSetMapper

Question 33

Question
What configuration is supported by the LocalSessionFactoryBean which supports Hibernate 4 or higher? Select a unique answer.
Answer
  • Listing entity classes annotated with @Entity
  • Scanning a package to detect annotated entity classes (with @Entity)
  • Listing hibernate XML mapping configuration file (.hbm.xml)
  • All above

Question 34

Question
What is/are incorrect statements about XML declaration of the transaction manager bean? Select one or more answers.
Answer
  • The tx namespace provides JTA transaction manager declaration shortcut syntax
  • Id of the bean has to be transactionManager
  • Depending the application persistence technology, the HibernateTransactionManager or the DataSourceTransactionManager could be used as bean class
  • Default transaction timeout could be given

Question 35

Question
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) { // IMPLEMENTATION }
Answer
  • The add() method executes code in a new transaction
  • The add() method uses the transaction of the transferMoney() method
  • When calling the add() method, an exception is thrown
  • Other behavior

Question 36

Question
Does Spring provide programmatic transaction management? Select a unique answer.
Answer
  • Yes with the TransactionTemplate class
  • Yes with the TransactionService class
  • Yes using the @Transactional bean post processor
  • No

Question 37

Question
What is the transaction behavior of the PROPAGATION_REQUIRES_NEW mode? Select a unique answer.
Answer
  • 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.
  • 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.
  • 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.
  • None of the above

Question 38

Question
What is the default rollback policy in transaction management?
Answer
  • Rollback for any Exception
  • Rollback for RuntimeException
  • Rollback for checked exceptions
  • Always commit

Question 39

Question
What could not return a Spring MVC controller? Select a single answer.
Answer
  • An absolute path to the view
  • A logical view name
  • A new JstlView
  • void
  • null value

Question 40

Question
Where do you cannot declare Spring MVC controller? Select one or more answers.
Answer
  • In a Spring application context XML configuration file
  • Into the web.xml file of the web application
  • Into the java code by using annotations
  • Into the JSP pages

Question 41

Question
What is the easiest method to write a unit test?
Answer
  • void displayAccount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
  • void displayAccount(HttpServletRequest req, HttpSession Session) throws ServletException, IOException
  • @RequestMapping("/displayAccount") String displayAccount(@RequestParam("accountId") int id, Model model)
  • 1. @RequestMapping("/displayAccount") String displayAccount(@PathVariable("accountId") int id, Model model)

Question 42

Question
How could you secure MVC controller with Spring Security? Select a unique answer.
Answer
  • With the @Secured annotation
  • With the @RolesAllowed annotation
  • In a XML security configuration file
  • All of the above
  • None of the above

Question 43

Question
What are the possible mechanisms provided by Spring Security to store user details? Select one or more correct answers.
Answer
  • Database
  • JAAS
  • LDAP
  • Properties file

Question 44

Question
What is right about Spring Security configuration and the security namespace? Select one or more correct answers.
Answer
  • The access attribute of the intercept-url tag support both EL and constants together.
  • The patterns declared into the intercept-url tag are analyzed from up to bottom. Winning is the first that matches.
  • The patterns declared into the intercept-url tag use by default the java regex syntax.
  • Security rules may apply depending request parameter

Question 45

Question
Which of the following is true regarding the below Spring controller? @RestController public class OwnerController { @RequestMapping(value = "/owner/{ownerId}", method = RequestMethod.POST) @ResponseBody public Owner findOwner(@PathVariable("ownerId") int ownerId) { return new Owner(); } }
Answer
  • RequestMethod.GET method is more accurate than POST
  • @PathVariable should be replaced with the @PathParam annotation
  • Returning the 201 HTTP status code is better
  • @ResponseBody could be removed

Question 46

Question
Which of the following statements is true regarding the @ResponseStatus annotation?
Answer
  • @ResponseStatus is detected on nested exceptions
  • The ExceptionHandlerExceptionResolver uses the @ResponseStatus annotation to map exception to HTTP status code
  • A controller handler is annotated with the @ResponseStatus, the response status set by RedirectView takes precedence over the annotation value.
  • The @ResponseStatus annotation can go on a @RequestMapping method or a @RestController class or a business exception class.

Question 47

Question
Compared to monolithic application, what are the advantage(s) of microservices?
Answer
  • The base code is easy to understand
  • Imply a simple distributed system
  • Easier deployment
  • Fine-grained scaling

Question 48

Question
What Spring Cloud provides in a microservices architecture?
Answer
  • A Service Discovery implementation
  • A server for externalized configuration
  • A Dockerfile building an image that runs any Spring Boot application
  • Netflix OSS integration for Spring Boot

Question 49

Question
What provides Spring Boot?
Answer
  • Support for Jetty and Undertow as embedded containers
  • Java code generation
  • Auto-configuration of the Spring Framework and third libraries
  • Convenient dependency descriptors to load transitive dependencies
  • Support both Java-based and YAML for Spring application context configuration

Question 50

Question
What is the name of the default environment configuration file of Spring Boot?
Answer
  • application.json
  • configuration.spring
  • configuration.yml
  • configuration.xml
  • application.properties
Show full summary Hide full summary

Similar

Core Spring 4.2 Certification Mock Exam
Abdullah G
Core Spring 4.2 Certification Mock Exam
luis enrique perez galindo
Spring 4.2 Certification Mock Exam
Karthikeyan Vaithilingam
How well do you know GoConqr?
Sarah Egan
GA IQ Set of Exam Questions
Rob Winners
Cloud Data Integration Specialist Certification
James McLean
Revision Timetable
katy.lay
General Knowledge Quiz
Andrea Leyden
OCR Gateway GCSE P3 Revision Quiz
xhallyx
Ancient Roman Quiz
Rev32
The Engineered World - Unit 1
Yachtmasterhammond