国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

Spring自定義配置Schema可擴展(一)

2019-11-26 14:38:57
字體:
來源:轉載
供稿:網友

簡述

本教程主要介紹如何擴展Spring的xml配置,讓Spring能夠識別我們自定義的Schema和Annotation。

這里我們要實現的功能如下,首先讓Spring能夠識別下面的配置。

<std:annotation-endpoint />

這個配置的要實現的功能是,配置完后能夠讓Spring掃描我們自定義的@Endpoint注解。并且根據注解自動發布WebService服務。功能未完全實現,作為擴展Spring的教程,起一個拋磚引玉的作用。

創建項目

首先需要創建一個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.apache.org/POM/4.0.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><version>1.0.0-SNAPSHOT</version><name>${project.artifactId}</name><description>使您的項目可以通過注解的方式發布WebService,基于Spring+CXF封裝,無API侵入。</description><url>https://github.com/CodeSTD/spring-cxf-annotation-support</url><licenses><license><name>The Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url></license></licenses><developers><developer><name>jaune(WangChengwei)</name><email>jaune162@126.com</email><roles><role>developer</role></roles><timezone>GMT+8</timezone></developer></developers><scm><connection>https://github.com/CodeSTD/spring-cxf-annotation-support.git</connection><developerConnection>https://github.com/CodeSTD/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></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>${cxf.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></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.14</version><scope>test</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.7</version><scope>test</scope></dependency></dependencies></project>

定義Schema

<?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"targetNamespace="http://www.codestd.com/schema/std/ws"elementFormDefault="qualified"attributeFormDefault="unqualified"><xsd:import namespace="http://www.springframework.org/schema/beans"/><xsd:annotation><xsd:documentation><![CDATA[ Namespace support for the annotation provided by cxf framework. ]]></xsd:documentation></xsd:annotation><xsd:element name="annotation-endpoint"><xsd:complexType><xsd:complexContent><xsd:extension base="beans:identifiedType"><xsd:attribute name="name" type="xsd:string" use="optional"><xsd:annotation><xsd:documentation><![CDATA[ Name of bean. Insted of id ]]></xsd:documentation></xsd:annotation></xsd:attribute><xsd:attribute name="package" type="xsd:string" use="optional"><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.Target;/*** 用于暴露WebService服務,通過在類上加入{@code @Endpoint}注解實現服務暴露的目的。* <p>擴展Spring的Bean掃描功能,在Bean上加入此注解后會自動注冊到Spring容器中。* @author jaune(WangChengwei)* @since 1.0.0*/@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Endpoint {/*** 此Endpoint在Spring容器中的ID* @return*/String id();/*** 服務發布的地址,應神略服務器地址及端口號和項目路徑* @return*/String address();}

在Spring中的配置

打開“Window”

主站蜘蛛池模板: 孟州市| 龙海市| 阿尔山市| 中方县| 大姚县| 于都县| 鹤岗市| 新竹县| 汉阴县| 仪陇县| 肥东县| 黎平县| 霍林郭勒市| 大冶市| 沙河市| 沧州市| 洪泽县| 东安县| 盐津县| 邛崃市| 新晃| 云林县| 同德县| 定兴县| 邳州市| 外汇| 萨迦县| 措勤县| 静安区| 临夏市| 红安县| 兴城市| 舒兰市| 阜康市| 海淀区| 黎川县| 云龙县| 札达县| 南阳市| 雅安市| 新兴县|