Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring Scala : 스프링이 스칼라를 만났을 때

Outsider
October 14, 2013

Spring Scala : 스프링이 스칼라를 만났을 때

Springcamp 2013 with Scala에서 발표한 발표자료

Outsider

October 14, 2013
Tweet

More Decks by Outsider

Other Decks in Technology

Transcript

  1. 1 public class Person { 2 private String name; 3

    4 public String getName() { 5 return this.name; 6 } 7 8 public void setName(String name) { 9 this.name = name; 10 } 11 }
  2. 1 class Person { 2 var name:String = _ 3

    4 def name():String = name 5 def name_=(n:String) = name = n 6 }
  3. 1 public class Person { 2 private String name; 3

    4 public String name() { 5 return this.name; 6 } 7 8 public void name_$eq(String name) { 9 this.name = name; 10 } 11 }
  4. 1 import scala.beans.BeanProperty 2 3 class Person { 4 5

    @BeanProperty 6 var name:String = _ 7 }
  5. 1 <repositories> 2 <repository> 3 <id>repository.springsource.milestone</id> 4 <name>SpringSource Milestone Repository</name>

    5 <url>http://repo.springsource.org/milestone</url> 6 </repository> 7 </repositories> 8 9 <dependencies> 10 <dependency> 11 <groupId>org.springframework.scala</groupId> 12 <artifactId>spring-scala</artifactId> 13 <version>1.0.0.M2</version> 14 </dependency> 15 </dependencies>
  6. 1 template.send("queue", 2 new MessageCreator() { 3 public Message createMessage(Session

    session) 4 throws JMSException { 5 return session 6 .createTextMessage("Hello World"); 7 } 8 });
  7. 1 RestTemplate restTemplate = new RestTemplate(); 2 3 String result

    = restTemplate 4 .getForObject( 5 "http://example.com", 6 String.class);
  8. 1 val restTemplate = new RestTemplate() 2 3 val result

    = restTemplate 4 .getForAny[String] 5 ("http://example.com")
  9. 1 class ScalaExampleConfiguration 2 extends FunctionalConfiguration { 3 4 bean(

    5 "foo", 6 aliases = Seq("bar") 7 scope = BeanDefinition.SCOPE_PROTOTYPE) { 8 "Foo" 9 } 10 }
  10. 1 class ScalaExampleConfiguration 2 extends FunctionalConfiguration { 3 4 val

    conference = bean() { 5 val c = new Conference("SpringCamp") 6 c.when = "2013-10-13" 7 c.where = "௏ুझ" 8 c 9 } 10 11 bean("helloService") { 12 new HelloService(conference()) 13 } 14 }
  11. 1 import org.springframework.scala.context. 2! function.FunctionalConfigApplicationContext 3 4 object HelloApp extends

    App { 5 val context = 6 FunctionalConfigApplicationContext[ScalaExampleConfiguration] 7 val helloService = context.getBean(classOf[HelloService]) 8 }
  12. 1 <plugin> 2 <groupId>net.alchim31.maven</groupId> 3 <artifactId>scala-maven-plugin</artifactId> 4 <version>3.1.6</version> 5 <executions>

    6 <execution> 7 <id>scala-compile-first</id> 8 <phase>process-resources</phase> 9 <goals> 10 <goal>add-source</goal> 11 <goal>compile</goal> 12 </goals> 13 </execution> 14 <execution> 15 <id>scala-test-compile</id> 16 <phase>process-test-resources</phase> 17 <goals> 18 <goal>testCompile</goal> 19 </goals> 20 </execution> 21 <execution> 22 <phase>process-resources</phase> 23 <goals> 24 <goal>compile</goal> 25 </goals> 26 </execution> 27 </executions> 28 </plugin>
  13. 1 class Pet { 2 private var name:String = _

    3 4 def name():String = name 5 def name_=(n:String) = name = n 6 }
  14. 1 @Controller 2 @SessionAttributes("visit") 3 public class OwnerController { 4

    @RequestMapping("/owners/{ownerId}") 5 public ModelAndView showOwner( 6 @PathVariable("ownerId") int ownerId) { 7 // .. 8 } 9 10 @RequestMapping( 11 value = "visits/new", 12 method = RequestMethod.GET) 13 public String initNewVisitForm() { 14 // .. 15 } 16 }
  15. 1 @Controller 2 @SessionAttributes(Array("visit")) 3 class OwnerController { 4 @RequestMapping(Array("/owners/{ownerId}"))

    5 def showOwner( 6 @PathVariable("ownerId") ownerId:Int) = { 7 //.. 8 } 9 10 @RequestMapping( 11 value = Array("/visits/new"), 12 method = Array(RequestMethod.GET)) 13 def initNewVisitForm = { 14 // ... 15 } 16 }
  16. 1 @Controller 2 public class VisitController { 3 4 private

    final ClinicService cs; 5 6 @Autowired 7 public VisitController(ClinicService cs) { 8 this.cs = cs; 9 } 10 }
  17. 1 object Joda { 2 implicit 3 def dateTimeOrdering: Ordering[DateTime]

    = 4 Ordering.fromLessThan(_ isBefore _) 5 } 1 import Joda._ 2 dateTimes.sorted
  18. 1 def initFindForm( 2 model: Map[String, Object] 3 ) =

    {} FSSPS PSHTQSJOHGSBNFXPSLCFBOT#FBO*OTUBOUJBUJPO&YDFQUJPO $PVMEOPUJOTUBOUJBUFCFBODMBTT <TDBMBDPMMFDUJPOJNNVUBCMF.BQ> 4QFDJGJFEDMBTTJTBOJOUFSGBDF