Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Grails 3で生まれ変わったGrailsの今 / Spring in Summer 2015
Search
Kazuki YAMAMOTO
September 02, 2015
1
400
Grails 3で生まれ変わったGrailsの今 / Spring in Summer 2015
「Spring in Summer ~ 夏なのにSpring」での発表資料です
http://www.springframework.jp/summer
Kazuki YAMAMOTO
September 02, 2015
Tweet
Share
More Decks by Kazuki YAMAMOTO
See All by Kazuki YAMAMOTO
今こそッ、始めようGrailsブートキャンプ!!!! / Grails Bootcamp for JGGUG
yamkazu
0
320
Grails 3でWeb APIを簡単に作ろう!
yamkazu
6
2.1k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Speed Design
sergeychernyshev
24
610
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
RailsConf 2023
tenderlove
29
900
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building an army of robots
kneath
302
43k
How to train your dragon (web standard)
notwaldorf
88
5.7k
A Tale of Four Properties
chriscoyier
156
23k
Transcript
Grails3Ͱੜ·ΕมΘͬͨ Grailsͷࠓ @yamkazu
ࢁຊ थ • @yamkazu • JGGUG
None
ຊͷ༰ • Grails͓͞Β͍ • Grails 3ͷ৽ػೳ • σϞ
Grails͓͞Β͍
Grailsͱ • Graeme Rocherࢯ͕։ൃ • ϑϧελοΫͷWebϑϨʔϜϫʔΫ • Groovyϕʔε • Ruby
on RailsɺDjangoͱ͍ͬͨϑϨʔϜϫʔΫʹӨڹΛड͚͍ͯΔ • DRYʢDon't Repeat Yourselfʣ= ಉ͡هड़Λ܁Γฦ͞ͳ͍ • CoCʢConvention over Configurationʣ= ઃఆΑΓن • εΩϟϑΥϧσΟϯά • Java EE্Ͱಈ࡞
Grailsͷྺ࢙ 4QSJOH4PVSDFԼ 7.XBSF͕ 4QSJOH4PVSDFΛങऩ
4QSJOH4PVSDF͕ 1JWPUBMԼ 1JWPUBMଔۀ
OCI͕৽͍͠ϗʔϜ http://www.ociweb.com/resources/news/2015/04/15/april-2015-grails-web-framework-finds-home-oci
৽ϝϯόՃ&ืूத
Grailsͷத
= + +
σʔλΞΫηε αʔϏε ΞϓϦέʔγϣϯ ϓϨθϯςʔγϣϯ GrailsΛߏ͢Δཁૉ 63-Ϛοϐϯά ϑΟϧλ λάϦϒ ίϯτϩʔϥ Ϗϡʔ
αʔϏε JO υϝΠϯΫϥε Ξηοτ ςετ ϓϥάΠϯ εΩϟϑΥϧυ
ίϯτϩʔϥ class BookController { def index() { … render view:
'index' } }
Ϗϡʔ(GSP) <!DOCTYPE html> <html> <head> <meta name="layout" content="main"/> <title>Render Domain</title>
</head> <body> <table> <tr> <td>Name</td> <td>Age</td> </tr> <g:each in="${list}" var="person"> <tr> <td>${person.lastName}, ${person.firstName}</td> <td>${person.age}</td> </tr> </g:each> </table> </body> </html>
υϝΠϯΫϥε(GORM) class Book { String title Integer price static
constraints = { title(blank: false, maxSize: 20) price(min: 0) } } // 保存 new Book(title: "はじめてのGrails", price: 3000).save() // クエリ Book.list() Book.findByTitle("はじめてのGrails")
ςετ(Spock) @TestFor(Book) class BookSpec extends Specification { def "find book
by title"() { given: "Bookが1件保存" new Book(title: "test title", price: 3000).save() when: "Bookをタイトルで検索する" def book = Book.findByTtile("test title") then: "対象のBookが取得できている" book.title == "test title" book.price == 3000 } }
Grails 3
Grails 3ͷ֓ཁ • Spring BootΛϕʔεʹ࠶ߏங • GradleͰϏϧυγεςϜ͕Ұ৽ • ΞϓϦέʔγϣϯϓϩϑΝΠϧͷՃ •
ίϯτϩʔϥɺυϝΠϯΫϥεͳͲͷ͍ํ΄ͱΜ Ͳมߋͳ͠ • etc
Spring Boot
Spring Boot • Spring Boot 1.2Λϕʔεʹ࠶ߏங • ෦ΞϓϦέʔγϣϯαʔό • ࣮ߦՄೳJarϑΝΠϧ
• Spring BootSpringͷΤίγεςϜ͕ΑΓ׆༻͘͢͠ • ϞχλϦϯάͷ֦ு • Spring CloudΛ͍͍ͨ
Bootʹ͓ͤͰ͖Δͱ͜Ζ ͤͯGrailsࣗΛεϦϜԽ
ͦͷଞSpring Bootಋೖʹ ͏มߋ
Application.groovy import grails.boot.GrailsApp import grails.boot.config.GrailsAutoConfiguration class Application extends GrailsAutoConfiguration
{ static void main(String[] args) { GrailsApp.run(Application) } }
application.yml --- grails: profile: web codegen: defaultPackage: grails.sample.plugin.database.migration info: app:
name: '@info.app.name@' version: '@info.app.version@' grailsVersion: '@info.app.grailsVersion@' spring: groovy: template: check-template-location: false --- grails: mime: disable: accept: header:
ΠϯςάϨʔγϣϯςετ import grails.test.mixin.integration.Integration import spock.lang.Specification @Integration class BookSpec extends
Specification { def "count books"() { expect: Book.count() == 1 } }
None
buildscript { ext { grailsVersion = project.grailsVersion } repositories {
mavenLocal() maven { url "https://repo.grails.org/grails/core" } } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.1.1' classpath 'org.grails.plugins:database-migration:2.+' } } plugins { id "io.spring.dependency-management" version "0.4.0.RELEASE" } version "0.1" group "grails.sample.plugin.database.migration" apply plugin: "spring-boot" apply plugin: "war" apply plugin: "asset-pipeline" apply plugin: 'eclipse' apply plugin: 'idea' apply plugin: "org.grails.grails-web"
None
None
maven/gradleͰ͓ೃછΈͷ σΟϨΫτϦߏʹมߋ
None
GGTS೦ͳ͕Β ݱࡏϝϯςφϯε ͞Ε͍ͯͳ͍
ͦͷଞGradleͷޮՌ • Ϗϧυ͕ߴʹͳͬͨ • ϚϧνϓϩδΣΫτ͕؆୯ʹ࣮ݱͰ͖Δ • Gradleͷطଘͷ֦ு͕༻Մೳʹͳͬͨ
ΞϓϦέʔγϣϯϓϩϑΝΠϧ
ΞϓϦέʔγϣϯϓϩϑΝΠϧ • ϓϩϑΝΠϧʹؚ·ΕΔͷ • ϓϩδΣΫτςϯϓϨʔτ • ϑΝΠϧςϯϓϨʔτ • ίϚϯυ(runɺpackageɺtestɺetc)
ϓϩϑΝΠϧϦϙδτϦ • GitͷϦϙδτϦͱͯ͠ཧ͞Ε͍ͯΔ • https://github.com/grails/grails-profile-repository/ • ݱࡏެ։͞Ε͍ͯΔϓϩϑΝΠϧ·ͩΘ͔ͣ • webɺweb microɺweb
apiɺpluginɺweb plugin • ࠓޙʹظ
ͦͷଞͷมߋ
Logback͕σϑΥϧτʹ appender('STDOUT', ConsoleAppender) { encoder(PatternLayoutEncoder) { pattern = "%level %logger
- %msg%n" } } root(ERROR, ['STDOUT']) logger('org.hibernate.type.descriptor.sql.BasicBinder', TRACE) logger('org.hibernate.SQL', DEBUG)
Geb͕σϑΥϧτϓϥάΠϯʹ @Integration class HomeSpec extends GebSpec { void "Test
the home page renders correctly"() { when:"The home page is visited" go '/' then:"The title is correct" $('title').text() == "Welcome to Grails" } }
σϞ
Grails 3ͷ࣮ࡍ • Grails 2.x͔ΒͷҠߦ͍ͨΜ • υΩϡϝϯτͱҠߦϓϥάΠϯͰؤுΔ • Grails 3Ͱͳ͘ͳͬͨػೳ͕͕͋ͬͨඞཁͳػೳ෮׆
• ίϛϡχςΟ͔ΒͷϑΟʔυόοΫ • ϓϥάΠϯ͕গͳ͍ • ओཁͳϓϥάΠϯग़ἧ͍ͭͭ͋Δ • Spring Security PluginઌM1͕ϦϦʔε • ·ͩόάଟΊͳؾ • ΄ΜͱΜͲͷ߹ϫʔΫΞϥϯυଘࡏ͢Δ
ࠓޙͷϦϦʔε༧ఆ • Grails 3.1 • New feature planned include: •
More flexible profile repository support • multiple repositories • custom repositories • altering current repo • REST Improvements • REST profile • JSON builder views • Renderer convention • Removal of org.json and GSon to unify around JsonBuilder • Namespaced marshallers • UrlMappings for members and collections • AngularJS / SPA framework support • AngularJS profile https://github.com/grails/grails-core/wiki/Roadmap
·ͱΊ • GradeɺSpringͳͲطଘͷΤίγεςϜΛϕʔ εʹੜ·ΕมΘͬͨ • ͜ΕΒΛͬͨ։ൃΛ͞ΒʹՃͤ͞Δϓ ϥοτϑΥʔϜʹ্͕͍ͬͯΔ • DRYɺCoCͳͲطଘͷGrailsͷίϯηϓτͦ ͷ··
ࠓڵຯͬͨਓੋඇҰ ͞ΘͬͯΈ͍ͯͩ͘͞ʂ