Spring XML名称空间:如何找到它们背后的实现类?
问题内容:
在我的Spring
3.1应用程序中,有时需要更改上下文文件中某些Spring命名空间的默认行为。为此,我创建了一些自定义类,这些类实现了某些接口或扩展了Spring使用的默认类。
但是我发现很难确切知道Spring在其名称空间后面使用的是哪些类!找到它们需要什么步骤?
例如,安全名称空间:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
和类似的东西:
<sec:http>
...
<sec:logout />
</sec:http>
如何找到“
security-3.1.xsd
找到信息!
我应该去哪里看?
问题答案:
每个Spring名称空间都有一个关联的NamespaceHandler
实现。命名空间模式映射到各种spring.schemas
文件中的Spring
JAR内部的模式文件另请参见[Spring DIapplicationContext.xml,如何精确使用xsi:schemaLocation?
XML模式名称空间也映射到spring.handlers
文件中的处理程序类(因为每个Spring
JAR可能引入不同的名称空间,所以这种方式很常见)。为了方便起见,下面列出了最常见的名称空间:
Spring core
aop
--AopNamespaceHandler
c
--SimpleConstructorNamespaceHandler
cache
--CacheNamespaceHandler
context
--ContextNamespaceHandler
jdbc
--JdbcNamespaceHandler
jee
--JeeNamespaceHandler
jms
--JmsNamespaceHandler
lang
--LangNamespaceHandler
mvc
--MvcNamespaceHandler
oxm
--OxmNamespaceHandler
p
--SimplePropertyNamespaceHandler
task
--TaskNamespaceHandler
tx
--TxNamespaceHandler
util
--UtilNamespaceHandler
spring安全
security
--SecurityNamespaceHandler
oauth
--OAuthSecurityNamespaceHandler
spring整合
int
--IntegrationNamespaceHandler
amqp
--AmqpNamespaceHandler
event
--EventNamespaceHandler
feed
--FeedNamespaceHandler
file
--FileNamespaceHandler
ftp
--FtpNamespaceHandler
gemfire
--GemfireIntegrationNamespaceHandler
groovy
--GroovyNamespaceHandler
http
--HttpNamespaceHandler
ip
--IpNamespaceHandler
jdbc
--JdbcNamespaceHandler
jms
--JmsNamespaceHandler
jmx
--JmxNamespaceHandler
mail
--MailNamespaceHandler
redis
--RedisNamespaceHandler
rmi
--RmiNamespaceHandler
script
--ScriptNamespaceHandler
security
--IntegrationSecurityNamespaceHandler
sftp
--SftpNamespaceHandler
stream
--StreamNamespaceHandler
twitter
--TwitterNamespaceHandler
ws
--WsNamespaceHandler
xml
--IntegrationXmlNamespaceHandler
xmpp
--XmppNamespaceHandler
如果浏览到每个此类的源,您将快速发现BeanDefinitionParser
负责解析实际XML定义的各种实现。