Java spring如何基于名称空间工作?
我通常看到spring模块是基于名称空间加载的,这对我来说并不清楚,尽管我有一些模糊的理解Java spring如何基于名称空间工作?,java,spring,Java,Spring,我通常看到spring模块是基于名称空间加载的,这对我来说并不清楚,尽管我有一些模糊的理解 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.spri
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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
http://www.springframework.org/schema/context/spring-context.xsd"
spring如何在内部使用上面声明的名称空间,如上下文、p等?
以下是我的理解:-
spring在内部解析xml
在解析时,它会尝试找出所有JAR的预期JAR
XSD(它在内部根据schemaLocation值知道JAR名称)
Spring处理器基于
名称空间(如context,p),其中context,p等是默认的
在步骤2中找到的某个XSD中的名称空间
正确吗?是的,您的理解是正确的,同时加载上下文Spring解析xml并验证所有名称空间。这些名称空间的所有定义都在jar中,您可以通过maven或在构建路径中提供,例如,xmlns:context的名称空间定义可以在spring-context.jar中找到
spring-context.jar包含spring-context-3.0.xsd,您可以在spring-context.jar/META-INF/spring.schema中看到它
一旦验证了名称空间,它就会根据您提到的名称空间验证和处理元素。请记住,标记中使用的实际名称空间名称是不相关的。它们只是与它们相关联的XSD定义的一个简写键。@chrylis您能否详细说明“请记住标记中使用的实际名称空间名称是不相关的”?无论您使用的是context
还是c
还是foobar
,都是不相关的。唯一重要的是名称空间名称(context
)与名称空间URI列表中的键相匹配。@chrylis您能详细说明您最后的注释吗?