xmlns解疑
为什么要使用xmlns
1.xmlns翻译过来就是xml命名空间,作用是唯一地指定标签名。
2.xmlns使用一段url来特定修饰一个前缀,如下为spring的配置文件,使用url的理由是,url在互联网上具有唯一性,与包命名机制类似。
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
</beans>
xmlns的使用场景
1.注意,bean并没有使用xmlns,由此可以看出,我们可以把xmlns的设置看成变量的定义1
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="club.jming"></context:component-scan>
<bean id="a" class="a"></bean>
</beans>
这里仅为个人理解,如有不妥,望提醒博主 ↩︎