core spring 4.2 certification mock exam · 3. provide some mocks for servlet classes 4. all of the...

26
Core Spring 4.2 Certification Mock Exam 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"/> 1. The first declared bean MyServiceImpl is missing an id must be named myService 2. The second declared bean JpaDao is missing an id must be named jpaDao 3. Answers 1 and 2 are both rights 4. Answers 1 and 2 are both wrong Question 2 Given the Spring configuration file, which are the correct statements? <bean class="com.spring.service.BankServiceImpl" p:bankName="NationalBank"> </bean> 1. The p namespace has to be declared 2. Bean id is bankServiceImpl 3. The BankServiceImpl references a NationalBank bean 4. NationalBank is a scalar value 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;

Upload: others

Post on 23-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

CoreSpring4.2CertificationMockExam

Question

ContainerQuestion1

GiventhefollowingSpringconfigurationfile,whatisthecorrectanswer: <bean class="com.spring.service.MyServiceImpl"> <property name="repository" ref="jpaDao"/> </bean> <bean class="com.spring.repository.JpaDao"/>

1. ThefirstdeclaredbeanMyServiceImplismissinganidmustbenamedmyService

2. TheseconddeclaredbeanJpaDaoismissinganidmustbenamedjpaDao

3. Answers1and2arebothrights

4. Answers1and2arebothwrong

Question2

GiventheSpringconfigurationfile,whicharethecorrectstatements?

<bean class="com.spring.service.BankServiceImpl" p:bankName="NationalBank"> </bean>

1. Thepnamespacehastobedeclared

2. BeanidisbankServiceImpl

3. TheBankServiceImplreferencesaNationalBankbean

4. NationalBankisascalarvalue

Question3

Whatthenameofthebeandefinedinthefollowingconfigurationclass?Selectasingleanswer.

@Configuration public class ApplicationConfig { @Autowired private DataSource dataSource; @Bean ClientRepository clientRepository() { ClientRepository accountRepository = new JpaClientRepository(); accountRepository.setDataSource(dataSource); return accountRepository;

Page 2: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

}

}

1. JpaClientRepository

2. jpaClientRepository

3. clientRepository

4. Twobeansaredefined:adatasouceandarepository

Question4

HowcouldyouexternalizeconstantsfromaSpringconfigurationfileoraSpringannotationintoa

.propertiesfile?Selectoneormoreanswers

1. Byusingthe<util:constant/>tag

2. BydeclaringtheConstantPlaceholderConfigurerbeanpostprocessor

3. Byusingthe<context:property-placeholder/>tag

4. Byusingthec:namespace

Question5

Whatstatementisnotcorrectinliveenvironment?Selectauniqueanswer.

1. Constuctorandpropertiesautowiringinthesamebeanarenotcompatible

2. Abeanshouldhaveadefaultorano-argsconstructor

3. The<constructor-arg>tagcouldtaketype,nameandindextoreduceambiguity

4. Noneoftheabove

5. Alloftheabove

Question6

Whataretherightaffirmationsaboutthe@PostConstruct,@Resourceandthe@PreDestroy

annotations?

1. ThoseannotationsarespecifiedintheJSR-250

2. TheSpringFrameworkembeddedthoseannotations

3. The<context:component-scan>tagenablethem

4. The<context:annotation-config>tagenablethem

5. DeclaringtheCommonAnnotationBeanPostProcessorenablethem

Question7

Whatis/aretypicallycase(s)whereyouusuallyneedtomanuallyinstantiatedanApplicationContext?

1. Inawebapplication

2. InanintegrationtestrunningwiththeSpringJUnit4ClassRunner

3. Inastandaloneapplicationstartedwithamainmethod

4. Noneoftheabove

Page 3: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question8

SelecttherightstatementaboutreferringaSpringconfigurationfileinsidethepackagecom.example.myappinthebelowexample?ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/com.example.myapp.config.xml");

1. Theclasspath:prefixcouldbeomitted

2. Packagenameusingthedotcharacterisnotwellformatted

3. Theslashcharacterprecedingcom.examplecouldbeomit

4. Alloftheabove

5. Noneoftheabove

Question9

Howtoauto-injectintoafieldaSpringbeanbyitsname?Selectoneormoreanswerchoices.

1. Withthenameattributeofthe@Autowiredannotation

2. Byusingthesingle@Qualifierannotation

3. Byusingboththe@Autowiredandthe@QualifierSpringannotations

4. Byusingthe@Autowiredannotationandnamingthefieldwiththebeanname

Question10

Whatarethemainadvantagesofusinginterfaceswhendesigningbusinessservices?Selectoneor

moreanswerchoices.

1. Mockingorstubbingtheservice

2. BeabletousetheSpringauto-injection

3. Candodependencychecking

4. Looselycoupledcode

Question11

SelectoneormanycorrectanswersaboutSpringbeanlifecycle.

1. Themethodannotatedwith@PostConstructiscalledafterbeaninstantiationandbefore

propertiessettingofthebean

2. Themethod@PreDestroyofaprototypebeaniscalledwhenthebeanisgarbagecollected

3. Theinit()methoddeclaredintheinit-methodattributeofabeaniscalledbeforethe

afterPropertiesSetcallbackmethodoftheInitializingBeaninterface

4. Themethodannotatedwith@PostConstructiscalledbeforetheafterPropertiesSetcallback

methodoftheInitializingBeaninterface

Question12

