Dynamically set the path of spring configuration Propertyplaceholderconfigurer location

Source: Internet
Author: User

In spring, you often place commonly used attributes in the properties file, and then use Propertyplaceholderconfigurer to reference the properties file in spring's configuration file.
For Web projects, the path to the configuration file can be obtained through a relative path, and for an executable project, the path to the properties configuration file is specified in the context of the individual environment for the execution of the projects.
For this scenario, you can place the path of the configuration file in a custom variable for the Java Virtual machine JVM, for example:-dconfig.path=/yourpath/1.properties
It is possible to refer to the values of the JVM custom variables using $config.path in the configuration file as follows:

<?xml version="1.0"encoding="UTF-8"?> <! DOCTYPE Beans Public"-//SPRING/DTD bean/en""HTTP://WWW.SPRINGFRAMEWORK.ORG/DTD/SPRING-BEANS.DTD"> <beans> <bean id="Configbean"  class="Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name=" Location"> <value> $config .path</value> </property> </bean> <bean Id="Hellobean" class="Onlyfun.caterpillar.HelloBean"> <property name="Helloword"> <value>${onlyfun.caterpillar.helloWord}</value> </property> &lt ;/bean></beans>

Dynamically set the path of spring configuration Propertyplaceholderconfigurer location

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.