Top Banner
08/01/2017 Spring Framework Reference Documentation http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 1/645 Spring Framework Reference Documentation Authors Rod Johnson , Juergen Hoeller , Keith Donald , Colin Sampaleanu , Rob Harrop , Thomas Risberg , Alef Arendsen , Darren Davison , Dmitriy Kopylenko , Mark Pollack , Thierry Templier , Erwin Vervaet , Portia Tung , Ben Hale , Adrian Colyer , John Lewis , Costin Leau , Mark Fisher , Sam Brannen , Ramnivas Laddad , Arjen Poutsma , Chris Beams , Tareq Abedrabbo , Andy Clement , Dave Syer , Oliver Gierke , Rossen Stoyanchev , Phillip Webb , Rob Winch , Brian Clozel , Stephane Nicoll , Sebastien Deleuze 4.3.5.RELEASE Copyright © 20042016 Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. Table of Contents I. Overview of Spring Framework 1. Getting Started with Spring 2. Introduction to the Spring Framework 2.1. Dependency Injection and Inversion of Control 2.2. Modules 2.2.1. Core Container 2.2.2. AOP and Instrumentation 2.2.3. Messaging 2.2.4. Data Access/Integration 2.2.5. Web 2.2.6. Test 2.3. Usage scenarios 2.3.1. Dependency Management and Naming Conventions Spring Dependencies and Depending on Spring Maven Dependency Management Maven "Bill Of Materials" Dependency Gradle Dependency Management Ivy Dependency Management Distribution Zip Files 2.3.2. Logging Not Using Commons Logging Using SLF4J Using Log4J II. What’s New in Spring Framework 4.x 3. New Features and Enhancements in Spring Framework 4.0 3.1. Improved Getting Started Experience 3.2. Removed Deprecated Packages and Methods 3.3. Java 8 (as well as 6 and 7) 3.4. Java EE 6 and 7 3.5. Groovy Bean Definition DSL 3.6. Core Container Improvements 3.7. General Web Improvements 3.8. WebSocket, SockJS, and STOMP Messaging 3.9. Testing Improvements 4. New Features and Enhancements in Spring Framework 4.1
645

Spring Framework Reference Documentation - wp wp-qn.devnp.com/2017/books/Spring Framework Reference Docume · PDF file08/01/2017 Spring Framework Reference Documentation...

Mar 12, 2018

Download

Documents

