Scala可以与服务组件架构一起使用吗?

时间:2011-03-10 22:02:14

标签: scala sca

有人知道Scala是否可以与SCA(服务组件架构)开源实现(如Fabric3或Apache Tuscany)一起使用?我在网上找不到这样的信息。我知道Scala编译成Java,但我想知道依赖注入是否会使事情复杂化。谢谢。

1 个答案:

答案 0 :(得分:1)

FraSCAti平台已经支持Scala作为SCA组件的实现语言。您可以查看following example

@Service
trait PrintService {
    def print(msg: String)
}

class Server extends PrintService {    
    println("SERVER created.")

    @Property protected var header = "->"
    @Property private var count = 1

    /** PrintService implementation. */
    def print(msg: String) {
        println("Server: begin printing...")
        for (i <- 0 until count)
            println(header + msg)
        println("Server: print done.")
    }        
}

@Service(classOf[Runnable])
class Client extends Runnable {
    println("CLIENT created")

    @Reference(required = true) private var service: PrintService = _
    def setPrintService(s: PrintService) { service = s }

    // Runnable interface implementation
    def run = service print "hello world"
}

存储库中的示例还说明了如何使用bean来实现这些组件。