GrailsでSpringをGroovyにしよう!

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    GrailsでSpringをGroovyにしよう! - Presentation Transcript

    1. def speaker = new Cast(name:”T.Yamamoto”,version:”JSG2UG-2009-06-24”)
    2. <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="host" value="127.0.0.1"/> </bean> <bean id="mailMessageMe" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="tyam@xmldo.jp"/> </bean> <bean id="mailMessageYou" class="org.springframework.mail.SimpleMailMessage"> <property name="from" value="you@xmldo.jp"/> </bean> mailSender(org.springframework.mail.javamail.JavaMailSenderImpl) { host = '127.0.0.1' } def map = ["Me":"tyam@xmldo.jp","You":"you@xmldo.jp"] map.each{k,v-> "mailMessage${k}"(org.springframework.mail.SimpleMailMessage) { from = v } }
    3. grails create-app demo cd demo grails install-template
    4. <web-app version="2.4" applicationContext! ... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> ... <servlet> <servlet-name>grails</servlet-name> <servlet-class> org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> ... DispatcherServlet!
    5. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" ...> <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactor yBean"> <description>Grails application factory bean</description> <property name="grailsDescriptor" value="/WEB-INF/grails.xml" /> <property name="grailsResourceLoader" ref="grailsResourceLoader" /> </bean> ... </beans>
    6. import org.springframework.context.ApplicationContext import grails.spring.BeanBuilder // BeanBuilder def builder = new BeanBuilder() builder.beans { // } // ApplicationContext ApplicationContext ctx = builder.createApplicationContext()
    7. AbstractBeanDefinition id someBean(MySomeBean," ",2 ,[3]){bean-> <bean . . . factoryMethod="getInstance"/> bean.singleton = false bean.factoryMethod = "getInstance" fieldOne = "JGGUG" anotherBean = ref("anotherBean",true) }
    8. withFactoryMethod(BeanWithFactoryMethod){bean-> bean.factoryMethod = "getInstance" bean.scope = "prototype" AbstractBeanDefinition person = "tyama" } def somebean = withFactoryMethod(BeanWithFactoryMethod){ person = "tyama" } somebean.factoryMethod = "getInstance" AbstractBeanDefinition somebean.scope = "prototype"
    9. withFactoryMethod(BeanWithFactoryMethod){bean-> bean.factoryMethod = "getInstance" bean.scope = "prototype" person = "tyama" }
    10. <ref bean="anotherBean"/> ref("anotherBean") ref("anotherBean",true)
    11. beanA(BeanA){ name="bean a" } beanB(BeanB){ name="bean b" parent=ref("beanA") } beanBB(BeanB){ name="bean b" parent=beanA }
    12. exampleInner(ExampleBean2){ bean = {ExampleBean b -> name="My First Inner Bean" num=24 } } exampleInnerBeanFactory(ExapleBeanFactory) exampleInnerUntyped(ExampleBean2){ bean = {bean-> bean.factoryBean = "exampleInnerBeanFactory" bean.factoryMethod = "newInstance" name="example BeanFactory" num=24 } }
    13. <bean id="exampleAbstractBeanNoClass" abstract="true"> <property name="name" value="abstract bean"/> <property name="num" value="20"/> </bean> <bean id="exampleNoCls" parent="exampleAbstractBeanNoClass" class="ExampleBean"> <property name="name" value="My First Bean"/> </bean> <bean id="exampleAbstractBeanWiCn" abstract="true" class="ExampleBean"> <property name="name" value="abstract bean"/> <property name="num" value="23"/> </bean> <bean id="exampleWiCn" parent="exampleAbstractBeanWiCn"> <property name="name" value="My First Bean"/> </bean>
    14. exampleAbstractBeanNoClass { name="abstract bean" (SomeClass) num = 20 } exampleAbstractBeanWiCn(ExampleBean){ bean -> bean.'abstract' = true bean.‘abstract’=true name="abstract bean" num = 23 } exampleNoCls(ExampleBean){ bean -> bean.parent = exampleAbstractBeanNoClass name = "My First Bean" } bean.parent
    15. package bean <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" class ExampleBean { "http://www.springframework.org/dtd/spring-beans.dtd"> def name def num <beans> ExampleBean(){} <bean id="exampleBean" class="bean.ExampleBean"> ExampleBean(String arg){println arg} <constructor-arg value="hello exampleBean"/> String toString(){ <property name="name" value="My First Bean" /> "ExamplBean: $name $num" <property name="num" value="19" /> } </bean> } </beans>
    16. package bean beans = { exampleBean(ExampleBean,"hello exampleBean"){ class ExampleBean { name = "My First Bean" def name num = 19 def num } ExampleBean(){} } ExampleBean(String arg){println arg} String toString(){ "ExamplBean: $name $num" } }
    17. ID dataSource(com.mchange.v2.c3p0.ComboPooledDataSource) { bean -> bean.destroyMethod = "close" driverClass = "org.hsqldb.jdbcDriver" jdbcUrl="jdbc:hsqldb:hsql://localhost:9001" user="sa" password="" }
    18. class JggugBeanGrailsPlugin { // the plugin version def version = "0.1" .... def doWithSpring = { // TODO Implement runtime spring config (optional) exampleBean3(bean.ExamplePluginBean,"hello plugin exampleBean3"){ name = "My 3rd Bean" num = 100 } } .... }
    19. <gorm:sessionFactory base-package="org.grails.samples" data-source-ref="dataSource" message-source-ref="messageSource"> <property name="hibernateProperties"> y En tit <util:map> n ce. <entry key="hibernate.hbm2ddl.auto" i ste .p ers value="update"/> ils t gra y </util:map> im por y n { gr oov tit erso e on. </property> @En s P nam Per s s cla tring </gorm:sessionFactory> S ... }

    + Tsuyoshi YamamotoTsuyoshi Yamamoto, 4 months ago

    custom

    507 views, 1 favs, 0 embeds more stats

    JSUG+JGGUG合同勉強会
    2009年6月24日

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 507
      • 507 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 7
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories