SCA 之Tuscany 5 ——helloworld Spring Bean
2011-10-10 15:56
447 查看
可通过这篇文章得到更加详实的信息:http://tuscany.apache.org/sca-java-implementationspring.html
可参照本文完成简单的应用demo一、可以说,Spring和Tuscany都是面向接口来编程的。
接口必须提供下面的两条信息:(1)内容:有哪些操作,需要什么参数
(2)访问的方式:SCA,Web,JMS,Session Bean还是其他
在SCA里,服务的提供方式用绑定来描述。binding.sca是sca的默认绑定模式。
spring利用依赖注入,对不同的访问方式有JMS template 和spring data bus等。
在依赖注入这一点上,sca和spring有共同点。Tuscany也是使用了依赖注入的方式。
在Spring里,有很多概念和SCA里的composite是对应的:
1.context对应composite
2.bean对应component
3.bean的接口对应service
4.bean实现类对应sca实现类
二者之间可以相互的引用:
后面给出一个Tuscany中使用spring的例子。
在spring中使用sca可借助在application-context.xml中使用sca的扩展标记完成。
如:
<sca:reference name="stockQuoteService" type="bigbank.stockquote.StockQuoteService"/>
为了能够支持标签,需要添加域名空间:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sca="http://www.springframework.org/schema/sca" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd">
二、Tuscany中使用spring
composite写法:<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" targetNamespace="http://sample" name="helloworld-contribution"> <component name="HelloworldComponent"> <implementation.spring location="helloworld-context.xml"/> </component> </composite>
spring bean
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca-j/spring/200810" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/sca http://www.osoa.org/xmlns/sca/1.0/spring-sca.xsd"> <sca:service name="HelloworldService" target="HelloworldBean"/> <bean id="HelloworldBean" class="sample.HelloworldImpl"> </bean> </beans>
接口:
package sample; import org.oasisopen.sca.annotation.Remotable; @Remotable public interface Helloworld { String sayHello(String name); }
实现类:
package sample; public class HelloworldImpl implements Helloworld { public String sayHello(String name) { return "Hello " + name; } }pom文件的支持:
<dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-implementation-spring-runtime</artifactId> <version>${tuscany.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <!-- to support running the composite with mvn tuscany:run --> <plugin> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-maven-plugin</artifactId> <version>${tuscany.version}</version> <dependencies> <dependency> <groupId>org.apache.tuscany.sca</groupId> <artifactId>tuscany-implementation-spring-runtime</artifactId> <version>${tuscany.version}</version> </dependency> </dependencies> </plugin> </plugins> </build>
整体:
相关文章推荐
- SCA 之Tuscany 2 ——helloworld JAX-RS
- SCA 之Tuscany 3 ——helloworld WebApp
- SCA 之Tuscany 4 ——helloworld Webservice
- SCA 之Tuscany 6 ——helloworld SCA Client
- SCA 之Tuscany 7 ——helloworld use ZIP format contributions
- SCA 之Tuscany 9 ——helloworld JMS binding
- Eclipse搭建SpringBoot之HelloWorld
- Spring Data MongoDB hello world example
- Eclipse使用maven搭建简单spring boot application Hello World
- Spring 3 MVC hello world example
- Spring 4 MVC HelloWorld 纯注解方式(带源码)
- Gradle – Spring 4 MVC Hello World Example – Annotation
- Spring 3 MVC: Create Hello World Application In Spring 3.0 MVC
- SpringBoot学习之hello world
- SpringBoot HelloWorld
- spring mvc helloworld
- SpringBoot HelloWorld实现
- spring helloworld
- Spring Boot——2分钟构建spring web mvc REST风格HelloWorld
- spring helloworld