Spring for Spring Boot #jsug

Spring for Spring Boot #jsug

JSUG勉強会「Spring for Spring Boot -Spring Bootユーザーが知るべきSpringの基礎知識-」の資料です。(2017年2月実施) https://jsug.doorkeeper.jp/events/57470 #jsug

5dbaf4015e7f249ab21b195ced8e9e46?s=128

Masatoshi Tada

February 27, 2017
Tweet

Transcript

  1. 2.

    (C) CASAREAL, Inc. All rights reserved. #jsug ͜ͷηογϣϯʹ͍ͭͯ ▸ 4QSJOH#PPU͔Β࢝Ίͨਓʹ஌ͬͯ΄͍͠


    4QSJOHͷجૅ஌ࣝΛղઆ͠·͢ ▸ !#FBOͬͯԿʂʁ ▸ !&OBCMF9YYͬͯԿΛͯ͠Δͷʂʁ ▸ ʮઃఆΛࣗಈԽʯͬͯԿʂʁ ▸ ΧελϚΠζ͍͚ͨ͠Ͳ্ख͍͔͘ͳ͍ɾɾɾ 2
  2. 3.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 3
  3. 4.

    (C) CASAREAL, Inc. All rights reserved. #jsug ࣗݾ঺հ ▸ ଟాਅහʢ!TVLF@NBTBʣ

    ▸ ݚमτϨʔφʔ!ΧαϨΞϧ ▸ 1JWPUBMೝఆߨࢣ ▸ ઐ໳ɿ4QSJOH+BWB&& ▸ ++6(΍(MBTT'JTIϢʔβʔάϧʔϓ
 ʹΑ͘ग़຅ͯ͠·͢ 4
  4. 5.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 5
  5. 6.

    (C) CASAREAL, Inc. All rights reserved. #jsug ࠷ॳʹΫΠζ ▸ ͜Ε͔ΒσϞ͢ΔΞϓϦͰɺ


    4QSJOH#PPUݻ༗ͷػೳΛ࢖͍ͬͯΔΫϥε͸ɺ
 Կݸ͋ΔͰ͠ΐ͏͔ʁʢશ෦Ͱݸʣ " ݸ # ʙݸ $ ʙݸ % ݸશͯ 6 ιʔείʔυ https://github.com/MasatoshiTada/spring-for-spring-boot/tree/master/02-spring-boot
  6. 9.
  7. 12.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 12
  8. 13.

    (C) CASAREAL, Inc. All rights reserved. #jsug #FBOͱ͸ʁ ▸ 4QSJOHͷ%*ίϯςφͰ


    ؅ཧ͞Ε͍ͯΔ
 Πϯελϯεͷ͜ͱ ▸ ඞཁʹԠͯ͡
 औΓग़͠Մೳ 13 DIίϯςφ Bean Bean Bean Bean Bean Bean औಘ
  9. 14.

    (C) CASAREAL, Inc. All rights reserved. #jsug #FBOΛఆٛ͢Δ ▸ ʮ͜ͷΫϥεͷΠϯελϯεΛ#FBOͱͯ͠Ͷʂʯ

    ͱ%*ίϯςφʹڭ͑Δ͜ͱ ▸ ఆٛํ๏͸ͭ ᶃΞϊςʔγϣϯʴίϯϙʔωϯτεΩϟϯ ᶄϝιουʹΑΔ#FBOఆٛ ᶅ9.-ઃఆϑΝΠϧ ࠓճ͸ׂѪ 14
  10. 15.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃΞϊςʔγϣϯʴίϯϙʔωϯτεΩϟϯ ▸ ΠϯελϯεΛ#FBOʹ͍ͨ͠Ϋϥεʹ


    !$PNQPOFOUΛ෇Ճ 15 package hoge.service.impl; @Component public class FooServiceImpl implements FooService { // লུ } ※ΠϯλϑΣʔε(্هͷ৔߹͸FooService)͸ඞਢͰ͸ͳ͍
  11. 16.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃΞϊςʔγϣϯʴίϯϙʔωϯτεΩϟϯ ▸ +BWB$POpHΫϥεʹ!$POpHVSBUJPOͱ


    !$PNQPOFOU4DBOΛ෇Ճ 16 package hoge.config; @Configuration @ComponentScan(basePackages = { “hoge.service.impl”}) public class AppConfig { // ۭͰOK }
  12. 17.

    (C) CASAREAL, Inc. All rights reserved. #jsug ίϯϙʔωϯτεΩϟϯͱ͸ʁ ▸ CBTF1BDLBHFTଐ

    ੑʹࢦఆͨ͠ύο έʔδ഑Լʢαϒύο έʔδؚΉʣ͔Βɺ !$PNQPOFOU͕෇ Ճ͞ΕͨΫϥεΛ୳ ͢͜ͱ 17 hoge config service impl bar App Config FooService Impl Bar FooService εΩϟϯ
 ൣғ
  13. 18.

    (C) CASAREAL, Inc. All rights reserved. #jsug !$PNQPOFOU4DBOʹ·ͭΘΔΤτητϥ ▸ CBTF1BDLBHF$MBTTFT9YYDMBTTͱ͢Δͱɺ


    ʮ9YYΫϥε͕ଐ͢Δύοέʔδʯ͕εΩϟϯର ৅ʹͳΔ ▸ CBTF1BDLBHFTଐੑ΋CBTF1BDLBHF$MBTTFTଐ ੑ΋ࢦఆ͠ͳ͔ͬͨ৔߹ɺ
 ʮ͜ͷ!$PNQPOFOU4DBO͕෇Ճ͞Ε͍ͯΔΫ ϥε͕ଐ͢Δύοέʔδʯ͕εΩϟϯର৅ʹͳΔ 18
  14. 19.

    (C) CASAREAL, Inc. All rights reserved. #jsug %*ίϯςφͷॳظԽ ▸ "OOPUBUJPO$POpH"QQMJDBUJPO$POUFYUͷ


    ίϯετϥΫλҾ਺ʹ+BWB$POpHΛࢦఆ͢Δ ▸ "QQMJDBUJPO$POUFYU%*ίϯςφ 19 // DIίϯςφͷੜ੒ɺίϯϙʔωϯτεΩϟϯɺ // BeanͷΠϯελϯεੜ੒ɺDIίϯςφ΁ͷอଘ͕ߦΘΕΔ ApplicationContext context = new AnnotationConfigApplicationContext( AppConfig.class); ※ίϯετϥΫλͷҾ਺͸Մม௕ͳͷͰɺෳ਺ͷJava ConfigΛࢦఆՄೳ
  15. 20.

    (C) CASAREAL, Inc. All rights reserved. #jsug #FBOͷऔಘํ๏ ▸ ํ๏͸ͭ

    20 ApplicationContext context = …; FooService fs = context.getBean(FooService.class); @Component // ͜ͷΫϥε΋BeanͰ͋Δ͜ͱ͕ඞਢ public class FooController { private final FooService fs; @Autowired // Spring 4.3Ҏ߱Ͱ͸@Autowired͸লུՄೳ public FooController(FooService fs) { this.fs = fs; } } DIίϯςφ FooServiceImpl ͷBean औಘ Spring͸ɺҾ਺ͷܕͰ
 ୅ೖ͢΂͖BeanΛ
 ൑அ͢Δ
  16. 21.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶄϝιουʹΑΔ#FBOఆٛ ▸ +BWB$POpH಺ʹ!#FBOΛ෇Ճͨ͠ϝιουΛ

    ࡞੒ˠ໭Γ஋͕#FBOͱͳΔ 21 @Configuration // @ComponentScan͸ෆཁ public class AppConfig2 { @Bean public BarService barService() { // ͜ͷ໭Γ஋͕BeanʹͳΔ return new BarServiceImpl(); } }
  17. 22.

    (C) CASAREAL, Inc. All rights reserved. #jsug ଞͷ#FBOΛར༻ͨ͠#FBOఆٛ ▸ !#FBOΛ෇Ճͨ͠ϝιουͷҾ਺Ͱɺଞͷ#FBOΛड͚औΕΔ

    ▸ !$PNQPOFOUͰఆٛͨ͠΋ͷͰ΋ɺଞͷ!#FBOͳϝιουͰఆٛ ͨ͠΋ͷͰ΋0, 22 @Configuration public class AppConfig3 { @Bean public BarService barService( BarRepository br) { return new BarServiceImpl(br); } } Spring͸ɺҾ਺ͷܕͰ
 ୅ೖ͢΂͖BeanΛ
 ൑அ͢Δ
  18. 23.

    (C) CASAREAL, Inc. All rights reserved. #jsug %*ίϯςφͷॳظԽɺ#FBOͷऔಘํ๏ ▸ !$PNQPOFOUͷ৔߹ͱશ͘ಉ͡

    23 ApplicationContext context = new AnnotationConfigApplicationContext( AppConfig2.class); BarService bs = context.getBean(BarService.class); @Component public class BarController { private final BarService bs; @Autowired // লུՄೳ public BarController(BarService bs) { this.bs = bs; } }
  19. 24.

    (C) CASAREAL, Inc. All rights reserved. #jsug ίϯϙʔωϯτεΩϟϯͱϝιουͰͷఆٛͷซ༻ ▸ !#FBOΛ෇Ճͨ͠ϝιουͷ໭Γ஋ɺ


    CBTF1BDLBHFT഑Լͷ!$PNQPOFOUͳΫϥεɺ
 ͷશ͕ͯ#FBOͱͳΔ 24 @Configuration @ComponentScan(basePackages = “hoge.service.impl”) public class AppConfig4 { @Bean public BarService barService() { return new BarServiceImpl(); } }
  20. 25.

    (C) CASAREAL, Inc. All rights reserved. #jsug +BWB$POpHͷ߹ମ ▸ !*NQPSUͰ+BWB$POpHΛ߹ମͰ͖Δ

    25 @Import(ConfigB.class) // ෳ਺ࢦఆՄೳ @Configuration public class ConfigA { /* লུ */} @Configuration public class ConfigB { /* লུ */} ApplicationContext context = new AnnotationConfigApplicationContext( ConfigA.class); // ྆ํͰఆٛͨ͠Bean͕ར༻Ͱ͖Δ ※ConfigA΍ConfigBʹ͸ɺ@ComponentScan͕෇͍͍ͯͯ΋OK
  21. 26.

    (C) CASAREAL, Inc. All rights reserved. #jsug ຊষͷ·ͱΊ ▸ 4QSJOHͷઃఆ㲈#FBOఆٛʂ

    ▸ !$PNQPOFOU͕෇͍ͨΫϥεΛɺ!$PNQPOFOU4DBOͰࢦఆͨ͠ύο έʔδ͔Β୳͠ग़ͯ͠#FBOఆٛ͢Δ ▸ !#FBOͳϝιουͷ໭Γ஋͕#FBOͱͳΔ ▸ ϝιουҾ਺Ͱଞͷ#FBOΛऔಘͰ͖Δ ▸ "QQMJDBUJPO$POUFYUHFU#FBO Ͱ#FBOΛऔಘ ▸ ίϯετϥΫλʹ!"VUPXJSFEͰ#FBOΛऔಘ ▸ !*NQPSUͰෳ਺ͷ+BWB$POpHΛ߹ମͰ͖Δ 26
  22. 27.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 27
  23. 28.

    (C) CASAREAL, Inc. All rights reserved. #jsug αϯϓϧΞϓϦͷٕज़ߏ੒ ▸ 4QSJOH.7$

    ▸ 5IZNFMFBG ▸ 4QSJOH%BUB+1" ▸ )%BUBCBTF 28 ιʔείʔυ https://github.com/MasatoshiTada/spring-for-spring-boot/tree/master/01-spring
  24. 29.

    (C) CASAREAL, Inc. All rights reserved. #jsug 4QSJOH.7$ΞʔΩςΫνϟʢͬ͘͟Γʣ 29 Dispatcher

    Servlet ίϯτ
 ϩʔϥʔ View Resolver ᶃϦΫΤετ ᶄॲཧͷৼΓ෼͚ ᶅϏϡʔͷ࿦ཧ໊ ᶆϏϡʔͷ࿦ཧ໊ ᶇϏϡʔͷ෺ཧ໊ ᶈϨεϙϯε ※ΞʔΩςΫνϟͷશମ૾͸
 ɹʮSpringೖ໳ʯʮSpringపఈೖ໳ʯΛ
 ɹಡΜͰ͍ͩ͘͞
  25. 30.

    (C) CASAREAL, Inc. All rights reserved. #jsug 7JFX3FTPMWFSΠϯλϑΣʔε ▸ Ϗϡʔͷ࿦ཧ໊͔ΒϏϡʔͷ෺ཧ໊Λղܾ͢Δ

    ▸ ྫɿzFNQMPZFFJOEFYz
 ˠz8&#*/'UFNQMBUFTFNQMPZFFJOEFYIUNMz ▸ ֤Ϗϡʔٕज़༻ͷ7JFX3FTPMWFS࣮૷Ϋϥε͕͋Δ ▸ 5IZNFMFBG7JFX3FTFPMWFSΫϥε 5IZNFMFBG  ▸ 'SFF.BSLFS7JFX3FTPMWFSΫϥε 'SFF.BSLFS  ▸ *OUFSOBM3FTPVSDF7JFX3FTPMWFSΫϥε +41 30
  26. 31.

    (C) CASAREAL, Inc. All rights reserved. #jsug 7JFX3FTPMWFSΛ#FBOఆٛ͠Α͏ ▸ #FBOͱͯ͠ఆٛ͢Ε͹ɺ4QSJOH.7$͕಺෦Ͱ

    ͦͷ7JFX3FTPMWFSΛ࢖ͬͯ͘ΕΔ 31 https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/ springframework/web/servlet/DispatcherServlet.java#L719
  27. 32.

    (C) CASAREAL, Inc. All rights reserved. #jsug 5IZNFMFBGͰͷ7JFX3FTPMWFSͷ#FBOఆٛ 32 Thymeleaf

    View Resolver Spring Template Engine Spring Resource Template Resolver ࢀর ࢀর @Bean @Bean @Bean
  28. 33.

    (C) CASAREAL, Inc. All rights reserved. #jsug 5IZNFMFBGͰͷ7JFX3FTPMWFSͷ#FBOఆٛ 33 @Configuration

    public class MvcConfig … { @Bean public SpringResourceTemplateResolver templateResolver() { SpringResourceTemplateResolver srtr = new SpringResourceTemplateResolver(); // ϏϡʔΛอଘ͢ΔϑΥϧμͷࢦఆ srtr.setPrefix("/WEB-INF/templates/"); // ֦ுࢠͷࢦఆ srtr.setSuffix(".html"); // Thymeleaf͕HTMLͱͯ͠ςϯϓϨʔτΛղऍ srtr.setTemplateMode(TemplateMode.HTML); return srtr; }
  29. 34.

    (C) CASAREAL, Inc. All rights reserved. #jsug 5IZNFMFBGͰͷ7JFX3FTPMWFSͷ#FBOఆٛ 34 @Bean

    public SpringTemplateEngine templateEngine( SpringResourceTemplateResolver srtr) { SpringTemplateEngine ste = new SpringTemplateEngine(); // SpringResourceTemplateResolverͷηοτ ste.setTemplateResolver(srtr); // SpELίϯύΠϥΛ༗ޮԽͯ͠ߴ଎Խ ste.setEnableSpringELCompiler(true); // ThymeleafͰDate and Time APIΛղऍͰ͖Δػೳͷ௥Ճ ste.addDialect(new Java8TimeDialect()); return ste; }
  30. 35.

    (C) CASAREAL, Inc. All rights reserved. #jsug 5IZNFMFBGͰͷ7JFX3FTPMWFSͷ#FBOఆٛ 35 @Bean

    public ThymeleafViewResolver viewResolver( SpringTemplateEngine ste) { ThymeleafViewResolver tvr = new ThymeleafViewResolver(); // SpringTemplateEngineͷηοτ tvr.setTemplateEngine(ste); // Ϩεϙϯε͢ΔHTMLͷจࣈίʔυࢦఆ tvr.setCharacterEncoding( StandardCharsets.UTF_8.name()); return tvr; }
  31. 36.

    (C) CASAREAL, Inc. All rights reserved. #jsug ϝοηʔδʹඞཁͳ#FBO ▸ 3FTPVSDF#VOEMF.FTTBHF4PVSDFΫϥεΛ


    #FBOఆٛ͢Δ ▸ ࠓճ͸TSDNBJOSFTPVSDFTNFTTBHFTQSPQFSUJFTΛ࢖͏ 36 @Bean public MessageSource messageSource() { ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); messageSource.setBasename("messages"); return messageSource; }
  32. 37.

    (C) CASAREAL, Inc. All rights reserved. #jsug ͦͷଞʹ΋ඞཁͳ#FBO͕͍ͬͺ͍ʂ ▸ 4QSJOH.7$͕ಈ࡞͢Δʹ͸ɺ7JFX3FTPMWFSҎ֎

    ʹ΋ଟ͘ͷ#FBO͕ඞཁ ▸ όϦσʔλʔ ▸ 63-ͱϋϯυϥʔʢίϯτϩʔϥʔϝιουʣΛରԠͮ ͚Δ ▸ ܕม׵ ▸ ଞʹ΋৭ʑɾɾɾ 37
  33. 38.

    (C) CASAREAL, Inc. All rights reserved. #jsug ͦͷଞʹ΋ඞཁͳ#FBO͕͍ͬͺ͍ʂ ▸ 4QSJOH.7$͕ಈ࡞͢Δʹ͸ɺ7JFX3FTPMWFSҎ֎

    ʹ΋ଟ͘ͷ#FBO͕ඞཁ ▸ όϦσʔλʔ ▸ 63-ͱϋϯυϥʔʢίϯτϩʔϥʔϝιουʣΛରԠͮ ͚Δ ▸ ܕม׵ ▸ ଞʹ΋৭ʑɾɾɾ 38 @EnableWebMvc
  34. 39.

    (C) CASAREAL, Inc. All rights reserved. #jsug !&OBCMF8FC.WD ▸ ਖ਼ମ͸!*NQPSU

    ▸ ͋Β͔͡Ί༻ҙ͞Ε͍ͯΔ+BWB$POpHΛΠϯϙʔτ͢Δ ▸ 4QSJOH#PPU4QSJOH$MPVEͰΑ͘࢖͏!&OBCMF9YY΋جຊత ʹ͸ಉ͡ 39 https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/ springframework/web/servlet/config/annotation/EnableWebMvc.java#L103
  35. 40.

    (C) CASAREAL, Inc. All rights reserved. #jsug 8FC.WD$POpHVSBUJPO4VQQPSUΫϥε ▸ %FMFHBUJOH8FC.WD$POpHVSBUJPO

    લग़ ͷ
 εʔύʔΫϥε ▸ όϦσʔλʔͳͲଟ਺ͷ#FBO͕ఆٛ͞Ε͍ͯΔ ▸ !&OBCMF8FC.WDΛ+BWB$POpHʹ෇Ճ͢Δͱɺ
 ͜ΕΒͷ#FBO͕ར༻ՄೳʹͳΔ 40 https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/ springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java
  36. 41.

    (C) CASAREAL, Inc. All rights reserved. #jsug ੩తϑΝΠϧͷѻ͍ ▸ %JTQBUDIFS4FSWMFU͕શϦΫΤετΛड͚औΔͷ

    ͰɺσϑΥϧτͰ͸$44+4ը૾ͳͲ੩తϑΝ Πϧ΁ͷϧʔςΟϯά͕͞Εͳ͍ ▸ 8FC.WD$POpHVSFSΛར༻ͯ͠ϧʔςΟϯά ઃఆΛ௥Ճ 41
  37. 42.

    (C) CASAREAL, Inc. All rights reserved. #jsug 8FC.WD$POpHVSFS"EBQUFSΫϥε ▸ 8FC.WD$POpHVSFSΠϯλϑΣʔεͷ࣮૷Ϋϥ

    ε ▸ ࣮૷ϝιου͸શ෦ۭͷΞμϓλʔΫϥε ▸ ͜ͷΫϥεΛܧঝͯ͠+BWB$POpHΛ࡞੒͠ɺ
 ඞཁͳϝιουͷΈΦʔόʔϥΠυ͢Δ 42
  38. 43.

    (C) CASAREAL, Inc. All rights reserved. #jsug ੩తϑΝΠϧΛར༻͢Δઃఆ 43 @EnableWebMvc

    @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers( ResourceHandlerRegistry registry) { // /resources/**΁ͷϦΫΤετΛ registry.addResourceHandler("/resources/**") // /resources/ʹϧʔςΟϯά͢Δ .addResourceLocations("/resources/"); }
  39. 44.

    (C) CASAREAL, Inc. All rights reserved. #jsug <ࢀߟ>͜ΕͰ΋0, 44 @EnableWebMvc

    @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { configurer.enable();
 }
  40. 45.

    (C) CASAREAL, Inc. All rights reserved. #jsug <ࢀߟ>+BWB$POpHͱผΫϥεʹͯ͠΋0, 45 //

    ίϯϙʔωϯτεΩϟϯର৅ͷύοέʔδʹஔ͘ @Component public class MyConfigurer extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers( ResourceHandlerRegistry registry) { registry.addResourceHandler("/resources/**") .addResourceLocations("/resources/"); } }
  41. 46.

    (C) CASAREAL, Inc. All rights reserved. #jsug 8FC.WD$POpHVSFS͸Ͳ͏΍ͬͯ࢖ΘΕΔͷ͔ ▸ %FMFHBUJOH8FC.WD$POpHVSBUJPOΫϥε͕


    !"VUPXJSFEͰऔಘ͍ͯ͠Δ 46 https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/java/org/ springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java#L48
  42. 47.

    (C) CASAREAL, Inc. All rights reserved. #jsug +BWB$POpH΋#FBO ▸ !$POpHVSBUJPOͷਖ਼ମ͸!$PNQPOFOU

    ▸ #FBO͔ͩΒɺDPOUFYUHFU#FBO ɺ!"VUPXJSFEɺ !#FBOϝιουͷҾ਺ͰଞͷΫϥε͔ΒऔಘͰ͖Δ 47 https://github.com/spring-projects/spring-framework/blob/master/spring-context/src/main/java/org/ springframework/context/annotation/Configuration.java
  43. 48.

    (C) CASAREAL, Inc. All rights reserved. #jsug ਖ਼ମ͕!$PNQPOFOUͳΞϊςʔγϣϯ ▸ !$POpHVSBUJPO

    ▸ !$POUSPMMFS ▸ !3FTU$POUSPMMFS ▸ !4FSWJDF ▸ !3FQPTJUPSZ ▸ !$POUSPMMFS"EWJDF ▸ !3FTU$POUSPMMFS"EWJDF 48 ͜ΕΒͷΞϊςʔγϣϯ͕ ෇͍ͨΫϥε͸͢΂ͯBean ※΋ͪΖΜɺίϯϙʔωϯτεΩϟϯର৅ͷ
 ɹύοέʔδͰͳ͚Ε͹ͳΒͳ͍
  44. 49.

    (C) CASAREAL, Inc. All rights reserved. #jsug %JTQBUDIFS4FSWMFUͷઃఆ ▸ 4QSJOH·Ͱ͸XFCYNMʹॻ͍͍ͯͨ

    ▸ 4QSJOH͔Β8FC"QQMJDBUJPO*OJUJBMJ[FSΫ ϥε͕௥Ճ͞Εͨ ▸ XFCYNMෆཁ ▸ 4FSWMFUͷ4FSWMFU*OJUJBMJ[FSɺ͓Αͼ+BWB4&ͷ 4FSWJDF-PBEFSͷ࢓૊ΈΛར༻͍ͯ͠Δ 49
  45. 50.

    (C) CASAREAL, Inc. All rights reserved. #jsug 8FC"QQMJDBUJPO*OJUJBMJ[FSͷར༻ ▸ "CTUSBDU"OOPUBUJPO$POpH%JTQBUDIFS4F

    SWMFU*OJUJBMJ[FSΫϥεΛܧঝͯ͠࡞੒ ▸ 8FC"QQMJDBUJPO*OJUJBMJ[FSΠϯλϑΣʔεͷ࣮૷Ϋϥ ε 50
  46. 51.

    (C) CASAREAL, Inc. All rights reserved. #jsug 8FC"QQMJDBUJPO*OJUJBMJ[FSͷར༻ 51 public

    class MyWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override // ϏδωεϩδοΫ૚ҎԼͷJava Configͷࢦఆ protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{DataSourceConfig.class, JpaConfig.class, ServiceConfig.class}; } @Override // MVC༻ͷJava Configͷࢦఆ protected Class<?>[] getServletConfigClasses() { return new Class<?>[]{MvcConfig.class}; } @Override // DispatcherServletͷurl-patternͷࢦఆ protected String[] getServletMappings() { return new String[]{"/"}; } @Override // αʔϒϨοτϑΟϧλʔͷࢦఆ protected Filter[] getServletFilters() { return new Filter[]{new CharacterEncodingFilter( StandardCharsets.UTF_8.name(), true)}; } }
  47. 52.

    (C) CASAREAL, Inc. All rights reserved. #jsug ຊষͷ·ͱΊ ▸ 4QSJOH.7$͸ɺ4QSJOHͷ%*ͷ࢓૊Έ্Ͱಈ͍͍ͯΔ

    ▸ ࢖͏ϏϡʔʹରԠͨ͠7JFX3FTPMWFSΛ#FBOఆٛ͢Δ ▸ ͦͷଞͷඞཁͳ#FBO͸!&OBCMF8FC.WDͰΠϯϙʔ τͰ͖Δ ▸ 8FC"QQMJDBUJPO*OJUJBMJ[FSͰ%JTQBUDIFS4FSWMFUͷઃ ఆΛهड़͢Δ 52
  48. 53.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 53
  49. 54.

    (C) CASAREAL, Inc. All rights reserved. #jsug 4QSJOH%BUB+1" ▸ 4QSJOHςΫϊϩδʔΛ׆༻ͯ͠ɺ+1"Λ͞Βʹ

    ࢖͍΍ͨ͘͢͠΋ͷ ▸ 3FQPTJUPSZ͸ΠϯλϑΣʔεͷΈͰ0, ▸ ϝιου໊͔ΒͷΫΤϦੜ੒ ▸ +1"࣮૷͸جຊతʹ)JCFSOBUF 54
  50. 55.

    (C) CASAREAL, Inc. All rights reserved. #jsug %BUB4PVSDFͷ#FBOఆٛ ▸ #FBOఆٛͯ͠ɺ4QSJOH%BUB+1"͕಺෦Ͱ


    औಘɾར༻Ͱ͖ΔΑ͏ʹ͢Δ ▸ ࠓճ͸૊ࠐ%#ͷ)%BUBCBTFΛར༻ ▸ ىಈ࣌ʹ42-ΛಡΈࠐΜͰɺDSFBUFUBCMF΍JOTFSUΛ ߦ͏ػೳΛ࣮૷ 55
  51. 56.

    (C) CASAREAL, Inc. All rights reserved. #jsug %BUB4PVSDFͷ#FBOఆٛ 56 @Configuration

    public class DataSourceConfig { @Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); return builder.setName("jsug") .setType(EmbeddedDatabaseType.H2) // drop table, create table .addScript("classpath:/schema.sql") // insert .addScript("classpath:/data.sql") .build(); } }
  52. 57.

    (C) CASAREAL, Inc. All rights reserved. #jsug &OUJUZ.BOBHFS'BDUPSZͷ#FBOఆٛ ▸ ໭Γ஋ͷܕ͕

    -PDBM$POUBJOFS&OUJUZ.BOBHFS'BDUPSZ#FBOͳ !#FBOϝιου࡞੒ ▸ ϝιου໊͸ʮFOUJUZ.BOBHFS'BDUPSZʯʹ͢Δඞཁ͕ ͋Δ ▸ ࣮ࡍʹ#FBOͱͯ͠ఆٛ͞ΕΔͷ͸ɺ 'BDUPSZ#FBOHFU0CKFDU ͷ໭Γ஋Ͱ͋Δ &OUJUZ.BOBHFS'BDUPSZ 57
  53. 58.

    (C) CASAREAL, Inc. All rights reserved. #jsug &OUJUZ.BOBHFS'BDUPSZͷ#FBOఆٛ 58 @Configuration

    @EnableJpaRepositories(basePackages = "com.example.persistence.repository") // RepositoryΠϯλϑΣʔεͷύοέʔδ public class JpaConfig { @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { HibernateJpaVendorAdapter hjva = new HibernateJpaVendorAdapter(); hjva.setDatabase(Database.H2); hjva.setGenerateDdl(false); // JPAͷDDLੜ੒ػೳΛແޮԽ LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(dataSource); // DataSourceͷηοτ factoryBean.setJpaVendorAdapter(hjva); factoryBean.setPackagesToScan("com.example.persistence.entity", "org.springframework.data.jpa.convert.threeten"); // εΩϟϯઃఆʢޙड़ʣ HashMap<String, Object> properties = new HashMap<>(); properties.put("hibernate.physical_naming_strategy", new MyPhysicalNamingStrategy()); // ΩϟϝϧέʔεɾεωʔΫέʔεͷม׵ factoryBean.setJpaPropertyMap(properties); return factoryBean; }
  54. 59.

    (C) CASAREAL, Inc. All rights reserved. #jsug /BNJOH4USBUFHZͷ࡞੒ ▸ )JCFSOBUFͷػೳͰɺ+BWBͷϑΟʔϧυ໊ͱ%#

    ͷΧϥϜ໊ͷม׵ϧʔϧΛهड़͢Δ΋ͷ ▸ ࠓճ͸ɺΩϟϝϧέʔεͱεωʔΫέʔεΛࣗಈ ม׵͢Δ/BNJOH4USBUFHZΛࣗલͰ࡞੒ ▸ ྫɿKPJOFE%BUFKPJOFE@EBUF 59
  55. 60.

    (C) CASAREAL, Inc. All rights reserved. #jsug /BNJOH4USBUFHZͷ࡞੒ 60 private

    static class MyPhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl { /** * ΩϟϝϧέʔεΛεωʔΫέʔεʹม׵(ࡶͳ࣮૷ͳͷͰਅࣅΔͳةݥ) */ @Override public Identifier toPhysicalColumnName( Identifier name, JdbcEnvironment context) { StringBuilder builder = new StringBuilder(name.getText()); for (int i = 1; i < builder.length() - 1; i++) { if (Character.isLowerCase(builder.charAt(i - 1)) && Character.isUpperCase(builder.charAt(i))) { builder.insert(i, '_'); i++; } } return Identifier.toIdentifier(builder.toString().toLowerCase()); } }
  56. 61.

    (C) CASAREAL, Inc. All rights reserved. #jsug !&OBCMF+QB3FQPTJUPSJFT ▸ ϦϙδτϦΠϯλϑΣʔεͷύοέʔδΛࢦఆ

    ▸ ਖ਼ମ͸!*NQPSU *NQPSU#FBO%FpOJUJPO3FHJTUSBS ▸ #FBOఆٛΛ௥ՃͰ͖ΔͬΆ͍ʢະௐࠪʣ 61 https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/ jpa/repository/config/EnableJpaRepositories.java#L47
  57. 63.

    (C) CASAREAL, Inc. All rights reserved. #jsug +1"Ͱ%BUFBOE5JNFΛ࢖͏ ▸ KBWBTRM%BUFKBWBUJNF-PDBM%BUFͳͲͷ


    ܕม׵Λߦ͏$POWFSUFS͕ɺ4QSJOH%BUB+1" Ͱఏڙ͞Ε͍ͯΔ ▸ PSHTQSJOHGSBNFXPSLEBUBKQBDPOWFSUUISFFU FOύοέʔδͷ+TS+QB$POWFSUFSTΫϥε ʹɺ੩తωετΫϥεͱͯ͠࡞੒͞Ε͍ͯΔ ▸ ͜ͷύοέʔδΛTFU1BDLBHF5P4DBO ʹࢦఆ 63
  58. 65.

    (C) CASAREAL, Inc. All rights reserved. #jsug ຊষͷ·ͱΊ ▸ ૊ࠐ%#Ͱ%BUB4PVSDFΛఆٛ͢Δͱɺ


    ىಈ࣌ʹ42-Λ࣮ߦͰ͖Δʂ ▸ &OUJUZ.BOBHFS'BDUPSZΛ#FBOఆٛ͢Δʂ ▸ /BNJOH4USBUFHZɺ!&OBCMF+QB3FQPTJUPSJFTɺ TFU1BDLBHF5P4DBO ͷࢦఆ͕ඞཁʂ ▸ %BUFBOE5JNF"1*Λ࢖͏৔߹͸ɺ$POWFSUFSͷࢦ ఆ΋ඞཁʂ 65
  59. 66.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃ 4QSJOH#PPU͸ԿΛ͍ͯ͠Δͷʁ ᶄ

    4QSJOHͷجຊʂ#FBOఆٛΛཧղ͠Α͏ ᶅ 4QSJOH.7$ͷ࢓૊ΈΛཧղ͠Α͏ ᶆ 4QSJOHͰͷσʔλΞΫηεͷ࢓૊ΈΛཧղ͠ Α͏ ᶇ "VUP$POpHVSBUJPOͷιʔεΛಡΜͰ
 4QSJOH#PPUΛཧղ͠Α͏ 66
  60. 67.

    (C) CASAREAL, Inc. All rights reserved. #jsug ʮઃఆͷࣗಈԽʯͷਖ਼ମ ▸ େྔͷ+BWB$POpHΫϥε͕͋Β͔͡Ί༻ҙ͞Ε͍ͯΔ

    ▸ ओʹTQSJOHCPPUBVUPDPOpHVSFYYY3&-&"4&KBS಺ ▸ ʮ͋ΔΫϥε͕Ϋϥεύε্ʹଘࡏ͢Δ͔Ͳ͏͔ʯͳͲͷ৚ ݅Ͱɺ֤+BWB$POpHΫϥε΍֤!#FBOϝιουΛ༗ޮԽແ ޮԽ͍ͯ͠Δ ▸ !$POEJUJPOBM0O9YYΞϊςʔγϣϯ ▸ ৄࡉ͸!LB[VLJ[PP͞Μͷ2JJUB΁ ▸ IUUQRJJUBDPNLB[VLJ[PPJUFNTEFEEDGEE 67
  61. 68.

    (C) CASAREAL, Inc. All rights reserved. #jsug 7JFX3FTPMWFSͷ#FBOఆٛ ▸ 4QSJOH3FTPVSDF5FNQMBUF3FTPMWFSͷ#FBOఆٛ

    ▸ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPUBVUPDPOpHVSFTSDNBJO KBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSFUIZNFMFBG "CTUSBDU5FNQMBUF3FTPMWFS$PO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DPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPU BVUPDPOpHVSFTSDNBJOKBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSF WBMJEBUJPO7BMJEBUJPO"VUP$POpHVSBUJPOKBWB 72
  66. 73.

    (C) CASAREAL, Inc. All rights reserved. #jsug ੩తϑΝΠϧͷϋϯυϦϯά ▸ Ϋϥεύε௚ԼͷTUBUJDϑΥϧμ౳͕ࢦఆ͞Εͯ

    ͍Δ ▸ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPU BVUPDPOpHVSFTSDNBJOKBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSF XFC3FTPVSDF1SPQFSUJFTKBWB- ▸ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPU BVUPDPOpHVSFTSDNBJOKBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSF XFC8FC.WD"VUP$POpHVSBUJPOKBWB- 73
  67. 74.

    (C) CASAREAL, Inc. All rights reserved. #jsug %JTQBUDIFS4FSWMFUͷઃఆ ▸ 4FSWMFU3FHJTUSBUJPO#FBOʹ%JTQBUDIFS4FSWMFU

    ͕ొ࿥͞Ε͍ͯΔ ▸ 4FSWMFU3FHJTUSBUJPO#FBO͸4QSJOH#PPUͰఆٛ͞Ε ͨΫϥε ▸ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPU BVUPDPOpHVSFTSDNBJOKBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSF XFC%JTQBUDIFS4FSWMFU"VUP$POpHVSBUJPOKBWB- 74
  68. 75.

    (C) CASAREAL, Inc. All rights reserved. #jsug ૊ࠐ%#ͷ%BUB4PVSDF ▸ &NCFEEFE%BUB4PVSDFΛ#FBOఆ͍ٛͯ͠Δ

    ▸ IUUQTHJUIVCDPNTQSJOHQSPKFD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inc. All rights reserved. #jsug !&OBCMF+QB3FQPTJUPSJFT ▸ +QB3FQPTJUPSJFT"VUP$POpHVSBUJPO


    ˠ+QB3FQPTJUPSJFT"VUP$POpHVSF3FHJTUSBS
 ˠ&OBCMF+QB3FQPTJUPSJFT$POpHVSBUJPO ▸ ͜͜ʹ!&OBCMF+QB3FQPTJUPSJFT͕෇͍͍ͯΔ ▸ IUUQTHJUIVCDPNTQSJOHQSPKFDUTTQSJOHCPPUCMPCYTQSJOHCPPU BVUPDPOpHVSFTSDNBJOKBWBPSHTQSJOHGSBNFXPSLCPPUBVUPDPOpHVSF EBUBKQB+QB3FQPTJUPSJFT"VUP$POpHVSBUJPOKBWB 78
  72. 79.

    (C) CASAREAL, Inc. All rights reserved. #jsug !&OUJUZ4DBO ▸ ΤϯςΟςΟ΍$POWFSUFSͷύοέʔδΛࢦఆ

    ▸ 4QSJOH#PPUͰఆٛ͞ΕͨΞϊςʔγϣϯ ▸ TFU1BDLBHF5P4DBO ૬౰ ▸ ͜Ε΋ਖ਼ମ͸!*NQPSU 79 @SpringBootApplication @EntityScan(basePackages = { "com.example.persistence.entity", "org.springframework.data.jpa.convert.threeten" }) public class Application {
  73. 80.

    (C) CASAREAL, Inc. All rights reserved. #jsug ղ͚ͳ͔ͬͨಾ ▸ 4QSJOH#PPU൛ͷΞϓϦͰɺ


    +1"ͷΤϯςΟςΟʹ!4FRVFODF(FOFSBUPSΛ ෇͚ͳ͍ͱɺ*%ࣗಈ࠾൪͕͞Εͳ͔ͬͨɾɾɾ ▸ ඇ4QSJOH#PPUͳαϯϓϧ͸ແ͠Ͱ΋࠾൪͞ΕΔ ▸ IUUQTHJUIVCDPN.BTBUPTIJ5BEBTQSJOHGPSTQSJOHCPPUCMPCNBTUFS TQSJOHCPPUTSDNBJOKBWBDPNFYBNQMFQFSTJTUFODFFOUJUZ &NQMPZFFKBWB- 80
  74. 82.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶃBQQMJDBUJPOQSPQFSUJFTʹઃఆ ▸ BQQMJDBUJPOQSPQFSUJFT


    ˠ!$POpHVSBUJPO1SPQFSUJFTͳΫϥε
 ˠ#FBOఆٛͰ࢖ΘΕΔ ▸ ৄࡉ͸!NBLJOH͞Μͷϒϩά΁ ▸ IUUQTCMPHJLBNFOUSJFT 82
  75. 83.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶄࣗ෼Ͱ#FBOఆٛ͢Δ ▸ "VUP$POpHVSBUJPO಺ͷ

    !$POEJUJPOBM0O.JTTJOH#FBOͳ#FBO͸ɺ
 ࣗ෼Ͱ#FBOఆٛͨ͠৔߹͸ແޮԽ͞ΕΔ 83
  76. 84.

    (C) CASAREAL, Inc. All rights reserved. #jsug ᶅ$VTUPNJ[FSΛར༻͢Δ ▸ 4QSJOH#PPU͸େྔͷ$VTUPNJ[FSΛఏڙ͍ͯ͠Δ

    ▸ 3FTU5FNQMBUF$VTUPNJ[FS ▸ +BDLTPO0CKFDU.BQQFS#VJMEFS$VTUPNJ[FS ▸ 1MBUGPSN5SBOTBDUJPO.BOBHFS$VTUPNJ[FS ▸ ͦͷଞ͍Ζ͍Ζ ▸ 9YY$VTUPNJ[FSΛ#FBOఆٛ͢Ε͹ɺ
 "VUP$POpHVSBUJPOΫϥε͕%*ίϯςφ͔Βरͬͯ͘ΕΔ ▸ ৄࡉ͸!LB[VLJ[PP͞Μͷ2JJUB΁
 IUUQRJJUBDPNLB[VLJ[PPJUFNTBCFD 84
  77. 85.

    (C) CASAREAL, Inc. All rights reserved. #jsug ຊষͷ·ͱΊ ▸ 4QSJOH#PPU͸

    ▸ େྔͷ+BWB$POpHΛ͋Β͔͡Ίఏڙ͠ɺ
 ৚݅ʹΑͬͯ༗ޮԽແޮԽ͍ͯ͠Δ͚ͩʂ ▸ #FBOఆٛʹศརͳΫϥεͳͲ΋ఏڙ͍ͯ͠Δ ▸ #FBOఆٛΛΧελϚΠζ͍ͨ͠৔߹͸ ▸ BQQMJDBUJPOQSPQFSUJFTɺࣗલͰ#FBOఆٛɺ $VTUPNJ[FSͷར༻ 85
  78. 87.

    (C) CASAREAL, Inc. All rights reserved. #jsug ࠷ޙͷ·ͱΊ ▸ ୤4QSJOH#PPUॳ৺ऀ͢ΔͨΊʹ͸ɺ


    4QSJOHͷجૅ஌͕ࣝԿΑΓେࣄʂ ▸ 4QSJOHͷ#FBOఆٛΛཧղ͠Α͏ʂ ▸ 4QSJOH#PPUΛ࢖ΘͣʹΞϓϦΛ࡞ͬͯΈΑ͏ʂ ▸ "VUP$POpHVSBUJPOͷιʔεΛಡΈͳ͕Βɺ
 ΞϓϦΛ4QSJOH#PPUԽ͍ͯ͜͠͏ʂ 87
  79. 88.

    (C) CASAREAL, Inc. All rights reserved. #jsug ͓͢͢Ίࢀߟॻ੶ ▸ վగ৽൛4QSJOHೖ໳

    ▸ ࠷ॳ͸͜ͷຊʂ ▸ 4QSJOHపఈೖ໳ ▸ ৄࡉΛ஌ΔͳΒ͜ͷຊʂ ▸ 1SP4QSJOH#PPU ༸ॻ  ▸ 4QSJOH#PPUΛ໢ཏతʹֶशͰ ͖Δʂ 88