Kurze Beschreibung
In diesem Tutorial wird hauptsächlich eingeführt, wie die XML -Konfiguration von Spring erweitert wird, damit der Frühling unser angepasendes Schema und Annotation erkennen kann.
Die Funktionen, die wir hier implementieren möchten, sind wie folgt: Erstens erkennen Spring die folgende Konfiguration.
<std: Annotation-Endpoint />
Die in dieser Konfiguration implementierte Funktion ist, dass Spring nach der Konfiguration unsere angepasste @endpoint -Annotation scannen kann. Und automatisch veröffentlichen WebService -Dienste gemäß den Anmerkungen. Die Funktion ist nicht vollständig implementiert und spielt als Tutorial für die Verlängerung des Frühlings eine Rolle bei der Anziehung von Jade.
Ein Projekt erstellen
Zunächst müssen Sie ein Java -Projekt erstellen, und hier verwenden Sie Maven, um ein QuickStart -Projekt (normales Java -Projekt) zu erstellen.
Der POM -Dateiinhalt ist wie folgt
<project xmlns = "http://maven.apache.org/pom/4.0.0" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion> 4.0.0 </modelversion> <gruppe> com.codestd </Groupid> <artifactid> Spring-CXF-Annotation-Support </artifactId> <version> 1.0.0-Snapshot </Version> <name> $ {project.artifactid} </name> <beschreibung> Ermöglicht Ihrem Projekt, Webservice durch Annotationen zu veröffentlichen, basierend auf der Spring+CXF -Kapselung, ohne API -Eindringen. </Beschreibung> <URL> https://github.com/codestd/spring-cxf-notation-support </url> <ciceszen> <lizenz> <name> Die Apache-Lizenz, Version, Version, Version, Version, Version, Version, Version, Version 2.0 </name> <URL> http://www.apache.org/licenses/license-2.0.txt </url> </lizenz> </lizenzen> <entwickler> <entwicklers> <name> jaune (Wangchengwei) </name> <Email> [email protected] </E-Mails> <rolle> < /role></roles><TimeZone>gmt+8</timezone></developer></developer><Scm><Connection>https://github.com/codestd/spring-cxf-NOnotation-support.git</connection><Developy 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> </prise rties> <depeopcies> <depeaponcy> <GroupID> junit </GroupId> <artifactID> junit </artifactID> <version> $ {junit.version} </Version> <Schope> test </scope> </abhängig> <abhängigkeit> <gruppe> org.springFrameWork </goo upid> <artifactId> Spring-Context </artifactId> <version> $ {Spring.version} </Version> </abhängig> <depeopecy> <Groupid> org.apache.cxf </Groupid> <artifactId> cxf-rt-frontend-jaxws </artifactid> $ {cx {cx {cx {cx {cx {cx {cx) {{cx f.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>${cxf.version}</version></dependency><dependency><groupId> org.springFramework </Groupid> <artifactID> Spring-Test </artifactId> <version> $ {Spring.version} </Version> </abhängig> <depectIncy> <gruppe> log4j </GroupID> <artifactid> log4j </artifactID> <version> 1.2.14 </v ERSION> <SCOPE> Test </Scope> </abhängig> <depeopcy> <gruppe> org.slf4j </GroupID> <artifactID> SLF4J-log4j12 </artifactID> <version> 1.7.7 </Version> <Schope> test </scope> </abhängig> </project>Definitionsschema
<? xmlns: xsd = "http://www.w3.org/2001/xmlschema" xmlns: beans = "http://www.springframework.org/schema/beans" TargetnameSpac e = "http://www.codestd.com/schema/std/ws" elementFormdefault = "qualifiziert" AttributeFormdefault = "unqualifiziert"> <xsd: Import Namespace = "http://www.springframework.org/schema/beans"/> <xsd: Annotation> <xsd: documentation> <! [CDATA [Namespace -Unterstützung für die Annotation, die nach CXF -Framework bereitgestellt wird. ]]> </xsd: documentation> </xsd: Annotation> <xsd: element name = "Annotation-Endpoint"> <xsd: complexType> <xsd: complexContent> <xsd: Erweiterung Basis = "Beans: identifiziert"> <xsd: Attribute name = "type" type "xsd: String: String". Verwendung = "Optional"> <xsd: Annotation> <xsd: Dokumentation> <! [CDATA [Name von Bean. Eingeleitet von ID]]> </xsd: Dokumentation> </xsd: Annotation> </xsd: Attribut> <xsd: Attribut name = "paket" type = "xsd: string" use = "optional"> <xsd: Annotation> <xsd: documentation> <! [Cdata [paKeAge, scan. ]]> </xsd: Dokumentation> </xsd: Annotation> </xsd: Attribut> </xsd: Erweiterung> </xsd: complexContent> </xsd: complexType> </xsd: element> </xsd: schema>
Das Wissen über Sechma wird hier nicht beschrieben. Freunde, die nicht wissen, wie man es benutzt, müssen zuerst darüber lernen. Der Standort von Sechma befindet sich in SRC/Main/Ressourcen/Meta-Inf/Schema/Stdws-1.0.xsd.
Definition Annotation
Paket com.codestd.spring.cxf.annotation; import Java.lang.Annotation.Documented; Import Java.lang.Annotation. Der Zweck der Dienstleistung durch Hinzufügen {@code @endpoint} Annotation zur Klasse. . Nach dem Hinzufügen dieser Annotation zur Bean wird sie automatisch im Federbehälter registriert. *@Author Jaune (Wangchengwei)*@Since 1.0.0*/ @target (elementtype.type) @retention (retentionPolicy.Runtime) @DocumentedPublic @Interface Endpoint {/*** Die ID dieses Endpunkts in der Spring Container* @return*/String id (). @return*/string address ();}Konfiguration im Frühjahr
Öffnen Sie "Fenster", "Einstellungen", "XML", "XML -Katalog". Klicken Sie auf "Hinzufügen" und wählen Sie dann das oben erstellte XSD, das wir oben in Position erstellt haben. "Schlüsseltyp" Wählen Sie den Namespace-Namen aus und geben Sie den Schlüssel in http://www.codestd.com/schema/std/ws/stdws-1.0.xsd ein. Das heißt, der in Sechma definierte TargetNameSpace+ -Dateiname.
Fügen Sie den Namespaces im Frühjahr hinzu und verwenden Sie Tags wie folgt. Hier müssen wir Spring's Annotation Scanning -Funktion verwenden.
<xml Version = "1.0" coding = "utf-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/xmlschema-in STICE "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>
Das zu scannte Paket ist in der Konfiguration definiert und hängt nicht von der Konfiguration mit Kontext ab.
Das obige ist das vom Editor geteilte Spring Custom -Konfigurationsschema erweiterbar (1). Ich hoffe, es wird für alle hilfreich sein.