0
点赞
收藏
分享

微信扫一扫

记录一次根据spring官网的例子,自定义编写xml发生的错误


网址:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#xml-custom
章节:10.2. XML Schema Authoring

按照spring官网的例子一步步测试,步骤如下:

1、编写xsd文件【myns.xsd】
2、编写NamespaceHandler【MyNamespaceHandler 】
3、编写BeanDefinitionParser【SimpleDateFormatBeanDefinitionParser 】
4、编写META-INF/spring.handlers
5、编写META-INF/spring.schemas
6、在application.xml文件中引入名称空间

//```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:myns=“http://www.mycompany.example/schema/myns”
xsi:schemaLocation="
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd

// 重点就是这里。按这里的写法会一直按照网址去网上下载不会使用本地的,然而又下载不到,所以一直报错
    http://www.mycompany.example/schema/myns http://www.mycompany.com/schema/myns/myns.xsd">

<!-- as a top-level bean -->
<myns:dateformat id="defaultDateFormat" pattern="yyyy-MM-dd HH:mm" lenient="true"/> 

<bean id="jobDetailTemplate" abstract="true">
    <property name="dateFormat">
        <!-- as an inner bean -->
        <myns:dateformat pattern="HH:mm MM-dd-yyyy"/>
    </property>
</bean>

```

解决:
1、在网上找了别的例子试了试,是成功的
2、比对官网的例子和网上给的例子
3、找到问题

http://www.mycompany.example/schema/myns http://www.mycompany.com/schema/myns/myns.xsd

替换为
http://www.mycompany.example/schema/myns http://www.mycompany.com/schema/myns.xsd

思考:
1、既然一直去网上去下载,那么就只需要对比http://www.mycompany.com/schema/**myns.xsd的差异就可以了


举报

相关推荐

0 条评论