More Related Content Similar to Spring Scala : 스프링이 스칼라를 만났을 때 (20) More from JeongHun Byeon (20) Spring Scala : 스프링이 스칼라를 만났을 때4. 이 발표에서는
- 스프링 스칼라가 어떤 기능을 지원하는가?
- 실제로 스칼라에서 스프링을 사용할 때는
어떤 이슈가 있는가?
10. 스프링 스칼라
스칼라 클래스를 스프링 빈으로 연결
스프링 템플릿을 함수형식으로 사용
스칼라의 컬렉션을 의존성 주입
JavaConfig를 ScalaConfig
12. 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 }
15. 1 class Person {
2
var name:String = _
3
4
def name():String = name
5
def name_=(n:String) = name = n
6 }
16. 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 }
27. 1 RestTemplate restTemplate = new RestTemplate();
2
3 String result = restTemplate
4
.getForObject(
5
"http://example.com",
6
String.class);
28. 1 val restTemplate = new RestTemplate()
2
3 val result = restTemplate
4
.getForAny[String]
5
("http://example.com")
36. 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 }
41. 스프링 스칼라가 해주는 일은 극히 일부다
http://www.flickr.com/photos/lenore-m/459508939/
44. 스칼라 라이브러리 추가
1 <dependencies>
2 <dependency>
3
<groupId>org.scala-lang</groupId>
4
<artifactId>scala-library</artifactId>
5
<version>2.10.1</version>
6 </dependency>
7 </dependencies>
49. 1 class Pet {
2
private var name:String = _
3
4
def name():String = name
5
def name_=(n:String) = name = n
6 }
50. 1 Pet pet = new Pet();
2 pet.name_$eq(“Dog”);
3 String n = pet.name();
54. 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 }
58. [WARNING] warning: Class
org.joda.convert.FromString not found continuing with a stub.
[WARNING] warning: Caught:
java.lang.NullPointerException
while parsing annotations in joda-time-2.3.jar
(org/joda/time/DateTime.class)
[ERROR] error: error while loading DateTime,
class file 'joda-time-2.3.jar
(org/joda/time/DateTime.class)' is broken
62. 1 object Joda {
2
implicit
3
def dateTimeOrdering: Ordering[DateTime] =
4
Ordering.fromLessThan(_ isBefore _)
5 }
1 import Joda._
2 dateTimes.sorted
71. 1 def initFindForm(
2
model: Map[String, Object]
3 ) = {}
error:
org.springframework.beans.BeanInstantiationException:
Could not instantiate bean class
[scala.collection.immutable.Map]:
Specified class is an interface
74. - 스칼라로 스프링을 사용할 수 있다
- 스프링는 검증된 프레임워크이므로
통합하고 나면 쓸만해 보인다
- 이슈는 있지만 타입오류나 자바와
스칼라의 모양이 다른 작은 이슈들이다
- 레퍼런스는 거의 없으므로 이슈는
직접 해결해야 한다