簡単な説明
このチュートリアルでは、主にSpringのXML構成を拡張する方法を紹介して、Springがカスタマイズされたスキーマと注釈を認識できるようにします。
ここで実装する機能は次のとおりです。まず、Springに次の構成を認識させます。
<std:annotation-endpoint />
この構成に実装する関数は、構成後、Springがカスタマイズされた@Endpoint Annotationをスキャンできることです。注釈に従ってWebServiceサービスを自動的に公開します。この機能は完全には実装されておらず、春を拡張するためのチュートリアルとして、ジェイドを引き付ける役割を果たします。
プロジェクトを作成します
まず、Javaプロジェクトを作成する必要があります。ここでは、Mavenを使用してQuickStartプロジェクト(通常のJavaプロジェクト)を作成します。
POMファイルのコンテンツは次のとおりです
<Project XMLNS = "http://maven.apache.org/pom/4.0.0" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation = "http://maven.apach/4.0. http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelversion> 4.0.0 </modelversion> <groupid> com.codestd </groupid> <artifactid> spring-cxf-annotation-support </artifactid> <バージョン> 1.0.0-snapshot </version> <name> $ {project.artifactid} </name> <説明> API侵入なしに、スプリング+CXFカプセル化に基づいて、プロジェクトが注釈を通じてWebサービスを公開できます。 </description> <url> https://github.com/codestd/spring-cxf-annotation-support </url> <ライセンス> <Name> apacheライセンス、バージョン2.0 </name> <url> http://www.apache.org/licenses/license-2.0.txt </url> </license> </licenses> <開発者> <開発者> <開発者<名> jaune(wangchengwei)</name> <メール> [email protected] </email> < /role> </roles> <timezone> gmt+8</timezone></developer> </developers> <scm> <connection>https://github.com/codestd/spring-cxf-annotation-suport.git</connection> estd/spring-cxf-annotation-support.git </developerconnection> </scm> <properties> <junit.version> 4.12 </junit.version> <spring.version> 4.2.4.release </spring.version> <cxf.version> 3.1.3 </cxf.version> </prope rties> <dependencies> <dependency> <groupid> junit </groupid> <artifactid> junit </artifactid> <version> $ {junit.version} </version> <scope> test </scope> </dependency> <依存関係> <groupid> org.springframework </gro upid> <artifactid> spring-context </artifactid> <bersion> $ {spring.version} </version> </dependency> <dependency> <expendency> <groupid> org.apache.cxf </groupid> <artifactid> cxf-rt-frontend-jaxws </artifactid> <バージョンf.version} </version> </dependency> <dependency> groupid> org.apache.cxf </groupid> <artifactid> cxf-rt-transports-http-jetty </artifactid> <バージョン> $ {cxf.version} </version> < org.springframework </groupid> <artifactid> spring-test </artifactid> <version> $ {spring.version} </version} </depence> <依存関係> log4j </groupId> <artifactid> log4j </artifactid> <バージョン> 1.2.14 </v ersion> <scope> test </scope> </dependency> <dependency> <groupid> org.slf4j </groupid> <artifactid> slf4j-log4j12 </artifactid> <バージョン>定義スキーマ
<?xml version = "1.0" encoding = "utf-8" standalone = "no"?> <xsd:schema xmlns = "http://www.codestd.com/schema/std/ws" xmlns:xsd = "http://www.w3.org/2001/xmlschema" xmlns:beans = "http://www.springframework.org/schema/beans"ターゲットネームスパックe = "http://www.codestd.com/schema/std/ws" elementformdefault = "qualified" attributeformdefault = "unaqualified"> <xsd:import namespace = "http://www.springframework.org/schema/beans"/> <xsd:annotation> <xsd:documentation> <![cdata [CXFフレームワークによって提供されるアノテーションの名前空間サポート。 ]> </xsd:ドキュメント> </xsd:annotation> <xsd:element name = "annotation-endpoint"> <xsd:complextype> <xsd:complexContent> <XSD:拡張ベース= "beans:識別タイプ"> <xsd:属性= "name" Type = "xsd:" String "" use = "optional"> <xsd:annotation> <xsd:documentation> <![cdata [name of bean。 IDのInsted]]]> </XSD:Documentation> </xsd:annotation> </xsd:属性> <xsd:属性name = "package" type = "xsd:string" use = "optional"> <xsd:annotation> <xsd:documentation> <![cdata to scan。 ]]> </xsd:ドキュメント> </xsd:annotation> </xsd:属性> </xsd:extension> </xsd:complexContent> </xsd:complextype> </xsd:element> </xsd:schema>
Sechmaに関する知識はここでは説明されません。それを使用する方法を知らない友人は、最初にそれについて学ぶ必要があります。 Sechmaの場所は、SRC/Main/Resources/Meta-INF/SCHEMA/STDWS-1.0.XSDにあります。
定義注釈
パッケージcom.codestd.spring.cxf.annotation; import java.lang.annotation.documented; import java.lang.annotation.elementtype; import java.lang.annotation.retention; import java.lang.annotation.retentionpolicy; hava.lang.nannotation.- {@code @endpoint}アノテーションをクラスに追加することによるサービス露出の目的。 * <p> SpringのBeanスキャン機能を拡張します。この注釈をBeanに追加した後、スプリングコンテナに自動的に登録されます。 *@author jaune(wangchengwei)*@since 1.0.0*/ @target(elementtype.type)@retention(retentionPolicy.runtime)@documentedpublic @interface endpoint {/***スプリングコンテナのこのエンドポイントのID* @return*/string*/service one eds the dordess on the proms of prut in serve nows exting path* 住所();}春の構成
「ウィンドウ」、「設定」、「XML」、「XMLカタログ」を開きます。 [追加]をクリックし、上記の場所で作成したXSDを選択します。 「キータイプ」という名前の名前を選択し、http://www.codestd.com/schema/std/ws/stdws-1.0.xsdにキーを入力します。つまり、Sechmaで定義されているTargetNamesSpace+ファイル名。
春に名前空間を追加し、次のようにタグを使用します。ここでは、Springの注釈スキャン機能を使用する必要があります。
<?xmlバージョン= "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-in stance "xmlns:std =" http://www.codestd.com/schema/std/ws "xsi:schemalocation =" http://www.springframew ork.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.cod estd.com/schema/std/wshttp://www.codestd.com/schema/std/ws/stdws-1.0.xsd"> <std:annotation-endpoint package = "com.codestd.spring.cxf.ws"/> </beans>
スキャンするパッケージは構成で定義されており、コンテキストを持つ構成に依存しません。
上記は、編集者が共有するSpringカスタム構成スキーマ拡張可能(1)です。私はそれが誰にでも役立つことを願っています。