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> < ;/bean></beans>
Dynamically set the path of spring configuration Propertyplaceholderconfigurer location