Page 4: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Giventhefollowingconfigurationclass,whatarethecorrectaffirmations?Selectoneormore

answers.

public class ApplicationConfig { private DataSource dataSource; @Autowired public ApplicationConfig(DataSource dataSource) { this.dataSource = dataSource; } @Bean(name="clientRepository") ClientRepository jpaClientRepository() { return new JpaClientRepository(); } }

1. @Configurationannotationismissing

2. Defaultorno-argconstructorismissing

3. @Beannameisambiguous

4. @Beanscopeisprototype

Question13

WhatarethefeaturesoftheXML<context:namespace?Selectoneormanyanswers.

1. @Transactionalannotationscanning

2. @Aspectannotationdetectionenabling

3. @Autowiredannotationenabling

4. @Componentannotationscanning

Test

Question14

SelectoneormorecorrectstatementsaboutdevelopingintegrationtestwithSpringsupport.

1. AnewSpringcontextiscreatedforeachtestclass

2. Togetareferenceonthebeanyouwanttotest,youhavetocallthegetBean()methodof

theSpringcontext

3. Springcontextconfigurationcouldbeinheritedfromthesuperclass

4. TheSpringcontextconfigurationfilehastobeprovidedtothe@ContextConfiguration

annotation

Question15

Whatarethemainadvantage(s)forusingSpringwhenwritingintegrationtests?

1. ReuseSpringconfigurationfilesoftheapplication

2. Createmockorstub

Page 5: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

3. Beabletousetherollbackafterthetestpattern

4. Usedependencyinjection

Question16

Whatarethemainadvantage(s)forusingSpringwhenwritingunittests?

1. ReuseSpringconfigurationfilesoftheapplication

2. Usedependencyinjection

3. Providesomemocksforservletclasses

4. Alloftheabove

5. Noneoftheabove

Question17

WhatisrightabouttheSpringtestmodule?

1. Itprovidesanabstractionlayerforthemainopensourcemockframeworks

2. Providesthe@Mockannotation

3. Itdynamicallygeneratesmockobjects

4. Alloftheabove

5. Noneoftheabove

Question18

Selectcorrectstatement(s)abouttransactionalsupportoftheSpringtestmodule.

1. Transactionmanagercouldbesetwithinthe@TransactionConfigurationannotation

2. Methodannotatedwith@Beforeisexecutedoutsideofthetest’stransaction

3. SpringtestmayrollbackthetransactionofaserviceconfiguredwiththeREQUIRES_NEW

propagation

4. Thetransactionofamethodannotatedwiththe@Rollbackannotationwithitsdefault

valuesisrolledbackafterthemethodhascompleted

AOPQuestion19

Considering2classesAccountServiceImplandClientServiceImpl.Anyofthese2classesinheritsfrom

eachother.Whatistheresultofthefollowingpointcutexpression?

execution(**..AccountServiceImpl.update(..))

&&execution(**..ClientServiceImpl.update(..))

1. Matchespublicupdatemethodsofthe2classes,whateverthearguments

2. Matchesanyupdatemethodsofthe2classes,whatevertheargumentsandmethodvisibility

3. Matchesanyupdatemethodsofthe2classes,withonemoreargumentsandwhatever

methodvisibility

4. Nojointpointisdefined

Page 6: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question20

UsingtheSpringAOPframework,whatisthevisibilityofthemethodmatchesbythefollowingjoin

point?

@Pointcut("execution(* *(..))") private void anyOperation() {};

1. Allmethods,whereastheirvisibility

2. Allmethods,exceptprivatemethod

3. Protectedandpublicmethods

4. Publicmethods

Question21

Whatarethe2correctstatementsaboutAOPproxy?

1. AOPproxiesarecreatedbySpringinordertoimplementtheaspectcontracts

2. AOPproxiesarealwayscreatedwithaJDKdynamicproxy

3. Onlyclassesthatimplementsaleastoneinterfacecouldbeproxied

4. Allmethodscouldbeproxied

5. ProxiesarecreatedbyaBeanPostProcessor

Question22

Whatisanafterthrowingadvice?Selectauniqueanswer.

1. Advicethatcouldthrowanexception

2. Advicetobeexecutedifamethodexitsbythrowinganexception

3. Advicethatexecutesbeforeajoinpoint

4. Springdoesnotprovidethistypeofadvice

Question23

Whatisanafterreturningadvice?Selectauniqueanswer.

1. Advicetobeexecutedregardlessofthemeansbywhichajoinpointexits

2. Advicethatsurroundsamethodinvocationandcanperformcustombehaviorbeforeand

afterthemethodinvocation

3. Advicetobeexecutedbeforemethodinvocation

4. Advicetobeexecutedafterajoinpointcompleteswithoutthrowinganexception

Question24

Page 7: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Whatisanadvice?Selectauniqueanswer.

1. Anactiontakenbyanaspectataparticularjoinpoint

2. Apointduringtheexecutionofaprogram

3. Anaspectandapointcut

4. Apredicatethatmatchesjoinpoints

Question25

Whatisapointcut?Selectthesingleanswer.

1. Codetoexecuteatajoinpoint

2. Anexpressiontoidentifyjoinpoints

3. Anadviceandajointpoint

4. Noneoftheabove

Question26

Selectmethod’ssignaturesthatmatchwiththefollowingpointcut:

execution(*com.test.service..*.*(*))

1. voidcom.test.service.MyServiceImpl#transfert(Moneyamount)

