dubbo.properties
dubbo.container=log4j,spring
dubbo.application.name=hello-core-service
dubbo.application.owner=coret
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=56432
dubbo.service.loadbalance=roundrobin
dubbo.spring.config=classpath:provider.xml
#dubbo.jetty.port=8080 ----配置jetty启动端口
#dubbo.jetty.directory=/foo/bar ----配置可通过jetty直接访问的目录,用于存放静态文件
#dubbo.jetty.page=log,status,system ----配置显示的页面,缺省加载所有页面
#dubbo.log4j.file=/foo/bar.log ----配置日志文件路径
dubbo.log4j.level=info ----配置日志级别
#dubbo.log4j.subdirectory=20880 ----配置日志子目录,用于多进程启动,避免冲突
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dubbo-demo</artifactId>
<groupId>com.chinanetcenter.wcs</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>provider</artifactId>
<dependencies>
<dependency>
<groupId>com.chinanetcenter.wcs</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.56.Final</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.42</version>
</dependency>
</dependencies>
</project>
provider.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
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-provider" />
<!-- 使用注册中心暴露服务地址 -->
<dubbo:registry address="zookeeper://localhost:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" server="netty4" serialization="kryo"/>
<!-- 没有服务也能启动 -->
<dubbo:consumer check="false" />
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.chinanetcenter.wcs.DemoService" ref="demoService" />
<!-- 和本地bean一样实现服务 -->
<bean id="demoService" class="com.chinanetcenter.wcs.DemoServiceImpl" />
</beans>
consumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
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="consumer-of-helloworld-app" />
<!-- 使用注册中心暴露发现服务地址 -->
<dubbo:registry address="zookeeper://localhost:2181" />
<!-- 生成远程服务代理,其中id属性值为实现服务接口类的beanId -->
<dubbo:reference id="demoService" interface="com.chinanetcenter.wcs.DemoService" />
</beans>