SCA中Java接口实现Service

1、基于Java 的service 接口和实现组件的Java类 

 接口

package  services.hello;
public   interface  HelloService {
    String hello(String message);
}

实现

package  services.hello;
import  org.osoa.sca.annotations. * ;
@Service(HelloService.
class )
public   class  HelloServiceImpl  implements  HelloService {
     
public  String hello(String message) {
          ...
     }
}

对应的Componet Type

<? xml version="1.0" encoding="ASCII" ?>
< componentType  xmlns =http://www.osoa.org/xmlns/sca/1.0 >
       
< service  name ="HelloService" >
               
< interface .java interface ="services.hello.HelloService" />
       
</ service >
</ componentType >

2、自己定义的service接口并实现的Java 实现类

package  services.hello;
import  org.osoa.sca.annotations. * ;
@Service(HelloServiceImpl.
class )
public   class  HelloServiceImpl  implements  AnotherInterface {
    
public  String hello(String message) {
        ...
    }
    …
}

根据@service注解的默认规则:如果一个service只有一个接口,实现了接口就是实现了service。
所以上面的实现还可以改写,如下:

package  services.hello;
public   class  HelloServiceImpl  implements  AnotherInterface {
    
public  String hello(String message) {
        ...
    }
    …
}

对应的Component Type

<? xml version="1.0" encoding="ASCII" ?>
< componentType  xmlns =http://www.osoa.org/xmlns/sca/1.0 >
    
< service  name ="HelloService" >
        
< interface .java interface ="services.hello.HelloServiceImpl" />
    
</ service >
</ componentType >

3、一个Java实现类实现两个service

package  services.hello;
import  org.osoa.sca.annotations. * ;
@Service(interfaces
= {HelloService. class , AnotherInterface. class })
public   class  HelloServiceImpl  implements  HelloService, AnotherInterface {
    
public  String hello(String message) {
        ...
    }
    …
}

对应的Component Type

<? xml version="1.0" encoding="ASCII" ?>
< componentType  xmlns =http://www.osoa.org/xmlns/sca/1.0 >
    
< service  name ="HelloService" >
        
< interface .java interface ="services.hello.HelloService" />
    
</ service >
    
< service  name ="AnotherService" >
        
< interface .java interface ="services.hello.AnotherService" />
    
</ service >
</ componentType >

4、Java实现类通过接口子类关系实现两个service

service 1

package  services.hello;
public   interface  HelloService {
     String hello(String message);
}

service 2

package  services.hello;
public   interface  HelloService2  extends  HelloService {
}

实现

package  services.hello;
import  org.osoa.sca.annotations. * ;
@Service(interfaces
= {HelloService. class ,HelloService2. class })
public   class  HelloServiceImpl  implements  HelloService {
    
public  String hello(String message) {
        ...
    }
}

对应Component Type

<? xml version="1.0" encoding="ASCII" ?>
< componentType  xmlns ="http://www.osoa.org/xmlns/sca/1.0" >
    
< service  name ="HelloService" >
        
< interface .java interface ="services.hello.HelloService" />
    
</ service >
    
< service  name ="HelloService2" >
        
< interface .java interface ="services.hello.HelloService2" />
    
</ service >
</ componentType >
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值