2. voidcom.test.service.MyServiceImpl#transfert(Accountaccount,Moneyamount)

3. voidcom.test.service.account.MyServiceImpl#transfert(Moneyamount)

4. voidcom.test.service.account.MyServiceImpl#transfert(Accountaccount,Moneyamount)

5. Noneoftheabove

Question27

WhataretheuniquerightansweraboutSpringAOPsupport?

1. Anadvicecouldproxiedaconstructor’sclass2. Apointcutcouldselectmethodsthathaveacustomannotation3. Staticinitializationcodecouldbetargetedbyapointcut4. Combinationofpointcutsby&&,||andthe!operatorsisnotsupported

Question28

UsingtheSpringAOPframework,whatarethejoinpointmethodsofthefollowingpointcut

expressions?

execution(public**(..))

1. Theexecutionofallpublicmethod

2. Theexecutionofallpublicmethodreturningavalue

Page 8: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

3. Theexecutionofallpublicmethodhavingatleastoneparameter

4. Theexecutionofallpublicmethodinclassbelongingtothedefaultjavapackage

DataAccess

Question29

Whyisitabestpracticetomarktransactionasread-onlywhencodedoesnotwriteanythingtothe

database?Selectoneormoreanswers.

1. ItismandatoryforusingSpringexceptiontranslationmechanism

2. MaybeimproveperformancewhenusingHibernate

3. Springoptimizesitstransactioninterceptor

4. ProvidessafeguardswithOracleandsomeotherdatabases

Question30

WhatdataaccesstechnologyissupportedbytheSpringframework?Selectoneormoreanswers.

1. JDBC

2. NoSQL

3. Hibernate

4. JPA

Question31

WhatisnotprovidedbytheJdbcTemplate?Selectauniqueanswer.

1. Datasourceaccess

2. Open/closedatasourceconnection

3. JDBCexceptionwrappingintoDataAccessException

4. JDBCstatementexecution

Question32

UsingJdbcTemplate,whatistheSpringprovidedclassyouwilluseforresultsetparsingandmerging

rowsintoasingleobject?Selectauniqueanswer.

1. RowMapper

2. RowCallbackHandler

3. ResultSetExtractor

4. ResultSetMapper

Question33

WhatconfigurationissupportedbytheLocalSessionFactoryBeanwhichsupportsHibernate4or

higher?Selectauniqueanswer.

1. Listingentityclassesannotatedwith@Entity

Page 9: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

2. Scanningapackagetodetectannotatedentityclasses(with@Entity)

3. ListinghibernateXMLmappingconfigurationfile(.hbm.xml)

4. Allabove

TransactionQuestion34

Whatis/areincorrectstatementsaboutXMLdeclarationofthetransactionmanagerbean?Select

oneormoreanswers.

1. ThetxnamespaceprovidesJTAtransactionmanagerdeclarationshortcutsyntax

2. IdofthebeanhastobetransactionManager3. Dependingtheapplicationpersistencetechnology,theHibernateTransactionManagerorthe

DataSourceTransactionManagercouldbeusedasbeanclass

4. Defaulttransactiontimeoutcouldbegiven

Question35

Assuming@TransactionalannotationsupportisenabledandthetransferMoneymethodiscalled

throughaSpringAOPproxy,whatisthebehaviorofthefollowingcodesample?

@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 }

1. Theadd()methodexecutescodeinanewtransaction

2. Theadd()methodusesthetransactionofthetransferMoney()method

3. Whencallingtheadd()method,anexceptionisthrown

4. Otherbehavior

Question36

DoesSpringprovideprogrammatictransactionmanagement?Selectauniqueanswer.

1. YeswiththeTransactionTemplateclass

2. YeswiththeTransactionServiceclass

3. Yesusingthe@Transactionalbeanpostprocessor

4. No

Page 10: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question37

WhatisthetransactionbehaviorofthePROPAGATION_REQUIRES_NEWmode?Selectaunique

answer.

1. Ifatransactionexists,thecurrentmethodshouldrunwithinthistransaction.Otherwise,it

shouldstartanewtransactionandrunwithinitsowntransaction.

2. Ifatransactionisinprogress,thecurrentmethodshouldrunwithinthenestedtransaction

oftheexistingtransaction.Otherwise,anewtransactionhastobestartedandrunwithinits

owntransaction.

3. Thecurrentmethodmuststartanewtransactionandrunwithinitsowntransaction.Ifthere

isanexistingtransactioninprogress,itissuspended.

4. Noneoftheabove

Question38

Whatisthedefaultrollbackpolicyintransactionmanagement?

1. RollbackforanyException

2. RollbackforRuntimeException

3. Rollbackforcheckedexceptions

4. Alwayscommit

Sping@MVC

Question39

WhatcouldnotreturnaSpringMVCcontroller?Selectasingleanswer.

1. Anabsolutepathtotheview

2. Alogicalviewname

3. AnewJstlView

4. void

5. nullvalue

Question40

WheredoyoucannotdeclareSpringMVCcontroller?Selectoneormoreanswers.

1. InaSpringapplicationcontextXMLconfigurationfile

2. Intotheweb.xmlfileofthewebapplication

3. Intothejavacodebyusingannotations

4. IntotheJSPpages

Page 11: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question41Whatistheeasiestmethodtowriteaunittest?

