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
410
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
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Why Our Code Smells
bkeepers
PRO
335
57k
4 Signs Your Business is Dying
shpigford
182
21k
Docker and Python
trallard
42
3.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
GitHub's CSS Performance
jonrohan
1031
460k
A designer walks into a library…
pauljervisheath
205
24k
Adopting Sorbet at Scale
ufuk
73
9.1k
Being A Developer After 40
akosma
87
590k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
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ͷίϯηϓτͦ ͷ··
ࠓڵຯͬͨਓੋඇҰ ͞ΘͬͯΈ͍ͯͩ͘͞ʂ