Quiz
Core Spring 4.2 Certification Mock Exam
Este quiz tem tempo limite, por isso abre no player de sempre.
Perguntas do quiz (50)
1Given 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"/>- AThe first declared bean MyServiceImpl is missing an id must be named myService
- BThe second declared bean JpaDao is missing an id must be named jpaDao
- CAnswers 1 and 2 are both rights
- DAnswers 1 and 2 are both wrong
2Given the Spring configuration file, which are the correct statements?
<bean class="com.spring.service.BankServiceImpl"
p:bankName="NationalBank">
</bean>- AThe p namespace has to be declared
- BBean id is bankServiceImpl
- CThe BankServiceImpl references a NationalBank bean
- DNationalBank is a scalar value
3What 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;
}
}- AJpaClientRepository
- BjpaClientRepository
- CclientRepository
- DTwo beans are defined: a data souce and a repository
4How could you externalize constants from a Spring configuration file or a Spring annotation into a .properties file? Select one or more answers
- ABy using the <util:constant /> tag
- BBy declaring the ConstantPlaceholderConfigurer bean post processor
- CBy using the <context:property-placeholder /> tag
- DBy using the c: namespace
5What statement is not correct in live environment? Select a unique answer.
- AConstuctor and properties autowiring in the same bean are not compatible
- BA bean should have a default or a no-args constructor
- CThe <constructor-arg> tag could take type, name and index to reduce ambiguity
- DNone of the above
- EAll of the above
6What are the right affirmations about the @PostConstruct, @Resource and the @PreDestroy annotations?
- AThose annotations are specified in the JSR-250
- BThe Spring Framework embedded those annotations
- CThe <context:component-scan> tag enable them
- DThe <context:annotation-config > tag enable them
- EDeclaring the CommonAnnotationBeanPostProcessor enable them
7What is/are typically case(s) where you usually need to manually instantiated an ApplicationContext?
- AIn a web application
- BIn an integration test running with the SpringJUnit4ClassRunner
- CIn a standalone application started with a main method
- DNone of the above
8Select 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");- AThe classpath: prefix could be omitted
- BPackage name using the dot character is not well formatted
- CThe slash character preceding com.example could be omit
- DAll of the above
- ENone of the above
9How to auto-inject into a field a Spring bean by its name? Select one or more answer choices.
- AWith the name attribute of the @Autowired annotation
- BBy using the single @Qualifier annotation
- CBy using both the @Autowired and the @Qualifier Spring annotations
- DBy using the @Autowired annotation and naming the field with the bean name
10What are the main advantages of using interfaces when designing business services? Select one or more answer choices.
- AMocking or stubbing the service
- BBe able to use the Spring auto-injection
- CCan do dependency checking
- DLoosely coupled code
11Select one or many correct answers about Spring bean life cycle.
- AThe method annotated with @PostConstruct is called after bean instantiation and before properties setting of the bean
- BThe method @PreDestroy of a prototype bean is called when the bean is garbage collected
- C1. The init() method declared in the init-method attribute of a bean is called before the afterPropertiesSet callback method of the InitializingBean interface
- D1. The method annotated with @PostConstruct is called before the afterPropertiesSet callback method of the InitializingBean interface
12Given 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();
}
}- AConfiguration annotation is missing
- BDefault or no-arg constructor is missing
- C@Bean name is ambiguous
- D@Bean scope is prototype
13What are the features of the XML <context:namespace? Select one or many answers.
- A@Transactional annotation scanning
- B@Aspect annotation detection enabling
- C@Autowired annotation enabling
- D@Component annotation scanning
14Select one or more correct statements about developing integration test with Spring support.
- AA new Spring context is created for each test class
- BTo get a reference on the bean you want to test, you have to call the getBean() method of the Spring context
- CSpring context configuration could be inherited from the super class
- D1. The Spring context configuration file has to be provided to the @ContextConfiguration annotation
15What are the main advantage(s) for using Spring when writing integration tests?
- AReuse Spring configuration files of the application
- BCreate mock or stub
- CBe able to use the rollback after the test pattern
- DUse dependency injection
16What are the main advantage(s) for using Spring when writing unit tests?
- AReuse Spring configuration files of the application
- BUse dependency injection
- CProvide some mocks for servlet classes
- DAll of the above
- ENone of the above
17What is right about the Spring test module?
- AIt provides an abstraction layer for the main open source mock frameworks
- BProvides the @Mock annotation
- CIt dynamically generates mock objects
- DAll of the above
- ENone of the above
18Select correct statement(s) about transactional support of the Spring test module.
- ATransaction manager could be set within the @TransactionConfiguration annotation
- BMethod annotated with @Before is executed outside of the test’s transaction
- CSpring test may rollback the transaction of a service configured with the REQUIRES_NEW propagation
- DThe transaction of a method annotated with the @Rollback annotation with its default values is rolled back after the method has completed
19Considering 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(..))- AMatches public update methods of the 2 classes, whatever the arguments
- BMatches any update methods of the 2 classes, whatever the arguments and method visibility
- CMatches any update methods of the 2 classes, with one more arguments and whatever method visibility
- DNo joint point is defined
20Using the Spring AOP framework, what is the visibility of the method matches by the following join point?
@Pointcut("execution(* *(..))")
private void anyOperation() {};- AAll methods, whereas their visibility
- BAll methods, except private method
- CProtected and public methods
- DPublic methods
21What are the 2 correct statements about AOP proxy?
- AAOP proxies are created by Spring in order to implement the aspect contracts
- BAOP proxies are always created with a JDK dynamic proxy
- COnly classes that implements a least one interface could be proxied
- DAll methods could be proxied
- EProxies are created by a BeanPostProcessor
22What is an after throwing advice? Select a unique answer.
- AAdvice that could throw an exception
- BAdvice to be executed if a method exits by throwing an exception
- CAdvice that executes before a join point
- DSpring does not provide this type of advice
23What is an after returning advice? Select a unique answer.
- AAdvice to be executed regardless of the means by which a join point exits
- BAdvice that surrounds a method invocation and can perform custom behavior before and after the method invocation
- CAdvice to be executed before method invocation
- DAdvice to be executed after a join point completes without throwing an exception
24What is an advice? Select a unique answer.
- AAn action taken by an aspect at a particular join point
- BA point during the execution of a program
- CAn aspect and a pointcut
- DA predicate that matches join points
25What is a pointcut? Select the single answer.
- ACode to execute at a join point
- BAn expression to identify joinpoints
- CAn advice and a jointpoint
- DNone of the above
26Select method’s signatures that match with the following pointcut:
execution(* com.test.service..*.*(*))- Avoid com.test.service.MyServiceImpl#transfert(Money amount)
- Bvoid com.test.service.MyServiceImpl#transfert(Account account, Money amount)
- Cvoid com.test.service.account.MyServiceImpl#transfert(Money amount)
- Dvoid com.test.service.account.MyServiceImpl#transfert(Account account, Money amount)
- ENone of the above
27What are the unique right answer about Spring AOP support?
- AAn advice could proxied a constructor’s class
- BA pointcut could select methods that have a custom annotation
- CStatic initialization code could be targeted by a point cut
- DCombination of pointcuts by &&, || and the ! operators is not supported
28Using the Spring AOP framework, what are the joinpoint methods of the following pointcut expressions?
execution(public * *(..))- AThe execution of all public method
- BThe execution of all public method returning a value
- CThe execution of all public method having at least one parameter
- DThe execution of all public method in class belonging to the default java package
29Why 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.
- AIt is mandatory for using Spring exception translation mechanism
- BMay be improve performance when using Hibernate
- CSpring optimizes its transaction interceptor
- DProvides safeguards with Oracle and some other databases
30What data access technology is supported by the Spring framework? Select one or more answers.
- AJDBC
- BNoSQL
- CHibernate
- DJPA
31What is not provided by the JdbcTemplate? Select a unique answer.
- AData source access
- BOpen/close data source connection
- CJDBC exception wrapping into DataAccess Exception
- DJDBC statement execution
32Using 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.
- ARowMapper
- BRowCallbackHandler
- CResultSetExtractor
- DResultSetMapper
33What configuration is supported by the LocalSessionFactoryBean which supports Hibernate 4 or higher? Select a unique answer.
- AListing entity classes annotated with @Entity
- BScanning a package to detect annotated entity classes (with @Entity)
- CListing hibernate XML mapping configuration file (.hbm.xml)
- DAll above
34What is/are incorrect statements about XML declaration of the transaction manager bean? Select one or more answers.
- AThe tx namespace provides JTA transaction manager declaration shortcut syntax
- BId of the bean has to be transactionManager
- CDepending the application persistence technology, the HibernateTransactionManager or the DataSourceTransactionManager could be used as bean class
- DDefault transaction timeout could be given
35Assuming @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
}- AThe add() method executes code in a new transaction
- BThe add() method uses the transaction of the transferMoney() method
- CWhen calling the add() method, an exception is thrown
- DOther behavior
36Does Spring provide programmatic transaction management? Select a unique answer.
- AYes with the TransactionTemplate class
- BYes with the TransactionService class
- CYes using the @Transactional bean post processor
- DNo
37What is the transaction behavior of the PROPAGATION_REQUIRES_NEW mode? Select a unique answer.
- AIf a transaction exists, the current method should run within this transaction. Otherwise, it should start a new transaction and run within its own transaction.
- BIf 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.
- CThe current method must start a new transaction and run within its own transaction. If there is an existing transaction in progress, it is suspended.
- DNone of the above
38What is the default rollback policy in transaction management?
- ARollback for any Exception
- BRollback for RuntimeException
- CRollback for checked exceptions
- DAlways commit
39What could not return a Spring MVC controller? Select a single answer.
- AAn absolute path to the view
- BA logical view name
- CA new JstlView
- Dvoid
- Enull value
40Where do you cannot declare Spring MVC controller? Select one or more answers.
- AIn a Spring application context XML configuration file
- BInto the web.xml file of the web application
- CInto the java code by using annotations
- DInto the JSP pages
41What is the easiest method to write a unit test?
- Avoid displayAccount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
- Bvoid displayAccount(HttpServletRequest req, HttpSession Session)
throws ServletException, IOException - C@RequestMapping("/displayAccount")
String displayAccount(@RequestParam("accountId") int id, Model model) - D1. @RequestMapping("/displayAccount")
String displayAccount(@PathVariable("accountId") int id, Model model)
42How could you secure MVC controller with Spring Security? Select a unique answer.
- AWith the @Secured annotation
- BWith the @RolesAllowed annotation
- CIn a XML security configuration file
- DAll of the above
- ENone of the above
43What are the possible mechanisms provided by Spring Security to store user details? Select one or more correct answers.
- ADatabase
- BJAAS
- CLDAP
- DProperties file
44What is right about Spring Security configuration and the security namespace? Select one or more correct answers.
- AThe access attribute of the intercept-url tag support both EL and constants together.
- BThe patterns declared into the intercept-url tag are analyzed from up to bottom. Winning is the first that matches.
- CThe patterns declared into the intercept-url tag use by default the java regex syntax.
- DSecurity rules may apply depending request parameter
45Which 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();
}
}- ARequestMethod.GET method is more accurate than POST
- B@PathVariable should be replaced with the @PathParam annotation
- CReturning the 201 HTTP status code is better
- D@ResponseBody could be removed
46Which of the following statements is true regarding the @ResponseStatus annotation?
- A@ResponseStatus is detected on nested exceptions
- BThe ExceptionHandlerExceptionResolver uses the @ResponseStatus annotation to map exception to HTTP status code
- CA controller handler is annotated with the @ResponseStatus, the response status set by RedirectView takes precedence over the annotation value.
- DThe @ResponseStatus annotation can go on a @RequestMapping method or a @RestController class or a business exception class.
47Compared to monolithic application, what are the advantage(s) of microservices?
- AThe base code is easy to understand
- BImply a simple distributed system
- CEasier deployment
- DFine-grained scaling
48What Spring Cloud provides in a microservices architecture?
- AA Service Discovery implementation
- BA server for externalized configuration
- CA Dockerfile building an image that runs any Spring Boot application
- DNetflix OSS integration for Spring Boot
49What provides Spring Boot?
- ASupport for Jetty and Undertow as embedded containers
- BJava code generation
- CAuto-configuration of the Spring Framework and third libraries
- DConvenient dependency descriptors to load transitive dependencies
- ESupport both Java-based and YAML for Spring application context configuration
50What is the name of the default environment configuration file of Spring Boot?
- Aapplication.json
- Bconfiguration.spring
- Cconfiguration.yml
- Dconfiguration.xml
- Eapplication.properties
Informações
- Descrição
- Free mock exam for the Spring Professional certification based on the Spring Core 4.2 course
- Autor
- antoine.rey
- Idioma
- English
- Visualizações
- 20.703
- Etiquetas
- Avaliação
- 4,3 de 5 · 3 avaliações Avalie este quiz