@Bean public PlatformTransactionManager txManager() { return new HibernateTransactionManager(sessionFactory()); }
@Bean public SessionFactory sessionFactory() throws Exception { return new LocalSessionFactoryBuilder(dataSource()) .addAnnotatedClasses(Order.class, Account.class) .buildSessionFactory(); }
@Bean public DataSource dataSource() { // ... configure and return JDBC DataSource ... } } 3.1 Serv|et 3.0 8ased App||canon In|na||zer /** * Automatically detected and invoked on startup. * May register listeners, filters, servlets etc against the given * Servlet 3.0 ServletContext. */ public class MyWebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext sc) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
// Manages the lifecycle of the root application context sc.addListener(new ContextLoaderListener(root)); ... } } 3.1 Dec|aranve Cach|ng @Cacheable public Owner loadOwner(int id);
@Cacheable(condition="name.length < 10") public Owner loadOwner(String name);
@CacheEvict public void deleteOwner(int id); 3.1 S p r | n g
I r a m e w o r k
3 . 2
Cradle-based bulld 8lnarles bullL agalnsL !ava 7 lnllned ASM 4.0 and CCLl8 3.0 Larly !Cache (!S8-107) supporL Async MvC processlng on ServleL 3.0 Sprlng MvC LesL supporL MvC congurauon renemenLs SpLL renemenLs Also lncludlng many runume renemenLs - parually backporLed Lo 3.1.2/3.1.3 1he Iava SL 7 Story 3.2 Sprlng 3.1 came wlLh early supporL for !ava 7 - !u8C 4.1, lork!olnool, eLc - framework lLself sull complled on !ava 6 Sprlng 3.2 ls now belng bullL on !ava 7 - Cl bullds runnlng agalnsL !ava 3, 6 and 7 - enabled Lhrough new Cradle bulld Sprlng 3.2 comes wlLh ASM 4.0 and CCLl8 3.0 - fully supporung Lhe !ava 7 byLe code formaL - ASM and CCLl8 lnllned lnLo Sprlng module [ars now Lar|y ICache Support 3.2 Allgned wlLh Sprlng's cache absLracuon !CacheCacheManager !CacheManagerlacLory8ean 8ullL agalnsL !Cache 0.3 (!S8-107 dra) no ouL-of-Lhe-box supporL for nauve !Cache annoLauons yeL - planned for Sprlng 3.3, once !Cache ls nal Async MVC rocess|ng: Ca||ab|e @RequestMapping(method=RequestMethod.POST) public Callable<String> processUpload(MultipartFile file) { // ... return new Callable<String>() { public String call() throws Exception { // ... return "someView"; } }; } 3.2 Async MVC rocess|ng: Deferredkesu|t @RequestMapping("/quotes") @ResponseBody public DeferredResult quotes() { DeferredResult deferredResult = new DeferredResult(); // Add deferredResult to a Queue or a Map... return deferredResult; }
// In some other thread: // Set the return value on the DeferredResult deferredResult.set(data); 3.2 S p r | n g
I r a m e w o r k
3 . 3
Comprehenslve !ava 8 supporL SupporL for !ava LL 7 Al levels locus on message-orlenLed archlLecLures - annoLauon-drlven !MS endpolnL model - revlsed appllcauon evenL mechanlsm - WebSockeL supporL ln Sprlng MvC nexL-generauon Croovy supporL - Cralls bean bullder nally maklng lL lnLo Sprlng proper 1he Iava SL 8 Story 3.3 Comprehenslve !ava 8 supporL - lambda expresslons a.k.a. closures - uaLe and 1lme Al (!S8-310) - nlC-based P11 cllenL Als - parameLer name dlscovery - [ava.uul.concurrenL enhancemenLs 8eLalnlng supporL for !ava 3 and hlgher - wlLh !ava 6 and 7 as common levels - !ava 8 poLenually becomlng popular raLher qulckly... 1he Iava LL 7 Story 3.3 SupporL for !ava LL 7 Al levels - !Cache 1.0 - !MS 2.0 - !A2.1 - !1A 1.2 ([1ransacuonal) - 8ean valldauon 1.1 - ServleL 3.1 - !Sl 2.2 8eLalnlng supporL for !ava LL 3 and hlgher Annotanon-Dr|ven IMS Lndpo|nts @JmsListener(destination="myQueue") public void handleMessage(TextMessage payload);
@JmsListener(destination="myQueue", selector="...") public void handleMessage(String payload);
@JmsListener(destination="myQueue") public String handleMessage(String payload); 3.3 WebSocket Support 3.3 WebSockeL supporL ln currenL servers lsn'L fully sLandardlzed yeL !S8-336 upcomlng wlLhln Lhe !ava LL 7 umeframe !euy 9 Lo adopL lL raLher qulckly Sprlng lramework 3.3 Lo research all opuons for WebSockeL supporL - prlmarlly ln Sprlng MvC - buL also generally for message-orlenLed archlLecLures
2 Spr|ng Integranon & 8atch Introducnon S p r | n g
I n t e g r a n o n
Sprlng lnLegrauon ls mouvaLed by Lhe followlng goals: - rovlde a slmple model for lmplemenung complex enLerprlse lnLegrauon soluuons - laclllLaLe asynchronous, message- drlven behavlor wlLhln a Sprlng-based appllcauon - romoLe lnLuluve, lncremenLal adopuon for exlsung Sprlng users Integranon Sty|es Integranon 8uslness Lo 8uslness lnLegrauon (828) lnLer Appllcauon lnLegrauon (LAl) lnLra Appllcauon lnLegrauon llle 1ransfer Shared uaLabase 8emoung Messaglng Lnterpr|se Integranon auerns Integranon 8y Cregor Pohpe & 8obby Woolf (ubllshed 2003) Collecuon of well-known pauerns hup://www.ealpauerns.com/ ealpauerns.hLml lcon llbrary provlded Spr|ng Integranon Integranon Sprlng lnLegrauon provldes an exLenslon of Lhe Sprlng programmlng model Lo supporL Lhe well-known enLerprlse lnLegrauon pauerns. What |s Spr|ng Integranon? Integranon LlghL-welghL messaglng framework rovldes an adapLer-based plauorm |pes and I||ters aL Lhe core of Sprlng lnLegrauon's archlLecLure LndpolnL (lllLer) Channel (lpe) Message Conhguranon Integranon xML namespace SupporL AnnoLauon SupporL (e.g. [1ransformer, [8ouLer, [ServlceAcuvaLor) <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xsi:schemaLocation=".."> ...
345+!1 -#&#!1 !"#',*&1' F)G&#'(&) 9 345+!1 0.!: -'":;7#,!"% 0&+4'=E O O What |s |n a Message? Integranon unlL of lnformauon LncapsulaLes daLa assed beLween endpolnLs ConslsLs of headers - conLalns daLa relevanL Lo Lhe messaglng sysLem and a pay|oad - acLual daLa for Lhe recelver - dependlng on use-cases: C!C lnsLances or serlallzed daLa What |s |n a Message? Integranon package org.springframework.integration;
public interface Message<T> { MessageHeaders getHeaders(); T getPayload(); } Message neaders Integranon Message lu (auLomaucally generaLed uulu) 1lmesLamp Correlauon ld 8eply Channel Lrror Channel Lxplrauon uaLe rlorlLy ... Add your own headers uslng a Peader Lnrlcher Iuncnon of a Message Integranon Command Message LvenL Message uocumenL Message What |s a Channe|? Integranon Channels connecL producers and consumers (decoupllng) MessageChannel lnLerface: - ollableChannel (olllng Consumer) - SubscrlbableChannel (LvenL urlven) lmplemenLauons: - ulrecLChannel - ubllshSubscrlbeChannel - CueueChannel - rlorlLyChannel - 8endezvousChannel - LxecuLorChannel <int:channel id="input"> <int:queue capacity="10"/> </int:channel> What |s a Lndpo|nt? Integranon olllng or evenL-drlven lnbound or ouLbound unldlrecuonal (Channel AdapLer) or bldlrecuonal (CaLeway) lnLernal or exLernal (appllcauon conLexL) <inbound-channel-adapter/> <outbound-channel-adapter/> <inbound-gateway/> <outbound-gateway/> <gateway/> <service-activator/> kouter Integranon Message 8ouLer ConLenL-based rouLer 8eclplenL llsL rouLer (dynamlc) ayload Lype rouLer Peader value rouLer Lxcepuon Lype rouLe 1ransformer Integranon uelegaung vla ref/meLhod Sprlng Lxpresslon Language Croovy, !8uby, !yLhon, !avaScrlpL Cb[ecL-Lo-!SCn / !SCn-Lo-Cb[ecL ayload serlallzlng/deserlallzlng llle-Lo-byLes, llle-Lo-SLrlng !Ax8, !lbx, CasLor, xML8eans, xsLream xaLh, xSL1 Cb[ecL xML Marshalllng/unmarshalllng (Sprlng CxM) ... Adapters Integranon AMC/8abblLMC AWS* llle/8esource l1/l1S/Sl1 Cemllre P11 (8LS1) !u8C !MS !Mx !A Mongou8 C3/lMA/SM1 rlnL* 8edls 8Ml 8SS/ALom Web Servlces SM8* Splunk* * Sprlng lnLegrauon LxLenslons ro[ecL
Sprlng lnLegrauon Samples (Cafe) Demo... S p r | n g
8 a t c h
LlghLwelghL, comprehenslve baLch framework deslgned Lo enable Lhe developmenL of robusL baLch appllcauons vlLal for Lhe dally operauons of enLerprlse sysLems 8atch Iobs 8atch 8aLch [obs dler from onllne/real-ume processlng appllcauons: Long-runnlng - Cen ouLslde omce hours non-lnLeracuve - Cen lnclude loglc for handllng errors or resLarLs rocess large volumes of daLa - More Lhan Ls ln memory or a slngle Lransacuon Common 8atch Id|oms 8atch 8aLch [obs Lyplcally process large amounLs of homogeneous lnpuL Makes lLerauon a common concern: kepeat 1ranslenL errors durlng processlng may requlre a ketry of an lnpuL lLem Some lnpuL may noL be valld, may wanL Lo Sk|p lL wlLhouL falllng Some errors should fall Lhe [ob execuuon, allowlng one Lo x Lhe problem and kestart Lhe [ob lnsLance where lL le o Spr|ng 8atch 8atch Sprlng 8aLch supporLs Lhese common concerns AbsLracLs Lhem ln Lhe framework - !ob buslness loglc doesn'L need Lo care abouL deLalls Allows for slmple congurauon wlLh pluggable sLraLegles Iob and Step 8atch Chunk-Cr|ented rocess|ng 8atch lnpuL-ouLpuL can be grouped LogeLher lnpuL collecLs lLems before ouLpumng: Chunk- CrlenLed rocesslng IobLauncher 8atch Iob and Step |n Context 8atch Iobkepos|tory and 8atch metadata 8atch Spr|ng 8atch Adm|n 8atch Sub pro[ecL of Sprlng 8aLch rovldes Web ul and 8LS1ful lnLerface Lo manage baLch processes Manager, 8esources, Sample WA8 - ueployed wlLh baLch [ob(s) as slngle app Lo be able Lo conLrol & monlLor [obs - Cr monlLors exLernal [obs only vla shared daLabase Sca||ng and ara||e| rocess|ng 8atch llrsL 8ule: - use Lhe slmplesL Lechnlque Lo geL Lhe [ob done ln Lhe requlred ume - uo noL opumlze/parallellze unnecessarlly Cpuons: - Mulu-Lhreaded SLep (slngle process) - arallel SLeps (slngle process) - 8emoLe Chunklng of SLep (mulu process) - aruuonlng a SLep (slngle or mulu process) Launch|ng batch [obs through messages 8atch LvenL-urlven execuuon of Lhe !obLauncher Sprlng lnLegrauon reLrleves Lhe daLa (e.g. le sysLem, l1, ...) Lasy Lo supporL separaLe lnpuL sources slmulLaneously Lxterna||z|ng batch process execunon 8atch use Sprlng lnLegrauon lnslde of 8aLch [obs, e.g.: - lLemrocessor - lLemWrlLer CMoad complex processlng Asynchronous processlng supporL: - AsynclLemrocessor - AsynclLemWrlLer LxLernallze chunk processlng uslng ChunkMessageChannellLemWrlLer
3 Spr|ng Data New data access techno|og|es S p r | n g
D a t a
SupporLs new daLa access Lechnologles such as non-relauonal daLabases, map- reduce frameworks, and cloud based daLa servlces umbrella open source pro[ecL whlch conLalns many subpro[ecLs LhaL are speclc Lo a glven daLabase Data s|ze? Data ro||feranon of "So|unons" Data Subpro[ects Data Category Sub-pro[ects Desc. 8elauonal u8 !A Sprlng uaLa !A - Slmplles Lhe developmenL of creaung a !A-based daLa access layer !u8C LxLenslons SupporL for Cracle 8AC, Advanced Cueulng, and Advanced daLaLypes. SupporL for uslng CueryuSL wlLh !dbc1emplaLe 8lg uaLa Apache Padoop 1he Apache Padoop pro[ecL ls an open- source lmplemenLauon of frameworks for rellable, scalable, dlsLrlbuLed compuung and daLa sLorage Subpro[ects (cont.) Data Category Sub-pro[ects Desc. uaLa-grld Cemllre vMware vlabrlc Cemllre ls a dlsLrlbuLed daLa managemenL plauorm provldlng dynamlc scalablllLy, hlgh performance, and daLabase-llke perslsLence. lL blends advanced Lechnlques llke repllcauon, paruuonlng, daLa-aware rouung, and conunuous querylng P11 8LS1 Sprlng uaLa 8LS1 - erform C8uu operauons of your perslsLence model uslng P11 and Sprlng uaLa 8eposlLorles Subpro[ects (cont.) Data Category Sub-pro[ects Desc. key value SLores 8edls 8edls ls an open source, advanced key- value sLore uocumenL SLores Mongou8 Mongou8 ls a scalable, hlgh- performance, open source, documenL- orlenLed daLabase Craph uaLabases neo4[ neo4[ ls a graph daLabase, a fully Lransacuonal daLabase LhaL sLores daLa sLrucLured as graphs Column SLores P8ase Apache P8ase ls an open-source, dlsLrlbuLed, versloned, column- orlenLed sLore modeled aer Coogle' 8lgLable Spr|ng Data Data 1rad|nona| Arch|tecture Data SCL u8 ul ConLroller uomaln Cb[ecLs uaLa Access (PlbernaLe, !A, eLc.) 1rad|nona| Arch|tecture Data ul ConLroller uomaln Cb[ecLs uaLa Access (PlbernaLe, !A, eLc.) Comp|ex neterogeneous Arch|tecture Data ul ConLroller uomaln Cb[ecLs Cemllre Mongou8 neo4[ CLher Spr|ng Data neterogeneous Arch|tecture Data ul ConLroller uomaln Cb[ecLs Sprlng uaLa 8eposlLory !A kepos|tory Data !"#$%&"' )"&*""+ &," #-.%$+ %+# #%&% .%//$+0 1%2"3' 4'$+0 % 5-11"56-+71$8" $+&"39%5" 9-3 %55"''$+0 #-.%$+ -):"5&' hup://msdn.mlcroso.com/en-us/llbrary/649690.aspx
hup://marunfowler.com/eaaCaLalog/reposlLory.hLml
Spr|ng Data kepos|tor|es Data 345+!1 !"#',*&1' >,4:H'3.-!#.,)IJK 8L 'C#'":- 7',!&+!M&5+' 'C#'":- H'3.-!#.,)IJK 8LN 9