How to replace the custom Property in the Application Context definition file

xiaoxiao2021-03-06  186

How to replace the custom Property in the Application Context definition file

Problem Description:

In Application Context definition files (such as XXX-Servlet.xml, ApplicationContext.xml, sometimes some custom Property, such as DataSource definition

$ {jdbc.driverclassname}

$ {jdbc.url}

$ {jdbc.username}

$ {jdbc.password}

Or may sometimes require the root path or system variable of Application.

solution:

Using Org.SpringFramework.beans.Factory.config.PreferenceSplaceholderConfigurer,

The design intent of this class is to solve this problem. It first uses user-defined variables and then uses system variables, and then the variable of this configuration file.

Specific usage:

1. Declare this class

2. Set the parameters (can be empty)

l location: Specify the path to a Properties file