In the project, you will often see this notation in XML:
<PropertiesResource= "Properties/database.properties"/><DataSourcetype= "simple"> < Propertyvalue= "${driver}"name= "JDBC. Driver "/> < Propertyvalue= "${url}"name= "JDBC. Connectionurl "/> < Propertyvalue= "${username}"name= "JDBC. Username "/> < Propertyvalue= "${password}"name= "JDBC. Password "/> </DataSource>
See ${} Such expressions, the first impression in my mind is not the El expression in our JSP?!
Ha ha...
However, this is really not an El expression, and spring provides its own El expression, but its format is #{}
So ....
${key} the expression in XML, which represents a variable value corresponding to key in the introduced properties file, is completely parsed by the third-party jar itself.
============== Split Line ===========
Example:
A.ibatis in the configuration file, ${} of the parse, directly on the code:
Public Staticstring Parsepropertytokens (String string, Properties variables) {FinalString OPEN = "${"; FinalString CLOSE = "}"; String newstring=string; if(NewString! =NULL&& Variables! =NULL) { intStart =Newstring.indexof (OPEN); intEnd =Newstring.indexof (CLOSE); while(Start >-1 && end >start) {String prepend= newstring.substring (0, start); String Append= newstring.substring (end +close.length ()); String propname= newstring.substring (start +open.length (), end); String PropValue=Variables.getproperty (propname); if(PropValue = =NULL) {newstring= prepend + propname +append; } Else{newstring= prepend + PropValue +append; } Start=Newstring.indexof (OPEN); End=Newstring.indexof (CLOSE); } } returnnewstring; }
Found the wood has, is completely analytic character!!!! Code reference: Com.ibatis.common.xml.NodeletUtils.java
b.spring configuration file, ${} parsing, directly on the code
/*** Resolve placeholder values in the given array of patterns. * @returna new array with updated patterns*/ protectedstring[] Resolveembeddedvaluesinpatterns (string[] patterns) {if( This. Embeddedvalueresolver = =NULL) { returnpatterns; } Else{string[] resolvedpatterns=NewString[patterns.length]; for(inti=0; i < patterns.length; i++) {Resolvedpatterns[i]= This. Embeddedvalueresolver.resolvestringvalue (Patterns[i]); } returnResolvedpatterns; } }
The spring code is not very obscure, interested in child shoes research propertyplaceholderconfigurer (and if it does not find the XXX key defined in ${xxx}, it will also go to the JVM System Properties (System.getproperty () ) and Environment variables (system.getenv ()).
Summarize:
XML file, if ${} is used, the work of parsing depends on the third-party jar;
Meaning of use of ${} in XML (dollar sign curly braces, for example, Spring, Ibatis, MyBatis)