0字左右外文翻译Word文档格式.docx
《0字左右外文翻译Word文档格式.docx》由会员分享,可在线阅读,更多相关《0字左右外文翻译Word文档格式.docx(16页珍藏版)》请在冰豆网上搜索。
系部
xxxx
专业
学生姓名
学号
指导教师
职称
2013年3月
IntroducingtheSpringFramework
TheSpringFramework:
apopularopensourceapplicationframeworkthataddressesmanyoftheissuesoutlinedinthisbook.ThischapterwillintroducethebasicideasofSpringanddis-cussthecentral“beanfactory”lightweightInversion-of-Control(IoC)containerindetail.
Springmakesitparticularlyeasytoimplementlightweight,yetextensible,J2EEarchi-tectures.Itprovidesanout-of-the-boximplementationofthefundamentalarchitecturalbuildingblockswerecommend.Springprovidesaconsistentwayofstructuringyourapplications,andprovidesnumerousmiddletierfeaturesthatcanmakeJ2EEdevelopmentsignificantlyeasierandmoreflexiblethanintraditionalapproaches.
ThebasicmotivationsforSpringare:
Toaddressareasnotwellservedbyotherframeworks.TherearenumerousgoodsolutionstospecificareasofJ2EEinfrastructure:
webframeworks,persistencesolutions,remotingtools,andsoon.However,integratingthesetoolsintoacomprehensivearchitecturecaninvolvesignificanteffort,andcanbecomeaburden.Springaimstoprovideanend-to-endsolution,integratingspe-cializedframeworksintoacoherentoverallinfrastructure.Springalsoaddressessomeareasthatotherframeworksdon’t.Forexample,fewframeworksaddressgenerictransactionmanagement,dataaccessobjectimplementation,andgluingallthosethingstogetherintoanapplication,whilestillallowingforbest-of-breedchoiceineacharea.HencewetermSpringanapplicationframework,ratherthanawebframework,IoCorAOPframework,orevenmiddletierframework.
Toallowforeasyadoption.Aframeworkshouldbecleanlylayered,allowingtheuseofindi-vidualfeatureswithoutimposingawholeworldviewontheapplication.ManySpringfeatures,suchastheJDBCabstractionlayerorHibernateintegration,canbeusedinalibrarystyleoraspartoftheSpringend-to-endsolution.
Todelivereaseofuse.Aswe’venoted,J2EEoutoftheboxisrelativelyhardtousetosolvemanycommonproblems.Agoodinfrastructureframeworkshouldmakesimpletaskssimpletoachieve,withoutforcingtradeoffsforfuturecomplexrequirements(likedistributedtransactions)ontheapplicationdeveloper.ItshouldallowdeveloperstoleverageJ2EEservicessuchasJTAwhereappropriate,buttoavoiddependenceonthemincaseswhentheyareunnecessarilycomplex.
Tomakeiteasiertoapplybestpractices.Springaimstoreducethecostofadheringtobestpracticessuchasprogrammingtointerfaces,ratherthanclasses,almosttozero.However,itleavesthechoiceofarchitecturalstyletothedeveloper.
Non-invasiveness.Applicationobjectsshouldhaveminimaldependenceontheframework.IfleveragingaspecificSpringfeature,anobjectshoulddependonlyonthatparticularfeature,whetherbyimplementingacallbackinterfaceorusingtheframeworkasaclasslibrary.IoCandAOParethekeyenablingtechnologiesforavoidingframeworkdependence.
Consistentconfiguration.Agoodinfrastructureframeworkshouldkeepapplicationconfigurationflexibleandconsistent,avoidingtheneedforcustomsingletonsandfactories.Asinglestyleshouldbeapplicabletoallconfigurationneeds,fromthemiddletiertowebcontrollers.
Easeoftesting.Testingeitherwholeapplicationsorindividualapplicationclassesinunittestsshouldbeaseasyaspossible.Replacingresourcesorapplicationobjectswithmockobjectsshouldbestraightforward.
Toallowforextensibility.BecauseSpringisitselfbasedoninterfaces,ratherthanclasses,itiseasytoextendorcustomizeit.ManySpringcomponentsusestrategyinterfaces,allowingeasycustomization.
ALayeredApplicationFramework
Chapter6introducedtheSpringFrameworkasalightweightcontainer,competingwithIoCcontainerssuchasPicoContainer.WhiletheSpringlightweightcontainerforJavaBeansisacoreconcept,thisisjustthefoundationforasolutionforallmiddlewarelayers.
BasicBuildingBlocks
pringisafull-featuredapplicationframeworkthatcanbeleveragedatmanylevels.Itconsistsofmulti-plesub-frameworksthatarefairlyindependentbutstillintegratecloselyintoaone-stopshop,ifdesired.Thekeyareasare:
Beanfactory.TheSpringlightweightIoCcontainer,capableofconfiguringandwiringupJava-BeansandmostplainJavaobjects,removingtheneedforcustomsingletonsandadhocconfigura-tion.Variousout-of-the-boximplementationsincludeanXML-basedbeanfactory.ThelightweightIoCcontaineranditsDependencyInjectioncapabilitieswillbethemainfocusofthischapter.
Applicationcontext.ASpringapplicationcontextextendsthebeanfactoryconceptbyaddingsupportformessagesourcesandresourceloading,andprovidinghooksintoexistingenviron-ments.Variousout-of-the-boximplementationsincludestandaloneapplicationcontextsandanXML-basedwebapplicationcontext.
AOPframework.TheSpringAOPframeworkprovidesAOPsupportformethodinterceptiononanyclassmanagedbyaSpringlightweightcontainer.Itsupportseasyproxyingofbeansinabeanfactory,seamlesslyweavingininterceptorsandotheradviceatruntime.Chapter8dis-cussestheSpringAOPframeworkindetail.ThemainuseoftheSpringAOPframeworkistoprovidedeclarativeenterpriseservicesforPOJOs.
Auto-proxying.SpringprovidesahigherlevelofabstractionovertheAOPframeworkandlow-levelservices,whichofferssimilarease-of-useto.NETwithinaJ2EEcontext.Inparticular,theprovisionofdeclarativeenterpriseservicescanbedrivenbysource-levelmetadata.
Transactionmanagement.Springprovidesagenerictransactionmanagementinfrastructure,withpluggabletransactionstrategies(suchasJTAandJDBC)andvariousmeansfordemarcat-ingtransactionsinapplications.Chapter9discussesitsrationaleandthepowerandflexibilitythatitoffers.
DAOabstraction.Springdefinesasetofgenericdataaccessexceptionsthatcanbeusedforcre-atinggenericDAOinterfacesthatthrowmeaningfulexceptionsindependentoftheunderlyingpersistencemechanism.Chapter10illustratestheSpringsupportforDAOsinmoredetail,examiningJDBC,JDO,andHibernateasimplementationstrategies.
JDBCsupport.SpringofferstwolevelsofJDBCabstractionthatsignificantlyeasetheeffortofwritingJDBC-basedDAOs:
theorg.springframework.jdbc.corepackage(atemplate/
callbackapproach)andtheorg.springframework.jdbc.objectpackage(modelingRDBMSoperationsasreusableobjects).UsingtheSpringJDBCpackagescandelivermuchgreaterpro-ductivityandeliminatethepotentialforcommonerrorssuchasleakedconnections,comparedwithdirectuseofJDBC.TheSpringJDBCabstractionintegrateswiththetransactionandDAOabstractions.
IntegrationwithO/Rmappingtools.SpringprovidessupportclassesforO/RMappingtoolslikeHibernate,JDO,andiBATISDatabaseLayertosimplifyresourcesetup,acquisition,andrelease,andtointegratewiththeoveralltransactionandDAOabstractions.TheseintegrationpackagesallowapplicationstodispensewithcustomThreadLocalsessionsandnativetransac-tionhandling,regardlessoftheunderlyingO/Rmappingapproachtheyworkwith.
WebMVCframework.SpringprovidesacleanimplementationofwebMVC,consistentwiththeJavaBeanconfigurationapproach.TheSpringwebframeworkenableswebcontrollerstobeconfiguredwithinanIoCcontainer,eliminatingtheneedtowriteanycustomcodetoaccessbusinesslayerservices.ItprovidesagenericDispatcherServletandout-of-the-boxcontrollerclassesforcommandandformhandling.Request-to-controllermapping,viewresolution,localeresolutionandotherimportantservicesareallpluggable,makingtheframeworkhighlyextensi-ble.ThewebframeworkisdesignedtoworknotonlywithJSP,butwithanyviewtechnology,suchasVelocity—withouttheneedforadditionalbridges.Chapter13discusseswebtierdesignandtheSpringwebMVCframeworkindetail.
Remotingsupport.Springprovidesathinabstractionlayerforaccessingremoteserviceswithouthard-codedlookups,andforexposingSpring-managedapplicationbeansasremoteservices.Out-of-the-boxsupportisincludedforRMI,Caucho’sHessianandBurlapwebserviceprotocols,andWSDLWebServicesviaJAX-RPC.Chapter11discusseslightweightremoting.
WhileSpringaddressesareasasdiverseastransactionmanagementandwebMVC,itusesaconsistentapproacheverywhere.Onceyouhavelearnedthebasicconfigurationstyle,youwillbeabletoapplyitinmanyareas.Resources,middletierobjects,andwebcomponentsareallsetupusingthesamebeanconfigurationmechanism.Youcancombineyourentireconfigurationinonesinglebeandefinitionsplititbyapplicationmodulesorlayers;
thechoiceisuptoyouastheapplicationdeveloper.Thereisnoneedfordiverseconfigurationfilesinavarietyofformats,spreadoutacrosstheapplication.
SpringonJ2EE
AlthoughmanypartsofSpringcanbeusedinanykindofJavaenvironment,itisprimarilyaJ2EEapplicationframework.Forexample,thereareconvenienceclassesforlinkingJNDIresourcesintoabeanfactory,suchasJDBCDataSourcesandEJBs,andintegrationwithJTAfordistributedtransactionmanagement.Inmostcases,applicationobjectsdonotneedtoworkwithJ2EEAPIsdirectly,improvingreusabilityandmeaningthatthereisnoneedtowriteverbose,hard-to-test,JNDIlookups.
ThusSpringallowsapplicationcodetoseamlesslyintegrateintoaJ2EEenvironmentwithoutbeingunnecessarilytiedtoit.YoucanbuilduponJ2EEserviceswhereitmakessenseforyourapplication,andchooselighter-weightsolutionsiftherearenoc