Spring XML namespaces : How do I find what are the implementing classes behind them?

后端 未结 4 1298
暖寄归人
暖寄归人 2020-12-22 18:12

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 i

相关标签:
4条回答
  • 2020-12-22 18:47

    In the case of Spring Security, it's well documented: see Appendix B. The Security Namespace

    See also this blog post: BEHIND THE SPRING SECURITY NAMESPACE

    0 讨论(0)
  • 2020-12-22 18:55

    Every XML namespace is parsed by its NamespaceHandler. The handler class for security namespace is SecurityNamespaceHandler, which is specified in spring.handlers file inside META-INF of spring-security-config-XXX.jar file.

    The http element is parsed by HttpSecurityBeanDefinitionParser and its child element logout is parsed by org.springframework.security.config.http.LogoutBeanDefinitionParser(package-protected).

    Also see notes in Coding a NamespaceHandler and advice in What beans are registered by the spring security namespace? if you are planning to customize it.

    0 讨论(0)
  • 2020-12-22 18:58

    Almost all of them are named *BeanDefinitionParser. First step is, using your browser, bring up the Spring JavaDocs and hit <Ctrl>-F (or <Command>-F). Search for BeanDefinitionParser. Of the classes that match, one or two will, by their names, look like they handle the namespace elements you are researching. It may take a bit of looking at the source code to those classes but you'll ultimately find what you want.

    Alternatively, in your IDE, you can browse to BeanDefinitionParser.java and then do "Find Usages" (IntelliJ) or "Type Hierarchy" (Eclipse) to find all of the implementers of that interface. There are a handful of classes that don't follow the *BeanDefinitionParser naming convention. Your IDE will give you a comprehensive list.

    I think that Spring should actually document, in the Namespace section of their reference docs, the names of the classes that handle each element.

    0 讨论(0)
  • 2020-12-22 19:03

    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?).

    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:

    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

    • security - SecurityNamespaceHandler
    • oauth - OAuthSecurityNamespaceHandler

    Spring integration

    • 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

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

    0 讨论(0)
提交回复
热议问题