간단한 설명
이 자습서는 주로 Spring의 XML 구성을 확장하여 Spring이 맞춤형 스키마 및 주석을 인식 할 수 있도록하는 방법을 소개합니다.
여기에서 구현하려는 기능은 다음과 같습니다. 첫째, Spring이 다음 구성을 인식하도록하겠습니다.
<std : 주석-엔드 포인트 />
이 구성에서 구현할 기능은 구성 후 Spring이 사용자 정의 @endpoint 주석을 스캔 할 수 있다는 것입니다. 주석에 따라 웹 서비스 서비스를 자동으로 게시합니다. 이 기능은 완전히 구현되지 않았으며 Spring을 확장하기위한 튜토리얼로서 Jade를 유치하는 데 중요한 역할을합니다.
프로젝트를 만듭니다
먼저 Java 프로젝트를 만들어야하며 여기에서 Maven을 사용하여 빠른 스타트 프로젝트 (일반 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.apache.org/pom/0.0.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "> <modelversion> 4.0.0 </modelversion> <groupid> com.codestd </groupid> <artifactid> Spring-CXF-Nantation-Support </artifactid> <bersion> 1.0.0-snapshot </version> <name> $ {project.artifactid} </name> <description> API 침입없이 Spring+CXF 캡슐화를 기반으로 주석을 통해 웹 서비스를 게시 할 수 있습니다. </description> <Url> https://github.com/codestd/spring-cxf-annotation-support </url> <라이센스> <name> Apache 라이센스, 버전 2.0 </name> <url> http://www.apache.org/licenses/license-2.txt </license> </license> </licensers> <Developers> <name> jaune (wangchengwei) </name> <email> [email protected]. /role></roles>> holes> <<timezone>gmt+8</timezone></developer></developers> <scm> https://github.com/codestd/spring-cxf-annotation-support.git</connection>developerconnection> https:/github.com/cod estd/spring-cxf-annotation-support.git </developernection> </scm> <properties> <junit.version> 4.12 </junit.version> <spring.version> 4.2.4. 4.2.4. Release> <cxf.version> 3.1.3 </cxf.version> </prope rties> <pectioniles> <pectinement> <groupId> junit </groupid> <artifactid> junit </artifactid> <버전> $ {junit.version} </version} </version> <cope> </scope> </spectency> <pelection> <groupid> org.springframework </gro upid> <artifactid> spring-context </artifactid> <version> $ {spring.version} </version> </dependency> <pectionency> <groupid> org.apache.cxf </groupID> <artifactid> cxf-rt-frontend-jaxws </artifactid> {cx f.version} </version> </dependency> <pectionency> <groupid> org.apache.cxf </groupid> <artifactid> cxf-rt-transports-http-jetty </artifactid> <버전> $ {cxf.version} </version> <pectionement> <groupdency> <groupid> org.springframework </groupid> <artifactid> spring-test </artifactid> <bersion> $ {spring.version} </version> </fectionency> <pectionency> <groupid> log4j </groupid> <artifactid> log4j </artifactid> <bersion> 1.2.14 </v ERSION> <Scope> 테스트 </scope> </fectionency> <pectionency> <groupId> org.slf4j </groupid> <tritifactid> slf4j-log4j12 </artifactid> <버전> 1.7.7 </version> <cope> test </scope> </fectionency> </project>정의 스키마
<? xml version = "1.0"encoding = "utf-8"독립형 = "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"targetnamespac e = "http://www.codestd.com/schema/std/ws"elementformdefault = "자격이있는"attributeformdefault = "자격이없는"> <xsd : import 네임 스페이스 = "http://www.springframework.org/schema/beans"/> <xsd : annotation> <xsd : documentation> <! ]]]> </xsd : documentation> </xsd : annotation> <xsd : element name = "annotation-endpoint"> <xsd : complemtype> <xsd : complexContent> <xsd : "beans :"beans : aftribute name = "name"xsd : string " 사용 = "옵션"> <xsd : annotation> <xsd : documentation> <! [cdata [Bean의 이름. ID]> </xsd : documentation> </xsd : annotation> </xsd : attribute> <xsd : attribute name = "package"type = "xsd : string"use = "옵션"> <xsd : annotation> <xsd : documentation> <! [cdata [pakeage to scan. ]]> </xsd : documentation> </xsd : annotation> </xsd : attribute> </xsd : extension> </xsd : complexContent> </xsd : complexType> </xsd : element> </xsd : schema>
SECHMA에 대한 지식은 여기에 설명되지 않습니다. 사용 방법을 모르는 친구들은 먼저 배워야합니다. SECHMA 위치는 SRC/Main/Resources/Meta-Inf/Schema/STDWS-1.0.xsd입니다.
정의 주석
package 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; import java.lang.annotation. to and and and and and and and and and and and and and and ancome services; {@code @endpoint} 주석을 클래스에 추가하여 서비스 노출의 목적. * <p> 스프링의 Bean 스캐닝 기능을 확장합니다. 이 주석을 콩에 추가하면 스프링 컨테이너에 자동으로 등록됩니다. *@Author jaune (wangchengwei)*@since 1.0.0*/ @target (elementtype.type) @retention (rendentpolicy.runtime) @documentedPublic @interface endpoint {/*** 스프링 컨테이너* @return*/string id (); 주소();}봄의 구성
"창", "환경 설정", "xml", "xml 카탈로그"열기. "추가"를 클릭 한 다음 위에서 만든 XSD를 선택하십시오. "키 유형"네임 스페이스 이름을 선택하고 http://www.codestd.com/schema/std/ws/stdws-1.xsd에 키를 입력하십시오. 즉, SECHMA에 정의 된 TargetNamesPace+ 파일 이름입니다.
스프링에 네임 스페이스를 추가하고 다음과 같이 태그를 사용하십시오. 여기서는 Spring의 주석 스캐닝 기능을 사용해야합니다.
<? xml 버전 = "1.0"encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://www.w3.org/2001/xmlschema-in 자세 "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>
스캔 할 패키지는 구성에 정의되며 컨텍스트의 구성에 따라 다릅니다.
위는 편집기가 공유하는 스프링 사용자 정의 구성 스키마 확장 가능 (1)입니다. 모든 사람에게 도움이되기를 바랍니다.