标签:select 用户 缺省值 实现 body cell nts img aaa
演示样例:
<?
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <dubbo:application
name="hello-world-app"
/> <dubbo:registry
address="multicast://224.5.6.7:1234"
/> <dubbo:protocol
name="dubbo"
port="20880"
/> <dubbo:service
interface="com.alibaba.dubbo.demo.DemoService"
ref="demoServiceLocal"
/> <dubbo:reference
id="demoServiceRemote"
interface="com.alibaba.dubbo.demo.DemoService"
/></beans> |
| 全部标签者支持自己定义參数,用于不同扩展点实现的特殊配置。 |
如:
<dubbo:protocol
name="jms"></dubbo:protocol> |
或:(2.1.0開始支持)
| 注意声明:xmlns:p="http://www.springframework.org/schema/p" |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"></beans> |
Configuration Relation:

Configuration Override:
| 假设公共配置非常easy,没有多注冊中心。多协议等情况。或者想多个Spring容器想共享配置,能够使用dubbo.properties作为缺省配置。 |
| Dubbo将自己主动载入classpath根文件夹下的dubbo.properties,能够通过JVM启动參数:-Ddubbo.properties.file=xxx.properties 改变缺省配置位置。 |
| 假设classpath根文件夹下存在多个dubbo.properties,比方多个jar包中有dubbo.properties,Dubbo会随意载入。并打印Error日志,兴许可能改为抛异常。 |
映射规则:
典型配置如:
dubbo.application.name=foodubbo.application.owner=bardubbo.registry.address=10.20.153.10:9090 |

覆盖策略:
| 2.2.1以上版本号支持 |
服务提供方注解:
import
com.alibaba.dubbo.config.annotation.Service;@Service(version="1.0.0")public
class FooServiceImpl implements
FooService { // ......} |
服务提供方配置:
<!-- 公共信息。也能够用dubbo.properties配置 --><dubbo:application
name="annotation-provider"
/><dubbo:registry
address="127.0.0.1:4548"
/><!-- 扫描注解包路径。多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中全部的类 --><dubbo:annotation
package="com.foo.bar.service"
/> |
服务消费方注解:
import
com.alibaba.dubbo.config.annotation.Reference;import
org.springframework.stereotype.Component;@Componentpublic
class BarAction { @Reference(version="1.0.0") private
FooService fooService;} |
服务消费方配置:
<!-- 公共信息,也能够用dubbo.properties配置 --><dubbo:application
name="annotation-consumer"
/><dubbo:registry
address="127.0.0.1:4548"
/><!-- 扫描注解包路径,多个包用逗号分隔,不填pacakge表示扫描当前ApplicationContext中全部的类 --><dubbo:annotation
package="com.foo.bar.action"
/> |
也能够使用:(等价于前面的:<dubbo:annotation package="com.foo.bar.service" />)
<dubbo:annotation
/><context:component-scan
base-package="com.foo.bar.service"> <context:include-filter
type="annotation"
expression="com.alibaba.dubbo.config.annotation.Service"
/></context:component-scan> |
Spring2.5及以后版本号支持component-scan。假设用的是Spring2.0及曾经版本号。需配置:
|
| API属性含义參考 API属性与配置项一对一。各属性含义。请參见:配置參考手冊 (+), 比方:ApplicationConfig.setName("xxx") 相应 <dubbo:application name="xxx" /> |
import
com.alibaba.dubbo.rpc.config.ApplicationConfig;import
com.alibaba.dubbo.rpc.config.RegistryConfig;import
com.alibaba.dubbo.rpc.config.ProviderConfig;import
com.alibaba.dubbo.rpc.config.ServiceConfig;import
com.xxx.XxxService;import
com.xxx.XxxServiceImpl;// 服务实现XxxService xxxService =
new XxxServiceImpl();// 当前应用配置ApplicationConfig application =
new ApplicationConfig();application.setName("xxx");// 连接注冊中心配置RegistryConfig registry =
new RegistryConfig();registry.setAddress("10.20.130.230:9090");registry.setUsername("aaa");registry.setPassword("bbb");// 服务提供者协议配置ProtocolConfig protocol =
new ProtocolConfig();protocol.setName("dubbo");protocol.setPort(12345);protocol.setThreads(200);// 注意:ServiceConfig为重对象,内部封装了与注冊中心的连接,以及开启服务port// 服务提供者暴露服务配置ServiceConfig<XxxService> service =
new ServiceConfig<XxxService>();
// 此实例非常重,封装了与注冊中心的连接,请自行缓存,否则可能造成内存和连接泄漏service.setApplication(application);service.setRegistry(registry);
// 多个注冊中心能够用setRegistries()service.setProtocol(protocol);
// 多个协议能够用setProtocols()service.setInterface(XxxService.class);service.setRef(xxxService);service.setVersion("1.0.0");// 暴露及注冊服务service.export(); |
import
com.alibaba.dubbo.rpc.config.ApplicationConfig;import
com.alibaba.dubbo.rpc.config.RegistryConfig;import
com.alibaba.dubbo.rpc.config.ConsumerConfig;import
com.alibaba.dubbo.rpc.config.ReferenceConfig;import
com.xxx.XxxService;// 当前应用配置ApplicationConfig application =
new ApplicationConfig();application.setName("yyy");// 连接注冊中心配置RegistryConfig registry =
new RegistryConfig();registry.setAddress("10.20.130.230:9090");registry.setUsername("aaa");registry.setPassword("bbb");// 注意:ReferenceConfig为重对象。内部封装了与注冊中心的连接,以及与服务提供方的连接// 引用远程服务ReferenceConfig<XxxService> reference =
new ReferenceConfig<XxxService>();
// 此实例非常重,封装了与注冊中心的连接以及与提供者的连接,请自行缓存。否则可能造成内存和连接泄漏reference.setApplication(application);reference.setRegistry(registry);
// 多个注冊中心能够用setRegistries()reference.setInterface(XxxService.class);reference.setVersion("1.0.0");// 和本地bean一样使用xxxServiceXxxService xxxService = reference.get();
// 注意:此代理对象内部封装了全部通讯细节,对象较重,请缓存复用 |
注:以下仅仅列出不同的地方,其他參见上面的写法
...// 方法级配置List<MethodConfig> methods =
new ArrayList<MethodConfig>();MethodConfig method =
new MethodConfig();method.setName("createXxx");method.setTimeout(10000);method.setRetries(0);methods.add(method);// 引用远程服务ReferenceConfig<XxxService> reference =
new ReferenceConfig<XxxService>();
// 此实例非常重,封装了与注冊中心的连接以及与提供者的连接,请自行缓存。否则可能造成内存和连接泄漏...reference.setMethods(methods);
// 设置方法级配置... |
...ReferenceConfig<XxxService> reference =
new ReferenceConfig<XxxService>();
// 此实例非常重,封装了与注冊中心的连接以及与提供者的连接。请自行缓存,否则可能造成内存和连接泄漏// 假设点对点直连,能够用reference.setUrl()指定目标地址,设置url后将绕过注冊中心,// 当中,协议相应provider.setProtocol()的值。port相应provider.setPort()的值,// 路径相应service.setPath()的值,假设未设置path。缺省path为接口名reference.setUrl("dubbo://10.20.130.230:20880/com.xxx.XxxService");
... |
标签:select 用户 缺省值 实现 body cell nts img aaa
原文地址:http://www.cnblogs.com/yangykaifa/p/6806466.html