当前位置:   article > 正文

【Spring】xml配置文件常用的头约束_spring-task-4.3.8.xsd

spring-task-4.3.8.xsd

        在Spring开发开发过程中,我们经常需要借助xml配置文件实现对于Spring相关配置的引入,很多人常常在使用的xml配置的时候不知道该引入什么样的头约束,下面就给大家提供下经常使用的一些框架的头约束。

一、Spring对xml文件的校验

Spring文件中的头部引用的xsd文件是用于校验xml文件的格式用的。

1.1、Spring是如何校验XML的

        Spring默认在启动时是要加载xsd文件来验证xml文件的,如果有的时候断网了,或者一些开源软件切换域名,那么就很容易碰到应用启动不了。为了防止这种情况,Spring提供了一种机制,默认从本地加载XSD文件。

例如:可以打开spring-context-4.3.4.RELEASE.jar,进入org/springframework/context/config/目录,可以看到如下所示:

 

1.2、Spring中的xsd文件带版本号与不带版本号的区别

        不带版本号,它会自动使用JAR中最新的xsd;这样以后升级Spring版本的时候,你的配置文件不用再手动改动。Spring的配置里,最好不要配置xsd文件的版本号。

        另外如果没有配置版本号,取的就是当前jar里的xsd文件,减少了各种风险。其实,最大的好处是,当你升级了Spring的jar,该配置文件的xsd声明部分也不用改,会自动找到最新的本地jar里的xsd声明。Spring做了特殊处理,保证断网的情况下不写xsd版本号,能找到本地的jar文件。

二、常见的xml头文件约束

2.1、spring-mvc

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:mvc="http://www.springframework.org/schema/mvc"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/mvc
  7. http://www.springframework.org/schema/mvc/spring-mvc.xsd">
  8. </beans>

2.2、spring-aop

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:aop="http://www.springframework.org/schema/aop"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/aop
  7. http://www.springframework.org/schema/aop/spring-aop.xsd">
  8. </beans>

2.3、spring-tx

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:tx="http://www.springframework.org/schema/tx"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/tx
  7. http://www.springframework.org/schema/tx/spring-tx.xsd">
  8. </beans>

2.4、spring-context

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:context="http://www.springframework.org/schema/context"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/context
  7. http://www.springframework.org/schema/context/spring-context.xsd">
  8. </beans>

2.5、spring-task

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.   xmlns:task="http://www.springframework.org/schema/task"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/task
  7. http://www.springframework.org/schema/task/spring-task.xsd">
  8. </beans>

2.6、spring-cache

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:cache="http://www.springframework.org/schema/cache"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/cache
  7. http://www.springframework.org/schema/cache/spring-cache.xsd
  8. </beans>

2.7、spring-jdbc

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/jdbc
  7. http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
  8. </beans>

2.8、P命名空间

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:p="http://www.springframework.org/schema/p"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. </beans>

 2.9、spring-jee

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:jee="http://www.springframework.org/schema/jee"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/jee
  7. http://www.springframework.org/schema/jee/spring-jee.xsd
  8. </beans>

2.10、spring-jms

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:jms="http://www.springframework.org/schema/jms"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/jms
  7. http://www.springframework.org/schema/jms/spring-jms.xsd
  8. </beans>

2.11、spring-lang

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:lang="http://www.springframework.org/schema/lang"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/lang
  7. http://www.springframework.org/schema/lang/spring-lang.xsd
  8. </beans>

2.12、spring-oxm

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:oxm="http://www.springframework.org/schema/oxm"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/oxm
  7. http://www.springframework.org/schema/oxm/spring-oxm.xsd
  8. </beans>

2.13、spring-util

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:util="http://www.springframework.org/schema/util"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/util
  7. http://www.springframework.org/schema/util/spring-util.xsd">
  8. </beans>

三、总结

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:cache="http://www.springframework.org/schema/cache"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
  7. xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
  8. xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
  9. xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
  10. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
  11. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  12. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
  14. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  15. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
  16. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  17. http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
  18. http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
  19. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
  20. http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd
  21. http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
  22. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  23. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
  24. </beans>
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/309183
推荐阅读
相关标签
  

闽ICP备14008679号