1、基于Java 的service 接口和实现组件的Java类
接口
package
services.hello;
public interface HelloService {
String hello(String message);
}
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) {
...
}
}
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 >
< 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) {
...
}
…
}
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) {
...
}
…
}
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 >
< 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) {
...
}
…
}
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 >
< 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);
}
public interface HelloService {
String hello(String message);
}
service 2
package
services.hello;
public interface HelloService2 extends HelloService {
}
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) {
...
}
}
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 >
< 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 >