doanque
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 08/01/2017 SpringFrameworkReferenceDocumentation

    http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 1/645

    SpringFrameworkReferenceDocumentation

    AuthorsRodJohnson,JuergenHoeller,KeithDonald,ColinSampaleanu,RobHarrop,ThomasRisberg,AlefArendsen,DarrenDavison,DmitriyKopylenko,MarkPollack,ThierryTemplier,ErwinVervaet,PortiaTung,BenHale,AdrianColyer,JohnLewis,CostinLeau,MarkFisher,SamBrannen,RamnivasLaddad,ArjenPoutsma,ChrisBeams,TareqAbedrabbo,AndyClement,DaveSyer,OliverGierke,RossenStoyanchev,PhillipWebb,RobWinch,BrianClozel,StephaneNicoll,SebastienDeleuze

    4.3.5.RELEASE

    Copyright20042016Copiesofthisdocumentmaybemadeforyourownuseandfordistributiontoothers,providedthatyoudonotchargeanyfeeforsuchcopiesandfurtherprovidedthateachcopycontainsthisCopyrightNotice,whetherdistributedinprintorelectronically.

    TableofContents

    I.OverviewofSpringFramework1.GettingStartedwithSpring

    2.IntroductiontotheSpringFramework2.1.DependencyInjectionandInversionofControl2.2.Modules

    2.2.1.CoreContainer2.2.2.AOPandInstrumentation2.2.3.Messaging2.2.4.DataAccess/Integration2.2.5.Web2.2.6.Test

    2.3.Usagescenarios2.3.1.DependencyManagementandNamingConventions

    SpringDependenciesandDependingonSpringMavenDependencyManagementMaven"BillOfMaterials"DependencyGradleDependencyManagementIvyDependencyManagementDistributionZipFiles

    2.3.2.LoggingNotUsingCommonsLoggingUsingSLF4JUsingLog4J

    II.WhatsNewinSpringFramework4.x3.NewFeaturesandEnhancementsinSpringFramework4.0

    3.1.ImprovedGettingStartedExperience3.2.RemovedDeprecatedPackagesandMethods3.3.Java8(aswellas6and7)3.4.JavaEE6and73.5.GroovyBeanDefinitionDSL3.6.CoreContainerImprovements3.7.GeneralWebImprovements3.8.WebSocket,SockJS,andSTOMPMessaging3.9.TestingImprovements

    4.NewFeaturesandEnhancementsinSpringFramework4.1

  • 08/01/2017 SpringFrameworkReferenceDocumentation

    http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 2/645

    4.1.JMSImprovements4.2.CachingImprovements4.3.WebImprovements4.4.WebSocketMessagingImprovements4.5.TestingImprovements

    5.NewFeaturesandEnhancementsinSpringFramework4.25.1.CoreContainerImprovements5.2.DataAccessImprovements5.3.JMSImprovements5.4.WebImprovements5.5.WebSocketMessagingImprovements5.6.TestingImprovements

    6.NewFeaturesandEnhancementsinSpringFramework4.36.1.CoreContainerImprovements6.2.DataAccessImprovements6.3.CachingImprovements6.4.JMSImprovements6.5.WebImprovements6.6.WebSocketMessagingImprovements6.7.TestingImprovements6.8.Supportfornewlibraryandservergenerations

    III.CoreTechnologies7.TheIoCcontainer

    7.1.IntroductiontotheSpringIoCcontainerandbeans7.2.Containeroverview

    7.2.1.Configurationmetadata7.2.2.Instantiatingacontainer

    ComposingXMLbasedconfigurationmetadata7.2.3.Usingthecontainer

    7.3.Beanoverview7.3.1.Namingbeans

    Aliasingabeanoutsidethebeandefinition7.3.2.Instantiatingbeans

    InstantiationwithaconstructorInstantiationwithastaticfactorymethodInstantiationusinganinstancefactorymethod

    7.4.Dependencies7.4.1.DependencyInjection

    ConstructorbaseddependencyinjectionSetterbaseddependencyinjectionDependencyresolutionprocessExamplesofdependencyinjection

    7.4.2.DependenciesandconfigurationindetailStraightvalues(primitives,Strings,andsoon)Referencestootherbeans(collaborators)InnerbeansCollectionsNullandemptystringvaluesXMLshortcutwiththepnamespaceXMLshortcutwiththecnamespaceCompoundpropertynames

    7.4.3.Usingdependson7.4.4.Lazyinitializedbeans7.4.5.Autowiringcollaborators

    LimitationsanddisadvantagesofautowiringExcludingabeanfromautowiring

  • 08/01/2017 SpringFrameworkReferenceDocumentation

    http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 3/645

    7.4.6.MethodinjectionLookupmethodinjectionArbitrarymethodreplacement

    7.5.Beanscopes7.5.1.Thesingletonscope7.5.2.Theprototypescope7.5.3.Singletonbeanswithprototypebeandependencies7.5.4.Request,session,globalsession,application,andWebSocketscopes

    InitialwebconfigurationRequestscopeSessionscopeGlobalsessionscopeApplicationscopeScopedbeansasdependencies

    7.5.5.CustomscopesCreatingacustomscopeUsingacustomscope

    7.6.Customizingthenatureofabean7.6.1.Lifecyclecallbacks

    InitializationcallbacksDestructioncallbacksDefaultinitializationanddestroymethodsCombininglifecyclemechanismsStartupandshutdowncallbacksShuttingdowntheSpringIoCcontainergracefullyinnonwebapplications

    7.6.2.ApplicationContextAwareandBeanNameAware7.6.3.OtherAwareinterfaces

    7.7.Beandefinitioninheritance7.8.ContainerExtensionPoints

    7.8.1.CustomizingbeansusingaBeanPostProcessorExample:HelloWorld,BeanPostProcessorstyleExample:TheRequiredAnnotationBeanPostProcessor

    7.8.2.CustomizingconfigurationmetadatawithaBeanFactoryPostProcessorExample:theClassnamesubstitutionPropertyPlaceholderConfigurerExample:thePropertyOverrideConfigurer

    7.8.3.CustomizinginstantiationlogicwithaFactoryBean

    [email protected][email protected]@Primary7.9.4.Finetuningannotationbasedautowiringwithqualifiers7.9.5.Usinggenericsasautowiringqualifiers7.9.6.CustomAutowireConfigurer7.9.7.@Resource7.9.8.@PostConstructand@PreDestroy

    7.10.Classpathscanningandmanagedcomponents7.10.1.@Componentandfurtherstereotypeannotations7.10.2.Metaannotations7.10.3.Automaticallydetectingclassesandregisteringbeandefinitions7.10.4.Usingfilterstocustomizescanning7.10.5.Definingbeanmetadatawithincomponents7.10.6.Namingautodetectedcomponents7.10.7.Providingascopeforautodetectedcomponents7.10.8.Providingqualifiermetadatawithannotations

    7.11.UsingJSR330StandardAnnotations7.11.1.DependencyInjectionwith@[email protected].@Namedand@ManagedBean:standardequivalentstothe@Componentannotation7.11.3.LimitationsofJSR330standardannotations

    7.12.Javabasedcontainerconfiguration7.12.1.Basicconcepts:@Beanand@Configuration7.12.2.InstantiatingtheSpringcontainerusingAnnotationConfigApplicationContext

    SimpleconstructionBuildingthecontainerprogrammaticallyusingregister(Class)Enablingcomponentscanningwithscan(String)SupportforwebapplicationswithAnnotationConfigWebApplicationContext

    7.12.3.Usingthe@BeanannotationDeclaringabeanBeandependenciesReceivinglifecyclecallbacksSpecifyingbeanscopeCustomizingbeannamingBeanaliasing

  • 08/01/2017 SpringFrameworkReferenceDocumentation

    http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 4/645

    Beandescription7.12.4.Usingthe@Configurationannotation

    InjectinginterbeandependenciesLookupmethodinjectionFurtherinformationabouthowJavabasedconfigurationworksinternally

    7.12.5.ComposingJavabasedconfigurationsUsingthe@ImportannotationConditionallyinclude@Configurationclassesor@BeanmethodsCombiningJavaandXMLconfiguration

    7.13.Environmentabstraction7.13.1.Beandefinitionprofiles

    @Profile7.13.2.XMLbeandefinitionprofiles

    ActivatingaprofileDefaultprofile

    7.13.3.PropertySourceabstraction7.13.4.@PropertySource7.13.5.Placeholderresolutioninstatements

    7.14.RegisteringaLoadTimeWeaver7.15.AdditionalCapabilitiesoftheApplicationContext

    7.15.1.InternationalizationusingMessageSource7.15.2.StandardandCustomEvents

    AnnotationbasedEventListenersAsynchronousListenersOrderingListenersGenericEvents

    7.15.3.Convenientaccesstolowlevelresources7.15.4.ConvenientApplicationContextinstantiationforwebapplications7.15.5.DeployingaSpringApplicationContextasaJavaEERARfile

    7.16.TheBeanFactory7.16.1.BeanFactoryorApplicationContext?7.16.2.Gluecodeandtheevilsingleton

    8.Resources8.1.Introduction8.2.TheResourceinterface8.3.BuiltinResourceimplementations

    8.3.1.UrlResource8.3.2.ClassPathResource8.3.3.FileSystemResource8.3.4.ServletContextResource8.3.5.InputStreamResource8.3.6.ByteArrayResource

    8.4.TheResourceLoader8.5.TheResourceLoaderAwareinterface8.6.Resourcesasdependencies8.7.ApplicationcontextsandResourcepaths

    8.7.1.ConstructingapplicationcontextsConstructingClassPathXmlApplicationContextinstancesshortcuts

    8.7.2.WildcardsinapplicationcontextconstructorresourcepathsAntstylePatternsTheClasspath*:portabilityclasspath*:prefixOthernotesrelatingtowildcards

    8.7.3.FileSystemResourcecaveats

    9.Validation,DataBinding,andTypeConversion9.1.Introduction9.2.ValidationusingSpringsValidatorinterface9.3.Resolvingcodestoerrormessages9.4.BeanmanipulationandtheBeanWrapper

    9.4.1.Settingandgettingbasicandnestedproperties9.4.2.BuiltinPropertyEditorimplementations

    RegisteringadditionalcustomPropertyEditors

    9.5.SpringTypeConversion9.5.1.ConverterSPI9.5.2.ConverterFactory

  • 08/01/2017 SpringFrameworkReferenceDocumentation

    http://docs.spring.io/spring/docs/current/springframeworkreference/htmlsingle/ 5/645

    9.5.3.GenericConverterConditionalGenericConverter

    9.5.4.ConversionServiceAPI9.5.5.ConfiguringaConversionService9.5.6.UsingaConversionServiceprogrammatically

    9.6.SpringFieldFormatting9.6.1.FormatterSPI9.6.2.AnnotationdrivenFormatting

    FormatAnnotationAPI9.6.3.FormatterRegistrySPI9.6.4.FormatterRegistrarSPI9.6.5.ConfiguringFormattinginSpringMVC

    9.7.Configuringaglobaldate&timeformat9.8.SpringValidation

    9.8.1.OverviewoftheJSR303BeanValidationAPI9.8.2.ConfiguringaBeanValidationProvider

    InjectingaValidatorConfiguringCustomConstraintsSpringdrivenMethodValidationAdditionalConfigurationOptions

    9.8.3.ConfiguringaDataBinder9.8.4.SpringMVC3Validation

    10.SpringExpressionLanguage(SpEL)10.1.Introduction10.2.FeatureOverview10.3.ExpressionEvaluationusingSpringsExpressionInterface

    10.3.1.TheEvaluationContextinterfaceTypeConversion

    10.3.2.Parserconfiguration10.3.3.SpELcompilation

    CompilerconfigurationCompilerlimitations

    10.4.Expressionsupportfordefiningbeandefinitions10.4.1.XMLba