Wildcard characters in spring

Source: Internet
Author: User

One, the wildcard character in the load path:? (matches a single character), * (matches any character except/outside), **/(matches any number of directories)

Classpath:app-beans.xml

Description: No wildcard characters, must match exactlyClasspath:app?-beans.xmlDescription: Matches a character, such as App1-beans.xml, App2-beans.xmlClasspath:user/*/base-beans.xmlDescription: Matches 0 or more strings (names only, does not match directory separators, etc.), for example: User/a/base-beans.xml, User/b/base-beans.xml, but does not match user/base-beans.xmlClasspath:user/**/base-beans.xmlDescription: Matches 0 or more directories in the path, for example: User/a/ab/abc/base-beans.xml, and can also match user/base-beans.xmlClasspath:**/*-beans.xmlDescription: Represents a configuration file that finds and loads a file name ending with "-beans.xml" in all classpath, but only one of the duplicate filenames is loaded, depending on the load orderClasspath*:user/**/*-beans.xmlclasspath*:* */*-beans.xmlDescription: "classpath*:" means loading multiple resource files, even if the same name will be loaded, such as App1.jar in a config-beans.xml,app2.jar there is also a config-beans.xml, this time, two will be loaded. Classpath*: Can be used to load the same file from multiple jar files and can be used to loadOther (non-current) ClassLoader files in the path.
Note that the path in spring is split identifier/, not with \ \, reference: http://mushiqianmeng.blog.51cto.com/3970029/875027/
Two, Spring AOP configures wildcard characters:The following documents are from the Spring Chinese Development Guide 2.5 document, translated by the Azolla Open source organization:Spring AOP users may often use executionPointcut indicator. The execution expression is in the following format:
Execution (Modifiers-pattern? Ret-type-pattern Declaring-type-pattern? Name-pattern (Param-pattern)          Throws-pattern?)
All parts are optional except the return type pattern (Ret-type-pattern in the code snippet above), the name pattern, and the parameter pattern. The return type mode determines that the return type of the method must match one connection point in turn. You'll use it. The most frequent return type pattern is * , which represents a match for any return type. A fully qualified type name will only match the method that returns the given type. The name pattern matches the method name. You can use * wildcards as all or part of a naming pattern。 The parameter mode is a little bit more complicated: () matches a method that does not accept any parameters, and (..) matches a method that accepts any number of parameters (0 or more). The pattern (*) matches a method that accepts a parameter of any type. The pattern (*,String) matches a method that accepts two parameters, the first of which can be any type, the second must be of type string。 For more information, see the Language Semantics section of the ASPECTJ Programming Guide. Some examples of common pointcut expressions are given below.
  • Execution of any public method:
    Execution (Public * * (.. ))
  • The execution of a method whose name begins with "set":
    Execution (* set* (.. ))
  • AccountServiceExecution of any method defined by the interface:
    Execution (* com.xyz.service.accountservice.* (.. ))
  • Execution of any method defined in the service package:
    Execution (* com.xyz.service.*.* (.. ))
  • Execution of any method defined in a service package or its child packages:
    Execution (* com.xyz.service). *.*(.. ))
  • Any connection point in the service package (only method execution in spring AOP):
    Within (com.xyz.service.*)
  • within (Com.xyz.service. *)
  • interface (only method execution in spring AOP):
    this (com.xyz.service.AccountService) 
    ' This ' is more commonly used in binding forms:-See the following notification section for information on how to make a proxy object available in the notification body.
  • interface (only method execution in spring AOP):
    target (com.xyz.service.AccountService) 
    ' target ' is more commonly used in binding forms:-See the following notification section for information on how to make a target object available in the notification body.
  • either one takes only one parameter, and the arguments passed in at run time are serializable   Interface Connection point (only method execution in spring AOP)
    args (java.io.Serializable) 
    ' args ' is more commonly used in binding forms:- See the following notification section for information on how to make method parameters available in the notification body. Note that the pointcut given in the example differs from the  execution (* * ( java.io.Serializable) : The args version only matches when the incoming parameter is Serializable when dynamically running, and the execution version declares only one  serializable the parameters of the type.
  • @Transactional any connection point for   annotations (only method execution in spring AOP)
     @target (org.springframework.transaction.annotation.Transactional) 
    < Span class= "Remark" style= "padding:0px; margin:0px; " > ' @target ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.
  • @Transactional the connection point for   annotations (only method execution in spring AOP):
     @within (org.springframework.transaction.annotation.Transactional) 
    < Span class= "Remark" style= "padding:0px; margin:0px; " > ' @within ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.
  • @Transactional the connection point for   annotations (only method execution in spring AOP)
     @annotation (org.springframework.transaction.annotation.Transactional) 
    ' @annotation ' is more commonly used in binding forms:-See the following notification section to learn how to make a callout object available in the notification body.
  • either one accepts only one parameter, and the parameter type passed in by the runtime has a @Classified the connection point for   annotations (only method execution in spring AOP)
     @args (com.xyz.security.Classified) 
    ' @args ' is more commonly used in binding forms:-See the following notification section for information on how to make a callout object available in the notification body.
  • Connection point above TradeService ' Spring bean (only method execution in spring AOP):
    bean (tradeservice) 
  • Any connection point above the spring bean whose name matches the wildcard expression " *Service (only method execution in spring AOP):
    Bean (*service)

 

From for notes (Wiz)

Wildcard characters in spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.