SpringSource社区近日推出了Spring Scala项目,该项目的目标是使开发者可以更容易地在Scala中使用Spring框架。
目前Spring Scala项目主要致力于:
1. 使用Spring Beans来配置、注入Scala类,你可以使用传统形式的XML,也可以使用Scala
例如,有一个Scala类:
Scala代码
class Person(val firstName: String, val lastName: String)
可以这样来配置,使用c命名空间:
Xml代码
<bean id="person" class="Person" c:firstName="John" c:lastName="Doe"/>
2. 提供了对Scala友好的Spring模板,如SimpleJdbcTemplate、JmsTemplate、RestTemplate和TransactionTemplate等。例如,使用JmsTemplate模板:
Scala代码
val connectionFactory : ConnectionFactory = ...
val template = new JmsTemplate(connectionFactory)
template.send("queue") {
session: Session => session.createTextMessage("Hello World")
}
template.receive("queue") match {
case Some(textMessage: TextMessage) => println(textMessage.getText)
case None => println("No text message received")
}
Spring Scala目前还是一个进展中的项目,开发团队称未来几个月内将提供更加完善的功能。
来源:http://blog.springsource.org/2012/12/10/introducing-spring-scala/