日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dubbo项目搭建

發布時間:2024/5/14 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dubbo项目搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

建立Dubbo-client

建立一個maven-archetype-quickstart工程
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"><modelVersion>4.0.0</modelVersion><groupId>com.xxx</groupId><artifactId>dubbo-client</artifactId><version>1.0-SNAPSHOT</version><name>dubbo-client</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target></properties><dependencies><dependency><groupId>com.taotao</groupId><artifactId>first-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.4</version></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.12</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.0.1</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies></project>

App.java

public static void main( String[] args ){ClassPathXmlApplicationContext context =new ClassPathXmlApplicationContext("dubbo-client.xml");ISumService sumService = (ISumService) context.getBean("sumService");System.out.println("3+4="+sumService.sum(3,4));}

dubbo-client.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:application name="dubbo-client" owner="lyj"/><dubbo:registry address="zookeeper://192.168.67.128:2181"/><dubbo:protocol name="dubbo" port="20880"/><dubbo:reference id="sumService" interface="com.taotao.ISumService"/> </beans>

server端

建立兩個子模塊 api和provider
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"><modelVersion>4.0.0</modelVersion><groupId>com.taotao</groupId><artifactId>do-dubboserver</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>first-api</module><module>first-provider</module></modules><name>do-dubboserver</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target></properties><dependencies><dependency><groupId>com.alibaba</groupId><artifactId>dubbo</artifactId><version>2.6.4</version></dependency><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.12</version></dependency><dependency><groupId>org.apache.curator</groupId><artifactId>curator-framework</artifactId><version>4.0.1</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies></project>

api 的接口

public interface ISumService {Integer sum(Integer a,Integer b); }

provider

public class SumService implements ISumService {@Overridepublic Integer sum(Integer a, Integer b) {return a+b;} } public class App {public static void main( String[] args ) throws IOException {ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("dubbo-server.xml");context.start();System.in.read();} }

dubbo-server.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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><dubbo:application name="dubbo-provider" owner="lyj"/><dubbo:registry address="zookeeper://192.168.67.128:2181"/><dubbo:protocol name="dubbo" port="20880"/><dubbo:service interface="com.taotao.ISumService" ref="sumService"/><bean name="sumService" class="com.taotao.service.SumService"/></beans>

總結

以上是生活随笔為你收集整理的dubbo项目搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。