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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Dubbo-Dependency

發(fā)布時間:2024/4/13 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Dubbo-Dependency 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Dubbo - 當(dāng)當(dāng)網(wǎng)?

public interface DependencyService {public String dependency() throws Exception; } import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import bhz.dubbo.dependency.provider.DependencyService; import bhz.dubbo.sample.provider.SampleService; @Service("dependencyServiceImpl") @com.alibaba.dubbo.config.annotation.Service(interfaceClass=com.dubbo.dependency.provider.DependencyService.class, protocol={"dubbo"}, retries=0) public class DependencyServiceImpl implements DependencyService {//注入SampleService@Autowiredprivate SampleService sampleService;public String dependency() throws Exception {//這里 我們可能需要調(diào)用SampleService,也可能不需要...System.out.println(sampleService.sayHello("jack"));return "dependency exec";}}

啟動時檢查?

<?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:annotation package="com" /><!-- 提供方應(yīng)用信息,用于計算依賴關(guān)系 --><dubbo:application name="dependency-provider" /><!-- 使用zookeeper注冊中心暴露服務(wù)地址 --><dubbo:registry address="zookeeper://localhost:2181" /><!-- 用dubbo協(xié)議在20880端口暴露服務(wù) --><dubbo:protocol name="dubbo" port="20890" /><!-- 注意這里,我們在使用DependencyService的時候,這個服務(wù)可能需要依賴某一個服務(wù),比如SampleService 檢查級聯(lián)依賴關(guān)系 默認(rèn)為true 當(dāng)有依賴服務(wù)的時候,需要根據(jù)需求進行設(shè)置 --><dubbo:reference id="sampleService" check="true"interface="com.dubbo.sample.provider.SampleService" /></beans> import org.springframework.context.support.ClassPathXmlApplicationContext;public class Provider {public static void main(String[] args) throws Exception {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "sample-provider.xml" });context.start(); System.in.read(); // 為保證服務(wù)一直開著,利用輸入流的阻塞來模擬} } import org.springframework.context.support.ClassPathXmlApplicationContext;public class Provider {public static void main(String[] args) {try {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "dependency-provider.xml" });context.start();System.in.read(); // 為保證服務(wù)一直開著,利用輸入流的阻塞來模擬} catch (Exception e) {e.printStackTrace();}} } import org.springframework.context.support.ClassPathXmlApplicationContext;import bhz.dubbo.dependency.provider.DependencyService;public class Consumer {public static void main(String[] args) throws Exception {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "dependency-consumer.xml" });context.start();DependencyService dependencyService = (DependencyService) context.getBean("dependencyService");//調(diào)用該服務(wù)System.out.println(dependencyService.dependency());System.in.read();}}

?

總結(jié)

以上是生活随笔為你收集整理的Dubbo-Dependency的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。