• nacos-spring-project 的 xml 配置


    nacos-spring-context 作为一座桥连接 spring 项目和 nacos-client

    在 spring 项目中使用自定义的 xml 标签

    1. 编写 xsd 文件

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns="http://nacos.io/schema/nacos"
                targetNamespace="http://nacos.io/schema/nacos">
    
        <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
    
        <xsd:annotation>
            <xsd:documentation>
                <![CDATA[ Nacos Framework Schema ]]>
            </xsd:documentation>
        </xsd:annotation>
    
        <xsd:element name="annotation-driven">
            <xsd:annotation>
                <xsd:documentation>
                    <![CDATA[
                    Activates various Nacos Spring's annotations :
                    @NacosInjected
                    @NacosConfigListener
                    @NacosPropertySource
                    @NacosPropertySources
                    @NacosConfigProperties / @NacosProperty / @NacosIgnore
                ]]></xsd:documentation>
            </xsd:annotation>
        </xsd:element>
    
        <xsd:element name="global-properties">
            <xsd:annotation>
                <xsd:documentation>
                    <![CDATA[
                    Register Nacos global Properties whose values are configured from attributes.
                    ]]>
                </xsd:documentation>
            </xsd:annotation>
            <xsd:complexType>
                <xsd:attribute name="endpoint" default="${nacos.endpoint:}"/>
                <xsd:attribute name="namespace" default="${nacos.endpoint:}"/>
                <xsd:attribute name="access-key" default="${nacos.access-key:}"/>
                <xsd:attribute name="secret-key" default="${nacos.secret-key:}"/>
                <xsd:attribute name="server-addr" default="${nacos.server-addr:}"/>
                <xsd:attribute name="context-path" default="${nacos.context-path:}"/>
                <xsd:attribute name="cluster-name" default="${nacos.cluster-name:}"/>
                <xsd:attribute name="encode" default="${nacos.encode:UTF-8}"/>
            </xsd:complexType>
        </xsd:element>
    
        <xsd:element name="property-source">
            <xsd:annotation>
                <xsd:documentation>
                    <![CDATA[
                    Add Nacos property source
                    ]]>
                </xsd:documentation>
            </xsd:annotation>
            <xsd:complexType>
                <xsd:attribute name="name" default=""/>
                <xsd:attribute name="group-id" default="DEFAULT_GROUP"/>
                <xsd:attribute name="data-id" use="required"/>
                <xsd:attribute name="data-ids"/>
                <xsd:attribute name="auto-refreshed" default="false"/>
                <xsd:attribute name="first" default="false"/>
                <xsd:attribute name="before" default=""/>
                <xsd:attribute name="after" default=""/>
                <xsd:attribute name="type" default="properties" />
            </xsd:complexType>
        </xsd:element>
    
    </xsd:schema>
    View Code

    2. 实现 NamespaceHandler 和 BeanDefinitionParser

    public class NacosNamespaceHandler extends NamespaceHandlerSupport {
    
        @Override
        public void init() {
            registerBeanDefinitionParser("annotation-driven", new NacosAnnotationDrivenBeanDefinitionParser());
            registerBeanDefinitionParser("global-properties", new GlobalNacosPropertiesBeanDefinitionParser());
            registerBeanDefinitionParser("property-source", new NacosPropertySourceBeanDefinitionParser());
        }
    }

    3. 编写 spring.handlers 和 spring.schemas 文件

    http://nacos.io/schema/nacos=com.alibaba.nacos.spring.context.config.xml.NacosNamespaceHandler
    http://nacos.io/schema/nacos.xsd=META-INF/schemas/nacos.xsd
  • 相关阅读:
    Python的if判断与while循环
    python基础之数据类型与变量
    网络基础之网络协议篇
    操作系统简介
    计算机基础之计算机硬件系统
    从头开始编写一个Orchard网上商店模块(3)
    从头开始编写一个Orchard网上商店模块(2)
    从头开始编写一个Orchard网上商店模块(1)
    var和dynamic的区别及如何正确使用dynamic ?
    [DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用
  • 原文地址:https://www.cnblogs.com/allenwas3/p/11394092.html
Copyright © 2020-2023  润新知