栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring自定义配置Schema可扩展(一)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring自定义配置Schema可扩展(一)

简述

本教程主要介绍如何扩展Spring的xml配置,让Spring能够识别我们自定义的Schema和Annotation。

这里我们要实现的功能如下,首先让Spring能够识别下面的配置。

这个配置的要实现的功能是,配置完后能够让Spring扫描我们自定义的@Endpoint注解。并且根据注解自动发布WebService服务。功能未完全实现,作为扩展Spring的教程,起一个抛砖引玉的作用。

创建项目

首先需要创建一个Java项目,这里使用Maven创建一个quickstart项目(普通Java项目)。
POM文件内容如下


4.0.0
com.codestd
spring-cxf-annotation-support
1.0.0-SNAPSHOT
${project.artifactId}
使您的项目可以通过注解的方式发布WebService,基于Spring+CXF封装,无API侵入。
https://github.com/CodeSTD/spring-cxf-annotation-support


The Apache License, Version 2.0
http://www.apache.org/licenses/LICENSE-2.0.txt




jaune(WangChengwei)
jaune162@126.com

developer

GMT+8




https://github.com/CodeSTD/spring-cxf-annotation-support.git


https://github.com/CodeSTD/spring-cxf-annotation-support.git



4.12
4.2.4.RELEASE
3.1.3



junit
junit
${junit.version}
test


org.springframework
spring-context
${spring.version}


org.apache.cxf
cxf-rt-frontend-jaxws
${cxf.version}


org.apache.cxf
cxf-rt-transports-http-jetty
${cxf.version}


org.springframework
spring-test
${spring.version}


log4j
log4j
1.2.14
test


org.slf4j
slf4j-log4j12
1.7.7
test


定义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;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@documented
public @interface Endpoint {

String id();

String address();
}

在Spring中的配置

打开“Window”–“Preferences”–“XML”–“XML Catalog”。点击“Add”,然后在Location中选择我们上面创建的xsd。“Key type”选择Namespace Name,key输入http://www.codestd.com/schema/std/ws/stdws-1.0.xsd。即Sechma中定义的targetNamespace+文件名。
在Spring中加入命名空间,并使用标签,如下。这里要用到Spring的注解扫描功能。




在配置中定义了要扫描的包,不依赖与context的配置。

以上所述是小编给大家分享的Spring自定义配置Schema可扩展(一),希望对大家有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/150666.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号