本文介绍了Spring XML名称空间:如何找到它们背后的实现类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring 3.1应用程序中,有时我需要更改上下文文件中某些Spring名称空间的默认行为.为此,我创建了一些自定义类,这些类实现了某些接口或扩展了Spring使用的默认类.

In my Spring 3.1 application, I sometime need to change the default behavior of some of the Spring namespaces in my context files. To do that, I create custom classes that implement some interfaces or that extend the default classes Spring uses.

但是我发现很难确切知道Spring在其名称空间后面使用的那些类是什么!找到它们需要什么步骤?

But I find it hard to know exactly what are those classes that Spring uses behind its namespaces! What is the steps required to find them?

例如,安全名称空间:

<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>

如何找到< sec:logout/>"命名空间使用的类?我没有通过查看 http://www.springframework找到信息.org/schema/security/spring-security-3.1.xsd

How do I find what classes are used by the "<sec:logout />" namespace? I don't find the information by looking at http://www.springframework.org/schema/security/spring-security-3.1.xsd !

我应该去哪里看?

推荐答案

每个Spring名称空间都有一个关联的 NamespaceHandler 实现.命名空间模式在各种spring.schemas文件中映射到Spring JAR内部的模式文件(另请参见 Spring DI applicationContext.xml如何精确使用xsi:schemaLocation ?).

Every Spring namespace has an associated NamespaceHandler implementation. The namespace schemas are mapped to schema files inside Spring JARs in various spring.schemas files (see also Spring DI applicationContext.xml how exactly is xsi:schemaLocation used?).

XML模式名称空间也映射到spring.handlers文件中的处理程序类(因为每个Spring JAR可能引入不同的名称空间,所以这些名称是多次的).为了方便起见,下面列出了最常见的名称空间:

The XML schema namespaces are also mapped to handler classes in spring.handlers files (several as each Spring JAR might introduce different namespaces). For your convenience here is a list of most common namespaces:

  • 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
  • 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

如果浏览到每个此类的源,您将很快发现负责解析实际XML定义的各种BeanDefinitionParser实现.

If you browse to the source of each of these classes you will quickly discover various BeanDefinitionParser implementations responsible for parsing actual XML definitions.

这篇关于Spring XML名称空间:如何找到它们背后的实现类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:54