2부자료_introduction to core spring topics

Upload: valigher

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 2 _Introduction to Core Spring Topics

    1/81

    "#$%&'()* $&

    Core Spring Topics

  • 8/13/2019 2 _Introduction to Core Spring Topics

    2/81

    !"#$%#$&

    )*+,#-

    .+/0%1"+2

    )*+,#-

    4#$%-+/5"# 67/$89

    )*+,#- ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    3/81

    )*+,#- .+/0%1"+2

    )*+,#- .+/0%1"+2

  • 8/13/2019 2 _Introduction to Core Spring Topics

    4/81

    )*+,#- .+/0%1"+2 :>( +,-). /0112

    !?++%#$ /#= @*8"0,#-A3.14 3./ 5 3.3

    ! 6#78%-#$ :%&;?7?@A?=-' )B(%?* '-)

  • 8/13/2019 2 _Introduction to Core Spring Topics

    5/81

    )*+,#

    -.+/0%

    1"+2:>(

    6#78%-#$@A?=-' A-?# '-;#8* :%&;?7?@A?=-' ?::

  • 8/13/2019 2 _Introduction to Core Spring Topics

    6/81

    7%/# ;%B#,5"# C+"BD%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    7/81

    E/F/G7/&%= !"#B-?+/5"#

    @Configuration

    @EnableTransactionManagement(proxyTargetClass=true)public class DataConfig {

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

    }

    }

    :>(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    8/81

    )%+FD%$ :>H 7/&%= I**D,8/5"# 4#,5/D,J%+

    /**

    * 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 contextAnnotationConfigWebApplicationContext root =

    new AnnotationConfigWebApplicationContext();

    root.scan("com.mycompany.myapp");

    root.register(FurtherConfig.class);

    // Manages the lifecycle of the root application context

    sc.addListener(new ContextLoaderListener(root));

    ...

    }

    }

    :>(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    9/81

    ;%8D/+/5F% !/89,#-

    @Cacheable

    public Owner loadOwner(int id);

    @Cacheable(condition="name.length < 10")

    public Owner loadOwner(String name);

    @CacheEvict

    public void deleteOwner(int id);

    :>(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    10/81

    )*+,#

    -.+/0%

    1"+2:>3

    G%?'E\@10D2 =(::&%$ R=F#) JKL :%&)-==8#B E-%7

  • 8/13/2019 2 _Introduction to Core Spring Topics

    11/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    12/81

    K/+DM E!/89% )?**"+$ :>3

    RL?)C-?##&$?*= F-$

    - :

  • 8/13/2019 2 _Introduction to Core Spring Topics

    13/81

    I&M#8 NO! C+"8%&&,#-A !/DD/PD%

    @RequestMapping(method=RequestMethod.POST)

    public Callable processUpload(MultipartFile file) {

    // ...

    return new Callable() {

    public String call() throws Exception {

    // ...return "someView";

    }

    };

    }

    :>3

  • 8/13/2019 2 _Introduction to Core Spring Topics

    14/81

    I&M#8 NO! C+"8%&&,#-A ;%Q%++%=R%&?D$

    @RequestMapping("/quotes")

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

  • 8/13/2019 2 _Introduction to Core Spring Topics

    15/81

    )*+,#

    -.+/0%

    1"+2:>:

    L&9:%-C-#=87- >?7? O =(::&%$ E(::&%$ Q&% >?7? 66 D RS"

  • 8/13/2019 2 _Introduction to Core Spring Topics

    16/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    17/81

    SR/.1- >aR 1./ +da%?#=?)*?

  • 8/13/2019 2 _Introduction to Core Spring Topics

    18/81

    I##"$/5"#G;+,F%# EN) K#=*",#$&

    @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);

    :>:

  • 8/13/2019 2 _Introduction to Core Spring Topics

    19/81

    T%P)"82%$ )?**"+$ :>:

    T-AE&)U-$ =(::&%$ 8# )(%%-#$ =-%7-%= 8=#_$ Q(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    20/81

    )*+,#- 4#$%-+/5"# 6 7/$89

    4#$+"=?85"#

  • 8/13/2019 2 _Introduction to Core Spring Topics

    21/81

    )*+,#

    -4#$%-+/5"#

    E:%8#B "#$-B%?* 8= 9&*7?$-' AF $C-Q&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    22/81

    4#$%-+/5"# )$MD%& 4#$%-+/5"#

    Z(=8#-== $& Z(=8#-== "#$-B%?* +Z/Z2 "#$-% R::

  • 8/13/2019 2 _Introduction to Core Spring Topics

    23/81

    K#$%+*+,&% 4#$%-+/5"# C/U%+#& 4#$%-+/5"#

    ZF G%-B&% H&C:- 5 Z&AAFT&&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    24/81

    )*+,#- 4#$%-+/5"# 4#$%-+/5"#

    E:%8#B "#$-B%?* :%&78'-= ?# -P$-#=8

    &Q $C- E:%8#B :%&B%?998#B 9&'-

  • 8/13/2019 2 _Introduction to Core Spring Topics

    25/81

    T9/$ ,& )*+,#- 4#$%-+/5"#V 4#$%-+/5"#

    [8BC$@V-8BC$ 9-==?B8#B Q%?9-V&%U S%&78'-= ?# ?'?:$-%@A?=-' :

  • 8/13/2019 2 _Introduction to Core Spring Topics

    26/81

    !"#B-?+/5"# 4#$%-+/5"#

    kJ[ `?9-=:?)- E(::&%$ R##&$?* E(::&%$ +-.B. da%?#=Q&%9-%4 d\&($-%4dE-%78)-R)*7?$&%2

    ...

  • 8/13/2019 2 _Introduction to Core Spring Topics

    27/81

    )*+,#- 4#$%-+/5"# ;)W& 4#$%-+/5"#

    E)?

  • 8/13/2019 2 _Introduction to Core Spring Topics

    28/81

    E/F/ %X/0*D% @ P9< 4#$%-+/5"#

    !!"#$%'(&)#$%&'($)'*+$%,-($./,0012-%1345-+$6-4/

    7$,-89+)%$:8$#+)(;-**$9./'*

    !!"#$*!+#','*?8+)(;-**$9./'*

  • 8/13/2019 2 _Introduction to Core Spring Topics

    29/81

    E/F/ %X/0*D% @ X?7? 4#$%-+/5"#

    345+!11+&--73,!"%8"#'%,!."8"#,. 9

    345+!1-#!10.!:/&!";7#,!"%

  • 8/13/2019 2 _Introduction to Core Spring Topics

    30/81

    T9/$ ,& ,# / N%&&/-%V 4#$%-+/5"#

    l#8$ &Q 8#Q&%9?* 6#)?:=(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    31/81

    T9/$ ,& ,# / N%&&/-%V 4#$%-+/5"#

    package org.springframework.integration;

    public interface Message {

    MessageHeaders getHeaders();

    T getPayload();

    }

  • 8/13/2019 2 _Introduction to Core Spring Topics

    32/81

    N%&&/-% Y%/=%+& 4#$%-+/5"#

    J-==?B- ", +?($&9?*)?

  • 8/13/2019 2 _Introduction to Core Spring Topics

    33/81

    .?#85"# "Q / N%&&/-% 4#$%-+/5"#

    L&99?#' J-==?B- 67-#$ J-==?B- ,&)(9-#$ J-==?B-

  • 8/13/2019 2 _Introduction to Core Spring Topics

    34/81

    T9/$ ,& / !9/##%DV 4#$%-+/5"#

    LC?##-

  • 8/13/2019 2 _Introduction to Core Spring Topics

    35/81

    T9/$ ,& / K#=*",#$V 4#$%-+/5"#

    S&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    36/81

    R"?$%+ 4#$%-+/5"#

    J-==?B- \&($-% L$-#$@A?=-' %&($-% \-)8:8-#$

  • 8/13/2019 2 _Introduction to Core Spring Topics

    37/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    38/81

    I=/*$%+& 4#$%-+/5"#

    RJMSW\?AA8$JM RTEm I8,ZL >JE >Jk >SR

    JB&,Z SbS3W"JRSWEJaS S%8#$m

    \-'8= \J" \EEWR$&9 T-A E-%78)-= EJZm E:

  • 8/13/2019 2 _Introduction to Core Spring Topics

    39/81

    E:%8#B "#$-B%?* E?9:

  • 8/13/2019 2 _Introduction to Core Spring Topics

    40/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    41/81

    )*+,#-7/$89

    [8BC$V-8BC$4 )&9:%-C-#=87- A?$)CQ%?9-V&%U '-=8B#-' $& -#?A

  • 8/13/2019 2 _Introduction to Core Spring Topics

    42/81

    7/$89 E"P& 7/$89

    Z?$)C X&A= '8n-% Q%&9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    43/81

    !"00"# 7/$89 4=,"0& 7/$89

    Z?$)C X&A= $F:8)?

  • 8/13/2019 2 _Introduction to Core Spring Topics

    44/81

    )*+,#- 7/$89 7/$89

    E:%8#B Z?$)C =(::&%$= $C-=- )&99 ))-%#= RA=$%?)$= $C-9 8# $C- Q%?9-V&%U- >&A A(=8#-==

  • 8/13/2019 2 _Introduction to Core Spring Topics

    45/81

    E"P /#= )$%* 7/$89

    9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    46/81

    !9?#2G[+,%#$%= C+"8%&&,#- 7/$89

    "#:($@&($:($ )?# A- B%&(:-' $&B-$C-% "#:($ )&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    47/81

    E"PW/?#89%+ 7/$89

    7 9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    48/81

    E"P /#= )$%* ,# !"#$%X$ 7/$89

    7 $ 9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    49/81

    E"PR%*"&,$"+M /#= 7/$89 0%$/=/$/ 7/$89

    9 = 7 $ 9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    50/81

    )*+,#- 7/$89 I=0,# 7/$89

    E(A :%&X-)$ &Q E:%8#B Z?$)C S%&78'-= T-A l" ?#' \6EaQ(< 8#$-%Q?)- $&9?#?B- A?$)C :%&)-==-=

    J?#?B-%4 \-=&(%)-=4 E?9:

  • 8/13/2019 2 _Introduction to Core Spring Topics

    51/81

    )8/D,#- /#= C/+/DD%D C+"8%&&,#- 7/$89

    I8%=$ \(

  • 8/13/2019 2 _Introduction to Core Spring Topics

    52/81

    W/?#89,#- P/$89 \"P& $9+"?-9 0%&&/-%& 7/$89

    67-#$@,%87-# -P-)(* &Q $C- >&A[?(#)C-% E:%8#B "#$-B%?* %-$%8-7-= $C- '?$? +-.B. ;

  • 8/13/2019 2 _Introduction to Core Spring Topics

    53/81

    KX$%+#/D,J,#- P/$89 *+"8%&& %X%8?5"# 7/$89

    l=- E:%8#B "#$-B%?* 8#=8'- &Q Z?$)C X&A=4 -.B.h- "$-9S%&)-==&%- "$-9T%8$-%

    bq&?' )&9:

  • 8/13/2019 2 _Introduction to Core Spring Topics

    54/81

    )*+,#- ;/$/

    ]%1 =/$/ /88%&& $%89#"D"-,%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    55/81

    )*+,#-;/$/

    E(::&%$= #-V '?$? ?))-== $-)C#&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    56/81

    ;/$/ &,J%V ;/$/

    C D,Q 5 Q ^) D 5 _ ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    57/81

    C+"D,Q%+/5"# "Q ^)"D?5"#&_ ;/$/

    ) P \ $ ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    58/81

    )?P*+"\%8$& ;/$/

    !/$%-"+M )?PG*+"\%8$& ;%&8>\-

  • 8/13/2019 2 _Introduction to Core Spring Topics

    59/81

    )?P*+"\%8$& `8"#$>a ;/$/

    !/$%-"+M )?PG*+"\%8$& ;%&8>,?$?@B%8' G-9I8%- KJV?%- 7I?A%8) G-9I8%- 8= ?

    '8=$%8A($-' '?$? 9?#?B-9-#$ :

  • 8/13/2019 2 _Introduction to Core Spring Topics

    60/81

    )?P*+"\%8$& `8"#$>a ;/$/

    !/$%-"+M )?PG*+"\%8$& ;%&8>r-F K?

  • 8/13/2019 2 _Introduction to Core Spring Topics

    61/81

    )*+,#- ;/$/ ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    62/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    63/81

  • 8/13/2019 2 _Introduction to Core Spring Topics

    64/81

    !"0*D%X Y%$%+"-%#%"?& I+89,$%8$?+% ;/$/

    l"

    L$%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    65/81

    )*+,#- ;/$/ Y%$%+"-%#%"?& I+89,$%8$?+% ;/$/

    l"

    L$%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    66/81

    R%*"&,$"+M ;/$/

    !"#$%&"' )"&*""+ &," #-.%$+ %+# #%&% .%//$+01%2"3' 4'$+0 % 5-11"56-+71$8"$+&"39%5" 9-3

    %55"''$+0 #-.%$+ -):"5&'

    Cf:hWW9='#.98)%&=&Y.)&9W-#@(=W

  • 8/13/2019 2 _Introduction to Core Spring Topics

    67/81

    )*+,#- ;/$/ R%*"&,$"+,%& ;/$/

    345+!1 !"#',*&1' >,4:H'3.-!#.,)IJK 8L 'C#'":- 7',!&+!M&5+'

    'C#'":- H'3.-!#.,)IJK 8LN 9

    J -&0';J '"#!#)=E

    8#',&5+'IJN -&0';8#',&5+'IO 'C#'":- JN '"#!#!'-=E

    J *!":P"';8L !:=E5..+'&" 'C!-#-;8L !:=E

    8#',&5+'IJN *!":B++;=E

    +."% 1.4"#;=E

    0.!: :'+'#';8L !:=E

    0.!: :'+'#';J '"#!#)=E

    0.!: :'+'#';8#',&5+'IO 'C#'":- JN '"#!#!'-=E

    0.!: :'+'#'B++;=E

    O

    b?%+M N%$9"=& ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    68/81

    b?%+M N%$9"=& ;/$/

    E$?%$=T8$C4 6#'=T8$C4 L$?8#=4 RY-%4 Z-Q&%-

    )*+,#- ;/$/ c%0.,+% @ \-:&=8$&%8-= ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    69/81

    )*+,#- ;/$/ c%0.,+%@ \-:&=8$&%8-= ;/$/

    345+!1!"#',*&1'>."#&1#H'3.-!#.,)

    'C#'":-G'/*!,'H'3.-!#.,)I>."#&1#K Q."%N9P'#+! ,'*7M4Q'%#+*-E$AK+%'*F ,'%#+*-E$DN

    P'#+! ,'*7M4P-#+*-E$K+-%+#C'+;AK+%'*F 9-#+*-E$DN

    O

    !R@E9 &$%#'0*.!"#$! &'()*+',-!./012!34

    !2$-*#S2$-*# T

    @E9*#.!5667899:::#;7

  • 8/13/2019 2 _Introduction to Core Spring Topics

    70/81

    ;"0/,# N/**,#-

    l"

    L$%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    71/81

    )*+,#- ;/$/ c%0.,+% 6#*$F J?::8#B

    VW$F'0*

    345+!11+&-->."#&1# !/3+'/'"#-7',!&+!M&5+' 93,!0'-#!1*!"&++."%!"#$%&'"#!$()*+,. /01

    VX7

    3,!0'Q."% !:E

    3,!0'7#,!"% *!,-#"&/'E

    3,!0'7#,!"% +&-#"&/'E

    3,!0'7'#I?@."'N 3@."'-R "'(S&-@7'#I?@."'N;=E

    3,!0'7'#IT/&!+B::,'--N '/&!+B::,'--R

    "'(S&-@7'#IT/&!+B::,'--N;=E

    O

    ;"0/,# N/**,#- ;/$/

  • 8/13/2019 2 _Introduction to Core Spring Topics

    72/81

    ;"0/,# N/**,#-

    l"

    L$%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    73/81

    )*+,#- ;/$/ c%0.,+% \-:&=8$&%F l=?B-

    !F,$)7-+-S%$?0#'+0%'$#

    2-#$)?-(U-F$.!)4-#./',K Q."%N 9

    K$+! ,'*7L99ADNP'#+! ,'*7M4P-#+*-E$AK+%'*F 9-#+*-E$DN

  • 8/13/2019 2 _Introduction to Core Spring Topics

    74/81

    )*+,#- ;/$/ c%0.,+% \-:&=8$&%F l=?B-

    345+!11+&-->4-#./',7',0!1' 9

    3,!0'-#!1Q.% &(2.0(23%45(#672"50(289:!5(;"#1

    VL8+06'%$7

    4-#./', 1,''>4-#./',;>4-#./', 14-#./',= 9

  • 8/13/2019 2 _Introduction to Core Spring Topics

    75/81

    )*+,#- ;/$/ c%0.,+% \-:&=8$&%F l=?B-

    111

    345+!15..+'&":'+'#'>4-#./',;+."%!:= 9

    4-#./',N *!":>4-#./',-V)Q&-#"&/';7#,!"% +&-#"&/'= 9

    ,'#4,"14-#./',H'3.-!#.,)

  • 8/13/2019 2 _Introduction to Core Spring Topics

    76/81

    @&% [bW Q"+ d?%+M

    345+!1!"#',*&1'?,.:41#H'3.-!#.,)

    'C#'":->,4:H'3.-!#.,)I?,.:41#K Q."%N 9V[8$%4A/KYPY ,'*7M4L++%'28+$#AK+%'*F U$4c K+%'*F &-98$DN

    O

    VW$F'0*

    345+!11+&--?,.:41# 'C#'":-B5-#,&1#?',-!-#'"#T"#!#) 9

    3,!0'7#,!"% "&/'K :'-1,!3#!."E

    3,!0'V!%L'1!/&+ 3,!1'E

    3,!0'F&3I7#,!"%K 7#,!"%N #,!54#'-R

    "'(S&-@F&3I7#,!"%K 7#,!"%N;=E

    O

    ;%F%D"*0%#$

  • 8/13/2019 2 _Introduction to Core Spring Topics

    77/81

    ;%F%D"*0%#$

  • 8/13/2019 2 _Introduction to Core Spring Topics

    78/81

    4;K 4#$%-+/5"# 6)

  • 8/13/2019 2 _Introduction to Core Spring Topics

    79/81

    E:%8#B ,?$? G-9I8%-

    ;%0"Z>>

    R%Q%+%#8%&

  • 8/13/2019 2 _Introduction to Core Spring Topics

    80/81

    )*+,#- .+/0%1"+2 :>3 /#= :>: @ >(-%B-# H&-

  • 8/13/2019 2 _Introduction to Core Spring Topics

    81/81

    4#$+"=?85"# $" !"+% )*+,#-