Instructions for reading the properties file with ${xxx} in Spring

Source: Internet
Author: User

Properties if loaded through Propertyplaceholderconfigurer in spring, you can take advantage of some of the key and value values in the properties that are needed in spring porpertyplace Holderconfiger provides direct access to the $.

Porpertyplaceholderconfiger has some common properties that may be used in some advanced applications

    • Locations
    • fileencoding the encoding format of the properties file
    • If more than one propertyplaceholderconfigurer is defined in the order file, this property specifies the precedence order.
    • The Placeholderprefix default prefix placeholder is "${".  You can change to a different prefix as needed. --- This feature estimate is the reason that spring can use ${xxx} to get the contents of the properties file, that is, it is estimated that spring will see the ${placeholder in Propertyplaceholderconfigurer to find The properties file it loads, so that spring can use ${} to obtain property values in the attributes.
    • Placeholdersuffix The default suffix placeholder is "}".
    • Because Propertyplaceholderconfigurer has a very rich built-in feature, if it does not find the XXX key defined in ${xxx}, it also goes to the JVM System Properties (System.getproperty () ) and Environment variables (system.getenv ()). By enabling the Systempropertiesmode and Searchsystemenvironment properties, developers can control this behavior.
    • ${} can also be used directly on Java beans on the class, see: Http://www.cnblogs.com/wzhanke/p/4838890.html

Examples are as follows:

<bean

class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" ><property name= "Locations" ><list><value>classpath*:* .properties</value></list></property></bean> <bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "Close" > <property Name= "Driverclass" value= "${driverclass}" ></property>---> indicates that the properties file has Driverclass = AAA, via ${ Driverclass} will be able to get AAA value <property name= "Jdbcurl" value= "${url}" ></property></bean>

Instructions for reading the properties file with ${xxx} 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.