1. void displayAccount(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

2. void displayAccount(HttpServletRequest req, HttpSession Session) throws ServletException, IOException

3. @RequestMapping("/displayAccount") String displayAccount(@RequestParam("accountId") int id, Model model)

4. @RequestMapping("/displayAccount") String displayAccount(@PathVariable("accountId") int id, Model model)

SpringSecurity

Question42

HowcouldyousecureMVCcontrollerwithSpringSecurity?Selectauniqueanswer.

1. Withthe@Securedannotation

2. Withthe@RolesAllowedannotation

3. InaXMLsecurityconfigurationfile

4. Alloftheabove

5. Noneoftheabove

Question43

WhatarethepossiblemechanismsprovidedbySpringSecuritytostoreuserdetails?Selectoneor

morecorrectanswers.

1. Database

2. JAAS

3. LDAP

4. Propertiesfile

Question44

WhatisrightaboutSpringSecurityconfigurationandthesecuritynamespace?Selectoneormore

correctanswers.

Page 12: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

1. Theaccessattributeoftheintercept-urltagsupportbothELandconstantstogether.

2. Thepatternsdeclaredintotheintercept-urltagareanalyzedfromuptobottom.Winningis

thefirstthatmatches.

3. Thepatternsdeclaredintotheintercept-urltagusebydefaultthejavaregexsyntax.

4. Securityrulesmayapplydependingrequestparameter

RESTQuestion45WhichofthefollowingistrueregardingthebelowSpringcontroller?

@RestController public class OwnerController { @RequestMapping(value = "/owner/{ownerId}", method = RequestMethod.POST) @ResponseBody public Owner findOwner(@PathVariable("ownerId") int ownerId) { return new Owner(); } }

1. RequestMethod.GETmethodismoreaccuratethanPOST2. @PathVariableshouldbereplacedwiththe@PathParamannotation3. Returningthe201HTTPstatuscodeisbetter4. @ResponseBodycouldberemoved

Question46

Whichofthefollowingstatementsistrueregardingthe@ResponseStatusannotation?

1. @ResponseStatusisdetectedonnestedexceptions2. TheExceptionHandlerExceptionResolverusesthe@ResponseStatusannotationtomap

exceptiontoHTTPstatuscode3. Acontrollerhandlerisannotatedwiththe@ResponseStatus,theresponsestatussetby

RedirectViewtakesprecedenceovertheannotationvalue.4. The@ResponseStatusannotationcangoona@RequestMappingmethodora@RestController

classorabusinessexceptionclass.

MicroserviceQuestion47

Comparedtomonolithicapplication,whataretheadvantage(s)ofmicroservices?

1. Thebasecodeiseasytounderstand2. Implyasimpledistributedsystem3. Easierdeployment

Page 13: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

4. Fine-grainedscaling

Question48

WhatSpringCloudprovidesinamicroservicesarchitecture?

1. AServiceDiscoveryimplementation2. Aserverforexternalizedconfiguration3. ADockerfilebuildinganimagethatrunsanySpringBootapplication4. NetflixOSSintegrationforSpringBoot

SpringBootQuestion49

WhatprovidesSpringBoot?

1. SupportforJettyandUndertowasembeddedcontainers2. Javacodegeneration3. Auto-configurationoftheSpringFrameworkandthirdlibraries4. Convenientdependencydescriptorstoloadtransitivedependencies5. SupportbothJava-basedandYAMLforSpringapplicationcontextconfiguration

Question50

WhatisthenameofthedefaultenvironmentconfigurationfileofSpringBoot?

1. configuration.spring2. configuration.yml3. configuration.xml4. application.properties5. application.json

Page 14: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Response

ContainerQuestion1

Answer2iscorrect.Thosebeansareanonymousbecausenoidissuppliedexplicitly.ThusSpring

containergeneratesauniqueidforthatbean.Itusesthefullyqualifiedclassnameandappendsa

numbertothem.However,ifyouwanttorefertothatbeanbyname,throughtheuseoftheref

elementyoumustprovideaname(seeNamingBeanssectionoftheSpringreferencemanual).Tobe

correct,the2ndbeanhastodeclareajpaDaoidattributeinordertobereferencebythe

repositorypropertyofthefirstbean.

Question2

Answers1and4arecorrect.

1. Tosetbean’spropertywiththep:propertyNameshortcut,youhavetodeclarethe

http://www.springframework.org/schema/pinyourxmlconfigurationfile.Noxsdis

required.

2. Thebeanisanonymous.Springgeneratesauniqueid:com.spring.service.BankServiceImpl#0

3. Toreferenceanotherbeanwiththepnamespace,youhavetousethep:propertyName-ref

syntax

4. Duetotheaboveexplanation,NationalBankisnotabeanreference,soitisasimpleString

andthusascalarvalue.

Question3

Correctansweris3.

The@BeanannotationdefinesaStringbeanwiththeid"clientRepository".JpaClientRepositoryis

theimplementationclassofthebean.Thedatasourceisinjectedandisnotdeclaredinthisclass.

Question4

Theonlypossibleansweristhenumber3.

1. The<util:constantstatic-field="constantname"/>tagenablestoreferenceaJavaconstantor

enumerationintoaspringconfigurationfile

2. ConstantPlaceholderConfigurerdoesnotexist.Youmaythinkaboutthe

PropertyPlaceholderConfigurer,whichisaBeanFactorypostprocessor.

3. The<context:property-placeholderlocation="file:/myApp.properties"/>tagactivatesthe

replacementof${...}placeholders,resolvedagainstthespecifiedpropertiesfile.

4. Thec:namespaceisforsimplifyingconstructorsyntax(sinceSpring3.1)anddon’tprovide

suchfeature.

Question5

Page 15: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Thestatementsnumber5isright.

1. Youmayauto-wiringpropertiesbyconstructor,setterorpropertiesinthesamebean

2. The<constructor-arg>taghelpstoinstanciatedabeanwithoutdefaultorno-args

constructor

3. The<constructor-arg>tagcouldtaketypeandindextoreduceambiguity,butnotname

whichrequiresdebugsymbols.

Question6Answers1,3,4and5arerights.

1. The@PostConstruct,@PreDestroyand@ResourceannotationsaredefinedintheJSR-250

"CommonAnnotations"

2. Theybelongtothejavax.annotationpackage.Youshouldaddanexternaljartousethemin

Java5.Java6andaboveintegratesthem.

3. The<context:component-scan>automaticallydetectsstereotypedclassesandturnsonthe

<context:annotation-config>

4. The<context:annotation-config>activatestheSpringinfrastructureforvariousannotations

tobedetectedinbeanclasses,includingtheJSR-250annotations

5. TheCommonAnnotationBeanPostProcessorsupportscommonJavaannotationsoutofthe

box,inparticulartheJSR-250annotations.

Question7

Correctanswerinthenumber3.

1. Inawebapplication,theContextLoaderListenerisinchargetocreatean

WebApplicationContext.

2. InanintegrationtestbasedonSpring,theSpringJUnit4ClassRunnercreatestheapplication

contextforyou.The@ContextConfigurationannotationallowstospecifiedapplication

contextconfigurationfiles.

3. Inamainmethod,youhavetoinstantiateaclassimplementingtheApplicationContext

interface(examples:ClassPathXmlApplicationContextorFileSystemXmlApplicationContext)

Question8

Answernumber4isright.

1. When using the ClassPathXmlApplicationContext, theclasspath:prefixisdefaultone

soyoucouldomitit

2. InaSpringlocationresource,packageseparatorisaslashandnotadot.Thusthe

com/example/myapp/config.xmlsyntaxhastobeused.

3. ClassPathXmlApplicationContextstartslookingfromrootoftheclasspathregardlessof

whetherspecify"/"

Question9

Page 16: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Answersnumber3and4arevalid.

1. The@Autowiredannotationhasnonameproperty,justarequiredone.

2. Forautowiring,the@Injectorthe@Autowiredorthe@Resourceannotationsare

mandatory.

3. The@Qualifier("name")annotationcompletestheuseofthe@Autowiredannotationby

specifyingthenameofthebeantoinject

4. When2beansareeligibletoauto-injection,Springusesthefieldnametoselectthe

appropriateone.

Question10

Answersnumber1and4arevalid.

1. WithmodernmockAPIlikeMockitoorEasyMock,interfacesarenotmandatoryformocking

orstubbingtheservice.Butusinginterfaceremainseasierwhenyouhavetomanuallymock

theserviceinunittest.

2. Auto-injectionispossiblewithclass.SpringusesCGLIB.

3. Dependencycheckingisanadvantageofdependenciesinjection.

4. TheInversionofControlpatternrequiresaninterfacetoseparate2classes.Thispattern

providescodemoreflexible,unittestable,looselycoupledandmaintainable.

Question11

Correctanswers:4

1. Inthebeanlifecycle,methodannotatedwith@PostConstructiscalledaftertheproperties

setstepandtheBeanPostProcessors#postProcessBeforeInitializationstep

2. Destroymethodsofprototypebeansarenevercalled

3. Inthebeanlifecycle,theafterPropertiesSetcallbackmethodoftheInitializingBeaniscalled

afterthemethodannotatedwiththe@PostConstructannotationandbeforetheinit-method

declaredintheXMLconfigurationfile.

4. Inthebeanlifecycle,themethodannotatedwiththe@PreDestroyannotationiscalled

beforethedestroycallbackoftheDisposableBeaninterfaceandbeforethedestroy-method

declaredintheXMLconfigurationfile.

Question12

Correctanswersare1and2.

1. InordertobetakenintoaccountbySpring,theApplicationConfigclasshastobeannotated

withthe@Configurationannotation

2. Defaultorno-argconstructorismandatory.Here,theprovidedconstructorwitha

dataSourceparameterisnottakenintoaccount

3. ThebeannameisclientRepository.Thenamepropertyofthe@Beanannotationisspecified

thusthemethodnamejpaClientRepositoryisignored.

4. SingletonisthescopeofthejpaClientRepositorybean.

Page 17: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question13

Correctanswersare3and4

1. Use<tx:annotation-driven/>toenable@Transactionalannotationscanning

2. Use<aop:aspectj-autoproxy/>toenabledetectionof@Aspectbean

3. Turnson<context:annotation-config/>or<context:component-scan/>toenable

@Autowiringannotation

4. Turnson<context:component-scan/>toenable@Componentannotationscanning

Test

Question14

Theonlycorrectanswerisnumber3.

1. TheSpringcontextiscachedacrosstestsunlessyouusethe@DirtiesContextannotation

2. WiththeSpringtestmodule,dependencyinjectionisavailableintestcase.Soyoumayauto-

wiredthebeanyouaretesting.

3. Bydefault,a@ContextConfigurationannotatedclassinheritstheSpringcontext

configurationfilelocationsdefinedbyanannotatedsuperclass.TheinheritLocationsofthis

attributeallowstochangethisdefaultbehavior.

4. Ifnocontextconfigurationfileisprovidedtothe@ContextConfigurationannotation,Spring

usesafileconventionnaming.Ittriestoloadafilenamedwiththetestclassnameand

sufficesby"-context.xml"(i.e.MyDaoTest-context.xml)

Question15

Correctanswersare1,3and4.

Whatarethemainadvantage(s)forusingSpringwhenwritingintegrationtests?

1. Morethantestingmultipleclassestogether,integrationtestmayallowtotestyourspring

configurationfileand/ortoreuseit.

2. Mockingorstubbingismorefrequentinunitteststhaninintegrationtests.AndSpringdoes

notprovideanyimplementationorabstractionofmockframework.

3. Theframeworkmaycreateandrollbackatransactionforeachtestmethod.Defaultrollback

policycouldbechangedbyusingthe@TransactionConfigurationannotation.Anddefault

modecouldbeoverriddenbythe@Rollbackannotation.

4. DependencyInjectionTestExecutionListenerprovidessupportfordependencyinjectionand

initializationoftestinstances.

Question16

Thecorrectansweristhenumber3.

Page 18: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Whatarethemainadvantage(s)forusingSpringwhenwritingunittests?

1. Youdon’tneedSpringcontainertowriteunittest

2. Refertotheanswernumber1.

3. Theorg.springframework.mockpackageprovidesmockclasseslikeMockHttpSessionor

MockHttpContext.Theycouldbehelpfulforunittestinthepresentationlayerandwhenyou

don’tuseanymockframeworksuchasMockityorEasyMock.

Question17

Answer5iscorrect.

Whatisrightaboutthespringtestmodule?

1. Thespringtestmoduledoesnotprovideanabstractionlayerforopensourcemock

frameworkslikeEasyMock,JMockorMockito

2. The@MockannotationscomesfromtheMockitoframework

3. Thespringtestmoduledoesnotprovidemechanismtogeneratemockobjectsatruntime

Question18

Correctstatementsarenumber1and4.

1. ThetransactionManagerpropertyofthe@TransactionConfigurationannotationenablesto

setthebeannameofthePlatformTransactionManagerthatistobeusedtodrive

transactions.

2. Methodannotatedwith@Beforeisexecutedinsidethetest’stransaction.Youhavetouse

the@BeforeTransactiontoexecutecodeoutsidethetest’stransaction.

3. TheREQUIRES_NEWpropagationsuspendsthecurrenttest’stransactionthencreatesanew

transactionthatwillbeusedtoexecutetheservice.Acommitattheservicelevelcouldnot

bechangedbythetest.

4. Thetransactionfortheannotatedmethodshouldberolledbackafterthemethodhas

completed.

AOPQuestion19

Thecorrectansweristhenumber4.

Considering2classesAccountServiceImplandClientServiceImpl.Anyofthese2classesinheritsfrom

eachother.Whatistheresultofthepointcutexpressions?

execution(**..AccountServiceImpl.update(..))

&&execution(**..ClientServiceImpl.update(..))

Poincutexpressioncouldnotsatisfiedbothfirstandsecondexecutionpoint.Donotconfusethe&&

operatorand||operator.

Page 19: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question20

Correctansweristhenumber4.

Duetotheproxy-basednatureofSpring'sAOPframework,protectedmethodsarebydefinitionnot

intercepted,neitherforJDKproxienorforCGLIBproxies.Asaconsequence,anygivenpointcutwill

bematchedagainstpublicmethodsonly!

Tointerceptprivateandprotectedmethods,AspecJweavingshouldbeusedinsteadoftheSpring’s

proxy-basesAOPframework.

Question21

The2correctstatementsare1and5.

Whatarethe2correctstatementsaboutAOPproxy.

1. AnobjectcreatedbytheAOPframeworkinordertoimplementtheaspectcontracts

2. Ifthetargetobjectdoesnotimplementanyinterfaces,thenaCGLIBproxywillbecreated.

YoucouldalsouseCGLIBproxyinsteadofJDKdynamicproxy

3. Ifthetargetobjectdoesnotimplementanyinterfaces,thenaCGLIBproxywillbecreated.

4. WhenCGLIBproxyisused,finalmethodscannotbeadvised,astheycannotbeoverridden.

5. AOPProxiesarecreatedbytheAbstractAutoProxyCreator#postProcessAfterInitialization

method.

Question22

Theanswernumber2iscorrect.

1. Abeforeadvicecouldthrowanexception

2. Anafterthrowingadviceisexecutedifamethodexitsbythrowinganexception

3. Anadvicethatexecutesbeforeajoinpointisnamedabeforeadvice

4. Springsupportsafterthrowingadvices

Question23

Correctanswer:4

1. Thisisanafter(finally)advice

2. Thisisanaroundadvice

3. Thisisabeforeadvice

4. True

Question24

Correctanswer:1

Page 20: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

1. Definitionofanadvice

2. Definitionofajointpoint

3. Representsnothing

4. Definitionofapointcut

Question25

Correctanswer:2

1. Definitionofanadvice

2. Definitionofapointcut

3. Representsnothing

Question26

Correctanswers:1,3

Selectmethodsthatmatchwiththefollowingpointcut:

execution(*com.test.service..*.*(*))

1. True

2. Thepattern(*)matchesamethodtakingoneparameterofanytype

3. Thecom.test.service.accountsub-packagematchesthepointcut

4. Falseforthesamereasonasanswernumber2.

Question27

Correctanswers:2

1. InterceptionofconstructorsrequirestheuseofSpring-drivennativeAspectJweavinginstead

ofSpring'sproxy-basedAOPframework

2. The@annotationdesignatorenablestoselectmethodsthatareannotatedbyagiven

annotation

3. ThestaticinitializationAspectJdesignatorisnotsupportedbySpringAOP

4. Pointcutexpressionscanbecombinedusing&&,||and!

Question28

Correctanswers:1

1. Theexecutionofallpublicmethod

2. The*returntypepatternindicatesanyreturnvalueorvoid

3. The(..)parampatternindicates0,1ormanyparameters

Page 21: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

4. Nopackagenameisspecified.Soclassesofanypackagecouldmatch.

DataAccess

Question29

Correctanswers:2,4

1. Springexceptiontranslationmechanismhasnothingtodowithread-onlytransaction

2. Read-onlytransactionpreventsHibernatefromflushingitssession.Hibernatedoesnotapply

dirtycheckingthusitincreasesitsperformance.

3. No

4. WhenJSBCtransactionismarkedasread-only,OracleonlyacceptsSELECTSQLstatements.

Question30

Correctanswers:1,3,4

1. JDBCissupported:JdbcTemplate,JDBCExceptionwrapper…

2. SomeNoSQLdatabasesaresupportsthroughtheSpringDataproject

3. Hibernateissupported:HibernateTemplate,AnnotationSessionFactoryBean…

4. JPAissupported:LocalEntityManagerFactoryBean,@PersistenceContextannotationsupport

Question31

Correctanswer:1

1. AJdbcTemplaterequiresaDataSourceasinputparameters

2. JdbcTemplateusestheprovideddatasourcetoopenthencloseaJDBCconnection

3. CallbackmethodsoftheJdbcTemplatethrowsandSQLExceptionthanSpringconvertsintoa

DataAccessException

4. Forexample,thequeryForIntmethodexecutesanSQLstatement

Question32

Correctanswer:3

1. RowMapper:resultsetparsingwhenneededtomapeachrowintoacustomobject

2. RowCallbackHandler:resultsetparsingwithoutreturningaresulttotheJdbcTemplatecaller

3. ResultSetExtractor:forresultsetparsingandmergingrowsintoasingleobject

4. ResultSetMapper:thisclassdoesnotexist

Question33

Page 22: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Correctanswer:4

1. TrueusingtheannotedClassesproperty.ForHibernate3.x,thispropertyisavailablefromthe

AnnotationSessionFactoryBeanchildclass.

2. TrueusingthepackagesToScanproperty.ForHibernate3.x,thispropertyisavailablefrom

theAnnotationSessionFactoryBeanchildclass.

3. TrueusingthemappingLocationsproperty.

4. True

TransactionQuestion34

Correctanswer:2

1. <tx:jta-transaction-manager/>

2. Idofthetransactionmanagerbeancouldbecustomized(ie.txManager)3. DataSourceTransactionManagerisatransactionmanagerforaJDBCdatasource.

HibernateTransactionManagermaybeusedtomanagetransactionwithHibernate.

4. TheAbstractPlatformTransactionManagerhasadefaultTimeoutpropertythatcouldbe

customized

Question35

Correctanswer:2

Inproxymode,onlyexternalmethodcallscominginthroughtheproxyareintercepted.Inthecode

snippet,theadd()methodisself-invocated.Thismeansthat,the@Transactionalannotationofthe

add()methodisnotinterpreted.TheREQUIRES_NEWpropagationlevelisnottakenintoaccount.

Tosummary,whenthetransferMoney()methodscallsadd()methoddirectly,thetransaction

attributesofadd()methodarenotused

Question36

Correctanswer:1

1. TheTransactionTemplateclassprovidesanexecute(TransactionCallback)method

2. TheTransactionServiceclassdoesnotexists

3. The@Transactionalannotationisfordeclarativetransactionmanagement

Question37

Correctanswer:3

1. PROPAGATION_REQUIRED

2. PROPAGATION_NESTED

3. PROPAGATION_REQUIRES_NEW

Page 23: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

Question38

Correctanswer:2

1. False.

2. True

3. False

4. False

Sping@MVC

Question39

Correctanswer:1

1. Springdoesnotallowtoreturnanabsolutepathtotheview

2. ControllercouldreturnaStringthatmatcheswithalogicalviewname

3. AJstlViewwiththe.jsppath(i.e./WEB-INF/accountList.jsp)

4. voidforwardtothedefaultview

5. nullforwardtothedefaultview

Question40

Correctanswer:2,4

1. SpringMVCcontrollersarebeans.SoyoucandeclarethemintoaSpringapplicationcontext

XMLconfigurationfilethatcouldbeloadedbytheDispatcherServlet.

2. Intheweb.xml,youmaydeclarerandaContextLoaderListenerandaDispatcherServletthat

areinchargetoloadXMLSpringconfigurationfiles.Butyoucannotdeclarecontrollers

directlyinthosefiles.

3. The@ControllerannotationmaybeusedtoannotatedSpringMVCControllerbeansthat

handleHTTPrequests.

4. JSPistheViewoftheMVCPattern.Thusthisisnottherightplacetodeclareanycontroller.

Question41Correctanswer:3

1. HttpServletRequestandHttpServletResponsehavetobemocked.Idoftheaccounttodisplaycouldbesetintothehttprequestparameters.

2. HttpServletRequestandHttpSessionhavetobemocked.Idoftheaccounttodisplaycouldbesetintothehttprequestparameters.

Page 24: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

3. ThismethodisnotdependentoftheservletAPI.Idoftheaccounttodisplaymaybedirectlypassedthroughthecallstack.Thustestmethodsaresimplified.

4. The@PathVariableannotationhastobeboundtoaURItemplatevariable.Thisisnotthecase.

SpingSecurity

Question42

Correctanswer:4

1. @SecuredannotationisaSpringSecurityannotation

2. @RolesAllowedisaJSR-250annotationthatissupportedbySpringSecurity

3. SpringSecuritycouldbeconfiguredinaXMLwaytointerceptparticularURLs

Question43

Correctanswer:1,2,3and4

Question44

Correctanswer:2

1. YoucannotmixELandconstantinthesameconfigurationfile

2. Ifmorethanoneintercept-urlmatches,thetoponeisused

3. Antpatternisusedbydefault.Butyoucanchangetouseregularexpression.

4. SecurityrulesmayapplytorequestURL,requestmethod(GET,POST…)butnottorequest

parameters.

REST

Question45

Correctanswers:1,4

1. Right:theHTTPGETmethodisusedread(orretrieve)arepresentationofaresource.ThisistheaimofthethefindOwermethod.ComparedtothePOSTverbthatismost-oftenusedtocreatenewresources.

2. Wrong:the@PathParamannotationhasthesamepurposethanthe@PathVariableannotation.ButitbelongstoJAX-RS.YoucannotuseitinSpringMVCbutforinstanceinApacheCXForJersey.

Page 25: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

3. Wrong:the201HTTPstatuscodemeans"Resourcecreated”.ItfollowsaPOSTcommandthisindicatessuccess.

4. Right:the@RestControllerannotationmarkstheOwnerControllerclassasacontrollerwhereeverymethodreturnsadomainobjectinsteadofaview.It’sshorthandfor@Controllerand@ResponseBodyrolledtogether.Byannotatingthecontrollerclasswith@RestControllerannotation,younolongerneedtoadd@ResponseBodytoalltherequestmappingmethods.

Question46Correctanswers:1

1. Right:startingfromSpringFramework4.2,the@ResponseStatusannotationisdetectedonnestedexceptions.

2. Wrong:thisisthejoboftheResponseStatusExceptionResolverclass3. Wrong:thisistheopposite.4. Wrong:@ResponseStatusannotationona@RestControllerclassisnotsupported

MicroservicesQuestion47

Correctanswers:1,3,4

1. Pro:amicro-serviceisresponsibleonlyforonething.Itrequireslesscodethanamonolithapplicationandhaslessriskofchanges.Anewdeveloperbecomesproductivequickly.

2. Con:distributedsystemarehardertoprogram.Developershavetoconsiderawholehostofconcernsthattheydidn'twithmonolith:backwardscompatibility,faulttolerance,latency,asynchronicity,severalmessageformats…

3. Pro:simpleservicesareeasiertodeploy,andsincetheyareautonomous,arelesslikelytocausesystemfailureswhentheygowrong.Startsthewebcontainermorequickly,sothedeploymentisalsofaster.

4. Pro:ifonemicroservicegetsalotofloadyoucanscalejustit,ratherthantheentireapplication.

Question48

Correctanswers:2,4

1. Wrong:SpringCloudsupportsServiceDiscoverysolutionasEurekaandConsul.ButitdoesnotimplementtheServiceDiscoverypattern.

2. Right:theSpringCloudConfigprojectprovidesbothaserverandaclient-sidesupportforexternalizedconfigurationinadistributedsystem.

3. Wrong:SpringClouddoesnotsupportDockeroutofthebox4. Right:SpringCloudsupportsNetfliximplementationofcommonmicroservicespatterns:

ServiceDiscovery(Eureka),CircuitBreaker(Hystrix),IntelligentRouting(Zuul)andClientSideLoadBalancing(Ribbon).

Page 26: Core Spring 4.2 Certification Mock Exam · 3. Provide some mocks for servlet classes 4. All of the above 5. None of the above Question 17 What is right about the Spring test module?

SpringBootQuestion49

Correctanswers:1,3,4

1. Right:usingUndertowinsteadofTomcatisverysimilartousingJettyinsteadofTomcat.2. Wrong:unlikeSpringRoo,oneofthemaingoalofSpringBootistoavoidcodegeneration3. Right:Theauto-configurationpartofSpringBootcanbeachievedthankstotheconditionals

annotations.Theseannotationswillactivatedifferentconfigurationsdependingontheclasses,beans,propertiesorresourcesthataredetectedintheclasspath.

4. Right:thisisStarterPOMs5. Wrong:Java-basedandXMLaresupported.SpringBootfavorsJava-basedconfiguration.

AlthoughitispossibletocallSpringApplication.run()withanXMLsourceandusethe@ImportResourceannotationtoimportSpringXMLconfigurationfile.Insteadofproperties,YAMLissupportedtoexternalizeenvironmentvariables.

Question50

Correctanswer:4

Bydefault,SpringApplicationwillloadpropertiesfromapplication.propertiesfiles.TosupportYAML,

theSnakeYAMLlibraryhastobeaddtotheclasspath.