【问题标题】:Can Scala be used with Service Component Architecture?Scala 可以与服务组件架构一起使用吗?
【发布时间】:2011-07-13 02:15:33
【问题描述】:

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

【问题讨论】:

    标签: scala sca


    【解决方案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 来实现这些组件。

    【讨论】:

      猜你喜欢
      • 2014-04-20
      • 2014-12-25
      • 2015-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多