关于spring框架头文件解析和两种模板

spring框架有两种模板,推荐使用带命名空间的,这样可以再编译的时候自动检查,还有提示功能:

<?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:aop="http://www.springframework.org/schema/aop"
		xmlns:tx="http://www.springframework.org/schema/tx"
		xsi:schemaLocation="
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
</beans>


另一种也可以正常运行,只是不会自动检查错误,如果编译期有错会在运行期抛出错误,如果applicationContext.xml文件大的话这样会使排错困难:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
</beans>

PS:没有命名空间的的xml为普通的xml文件,所以不会检查和提示,提示效果如下:


如果能保证xml书写结果正确的话,也可以不用写命名空间,官方并不要求,但推荐。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章