1

Does anyone know if Scala can be used with SCA (Service Component Architecture) open source implementations such as Fabric3 or Apache Tuscany? I found no such information online. I know Scala compiles to Java, but I was wondering if dependency injection would complicate things. Thanks.

4

1 回答 1

1

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

@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 来实现这些组件。

于 2011-03-11T08:20:52.813 回答