1、基于Java 的service接口和实现组件的Java类
接口
packageservices.hello;
publicinterfaceHelloService{
Stringhello(Stringmessage);
}
publicinterfaceHelloService{
Stringhello(Stringmessage);
}
实现
packageservices.hello;
importorg.osoa.sca.annotations.*;
@Service(HelloService.class)
publicclassHelloServiceImplimplementsHelloService{
publicStringhello(Stringmessage){
...
}
}
importorg.osoa.sca.annotations.*;
@Service(HelloService.class)
publicclassHelloServiceImplimplementsHelloService{
publicStringhello(Stringmessage){
...
}
}
对应的Componet Type
<?xmlversion="1.0"encoding="ASCII"?>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
</componentType>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
</componentType>
2、自己定义的service接口并实现的Java 实现类
packageservices.hello;
importorg.osoa.sca.annotations.*;
@Service(HelloServiceImpl.class)
publicclassHelloServiceImplimplementsAnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
importorg.osoa.sca.annotations.*;
@Service(HelloServiceImpl.class)
publicclassHelloServiceImplimplementsAnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
根据@service注解的默认规则:如果一个service只有一个接口,实现了接口就是实现了service。
所以上面的实现还可以改写,如下:
packageservices.hello;
publicclassHelloServiceImplimplementsAnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
publicclassHelloServiceImplimplementsAnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
对应的Component Type
<?xmlversion="1.0"encoding="ASCII"?>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloServiceImpl"/>
</service>
</componentType>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloServiceImpl"/>
</service>
</componentType>
3、一个Java实现类实现两个service
packageservices.hello;
importorg.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class,AnotherInterface.class})
publicclassHelloServiceImplimplementsHelloService,AnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
importorg.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class,AnotherInterface.class})
publicclassHelloServiceImplimplementsHelloService,AnotherInterface{
publicStringhello(Stringmessage){
...
}
…
}
对应的Component Type
<?xmlversion="1.0"encoding="ASCII"?>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
<servicename="AnotherService">
<interface.javainterface="services.hello.AnotherService"/>
</service>
</componentType>
<componentTypexmlns=http://www.osoa.org/xmlns/sca/1.0>
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
<servicename="AnotherService">
<interface.javainterface="services.hello.AnotherService"/>
</service>
</componentType>
4、Java实现类通过接口子类关系实现两个service
service 1
packageservices.hello;
publicinterfaceHelloService{
Stringhello(Stringmessage);
}
publicinterfaceHelloService{
Stringhello(Stringmessage);
}
service 2
packageservices.hello;
publicinterfaceHelloService2extendsHelloService{
}
publicinterfaceHelloService2extendsHelloService{
}
实现
packageservices.hello;
importorg.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class,HelloService2.class})
publicclassHelloServiceImplimplementsHelloService{
publicStringhello(Stringmessage){
...
}
}
importorg.osoa.sca.annotations.*;
@Service(interfaces={HelloService.class,HelloService2.class})
publicclassHelloServiceImplimplementsHelloService{
publicStringhello(Stringmessage){
...
}
}
对应Component Type
<?xmlversion="1.0"encoding="ASCII"?>
<componentTypexmlns="http://www.osoa.org/xmlns/sca/1.0">
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
<servicename="HelloService2">
<interface.javainterface="services.hello.HelloService2"/>
</service>
</componentType>
<componentTypexmlns="http://www.osoa.org/xmlns/sca/1.0">
<servicename="HelloService">
<interface.javainterface="services.hello.HelloService"/>
</service>
<servicename="HelloService2">
<interface.javainterface="services.hello.HelloService2"/>
</service>
</componentType>