分散型プロジェクト第一に考えたのは、複数のインタフェース・コール・サービスとの間でデータを転送後、どのように問題にされ、
1、2つのサービス、コントローラ、サービスを作成します
使用されるサービス実装クラスのアノテーションレイヤサービス、アリババがある JDKありません
層//サービスクラス
パッケージcom.ghh.service; インポートcom.alibaba.dubbo.config.annotation.Service; @Service パブリック クラス TestServiceImpl 実装TestService { @Override パブリック文字列のgetName(){ 戻り「ジョン・ドウ」; } }
//インタフェース
パブリックインターフェースTestService {
パブリック文字列のgetName()。
}
//サービス服务的applicationContext.xmlを配置文件
<?xmlのバージョン= "1.0"エンコード= "UTF-8"> <豆のxmlns = "http://www.springframework.org/schema/beans" のxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance"のxmlns:P = "http://www.springframework.org/schema/p" のxmlns:コンテキスト = "http://www.springframework.org /スキーマ/コンテキスト" のxmlns:ダボ = "http://code.alibabatech.com/schema/dubbo"のxmlns:MVC = "http://www.springframework.org/schema/mvc" のxsi:schemaLocationの ="のhttp: //www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ます。http:// www.springframework。ORG /スキーマ/ MVChttp://www.springframework.org/schema/mvc/spring-mvc.xsd HTTP:// code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd HTTP :// www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <ダボ:ファイルのアプリケーション名=" dubbodemo -サービス「/> <! -ポートの接続設定- > <ダボ:レジストリアドレス= "のZooKeeper://192.168.200.128:2181" /> // ZooKeeperの上の仮想マシンのアドレス < -注釈付きサービススキャニング、zeekooper登録します!レジストリ- > <ダボ:注釈のためのパッケージ変更 = "com.ghh" /> </豆>
web.xmlファイル//サービスサービス
<xmlのバージョン= "1.0"エンコード= "UTF-8"?>
の<web-appのxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance"
のxmlns = "のhttp:// javaのsun.comの/ XML / NS / JavaEEの"
XSI:のschemaLocation =" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5 .xsd」
バージョン= "2.5">
<! -加载春容器- >
<コンテキスト-param>の
の<param-name>のcontextConfigLocation </ PARAM名>
の<param-value>のクラスパス:ApplicationContextの* .xmlの</ PARAM -value>
</コンテキスト-param>の
<リスナー>
<リスナクラス> org.springframework.web.context.ContextLoaderListener </リスナクラス>
</リスナー>
</ web-app>の
2、コントローラサービス
@Reference // アリババさんのコメントを使用して、いないJDK
@RestController @RequestMapping( "/テスト" ) パブリック クラスTestController { @Reference プライベートTestService testService。 (@RequestMapping "/のgetName" ) パブリック文字列のgetName(){ System.out.printlnは( "123" )。 文字列名 = testService.getName()。 リターン名。 } @RequestMapping( "/ ME" ) パブリック文字列名(){ リターン "张三" 。 } }
ここで、私は、私はコントローラ案内サービスサービスサービスへのダイレクトインタフェース、ダイレクトコールサービス、サービスパックの瓶をインポートする必要はありません
コントローラサービスのApplicationContext-web.xmlの
<?xmlのバージョン= "1.0"エンコード= "UTF-8"> <豆のxmlns = "http://www.springframework.org/schema/beans" のxmlns:XSI = "http://www.w3.org / 2001 / XMLスキーマ・インスタンス"のxmlns:P = "http://www.springframework.org/schema/p" のxmlns:コンテキスト = "http://www.springframework.org/schema/context" のxmlns:ダボ =" http://code.alibabatech.com/schema/dubbo "のxmlns:MVC = "http://www.springframework.org/schema/mvc" のxsi:schemaLocationの =" http://www.springframework.org/schema/豆http://www.springframework.org/schema/beans/spring-beans.xsd ます。http:// www.springframework.org/schema/mvc ます。http://www.springframework。ORG /スキーマ/ MVC /春-mvc.xsd ます。http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd HTTP:// www.springframework.org/schema/context http://www.springframework.org/schema /context/spring-context.xsd 「> <! -注釈運転- > <MVC:注釈駆動型> <! - 、歪みの中国をUTF-8エンコードされた文字列へのキャスト伝送へのを防ぐために- > < MVC:メッセージの登録-デフォルト= "falseに"コンバータ> <豆のクラス = "org.springframework.http.converter.StringHttpMessageConverter"> <コンストラクタ-Argの値= "UTF-8" /> </豆> </ MVC:コンバータ・メッセージ> </ MVC:ドリブン・注釈> <! -名前から現在のプロジェクトサービスへ- > <ダボ:ファイルのアプリケーション名= "dubboxdemo-ウェブ" /> < -接続の構成zookepper! - > <ダボ:レジストリアドレス= "のZooKeeper://192.168.200.128:2181" /> <! -スキャン構成パッケージ、のみ、このパッケージでのみの下、サービスを注入することができます- > <ダボ:アノテーションパッケージ =「com.ghh」/> </豆>
//コントローラ服务的web.xmlの文件
の<?xml version = "1.0"エンコード= "UTF-8"?> の<web-appのxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance " のxmlns =" http://java.sun.com/xml/ns/javaee " のxsi:schemaLocationの =" http://java.sun.com/xml/ns/javaee http://java.sun.com/ XML / NS / JavaEEの/ WEB-app_2_5.xsd」 バージョン = "2.5"> <! -解决ポスト乱码- > <フィルタ> <フィルタ名> CharacterEncodingFilter </フィルタ名> <フィルタ- クラス >組織。 springframework.web.filter.CharacterEncodingFilter </フィルタ- クラス > の<init-param>の の<param-name>のエンコーディング</ PARAM名> の<param-value>は、UTF-8 </ PARAM値> </ INIT-param>の の<init-param>の <PARAM名> forceEncoding </ PARAM名> の<param-value>は真 </ PARAM値> </ INIT-param>の </フィルタ> <フィルタマッピング> <フィルタ名> CharacterEncodingFilter </フィルタ名> の<url-pattern> / * </のurl-pattern> </のfilter-mapping> <! -配置springMvc前端控制器- > の<servlet> の<servlet-name>のspringmvc </サーブレット-name> の<servlet-class>のorg.springframework.web.servlet.DispatcherServlet </サーブレットクラス> <! -指定加载的配置文件、通过参数contextConfigLocation加载- > の<init-param>の <PARAM名> contextConfigLocation </ PARAM名> の<param-value>のクラスパス:ApplicationContextの-web.xmlの</ PARAM値> </ initの-param>の </サーブレット> の<servlet-mapping>は <サーブレット名> springmvc </サーブレット名> の<url-pattern> / </のurl-pattern> </サーブレット-mapping> </ web-app>の
3、要約
ダボ飼育係の+実現は、各サービスは、アリババのコメント@serviceを通じてサービスに登録された飼育係飼育係、@Referenceノートを介してコントローラ、飼育係からサービスを取得するためのプロキシクラスオブジェクトに登録されています
2つのサービス・インターフェース呼び出し間の相互サービスコールを達成するために。