spring最基本引入自定义命名空间_重点在约束

这个目的只为了约束正确生效: 

文件结构:

 

 

 

 spring.handlers:

http\://www.shishi.com/myschema/customize=com.readspring.myannotation.MyNamespaceHandler

spring.schemas:

http\://www.shishi.com/myschema/customize.xsd=META-INF/customize.xsd

 

customize.xsd:

targetNamespage 和默认命名空间,这两个要一致: 

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.shishi.com/myschema/customize"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
            targetNamespace="http://www.shishi.com/myschema/customize"
            elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:element name="word">

</xsd:element>

</xsd:schema>

 

applicationcontext3.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:customize="http://www.shishi.com/myschema/customize"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.shishi.com/myschema/customize http://www.shishi.com/myschema/customize.xsd">

    <customize:word ></customize:word>

</beans>

 

能有提示了:

 

 

注意applicationcontext.xml里引入的命名空间的值要和xsd的命名空间的值里的一致, 不然会红色识别不了。 xmlns

 

posted @ 2020-11-19 19:59  圣金巫灵  阅读(139)  评论(0编辑  收藏  举报