Distributed assembly of assembly beans in study notes

Today I learned another method in the assembly bean, scattered assembly

significance:

for example:

If the attribute value of the name configured in the xml file has other beans that want to use this data , it must be input again , just like bean1 and bean2. The amount of information tested is small, so no difference is felt. If the amount of information to be processed is very large There is a big difference between the two methods

bean1 _

bean2 _

If the data they need to share is placed in another place and taken out when needed, it will be very convenient, and decentralized assembly just perfectly solves this problem.

First create the xml file as usual and configure a bean. , there are only simple set and get methods in the java file

    

We put the data that needs to be shared into a test.property file, that is, the three values ​​of the three properties


Next change the configuration in the xml file:


Instead of using the previous method, use placeholders instead. Note that the strings in "${}" must correspond to each name of test.property to be successfully extracted from it.

But this is not enough so that the test.property and xml files cannot be associated

Next, a little configuration is required

<context:property-placeholder location="classpath:it/dispatcher/test.property/>

Just import its path. Note that the delimiter here is /

If there are two property files, two <context/> tags are not allowed in the xml file , but they can be placed in the same tag and separated by commas.

<context:property-placeholder  location="classpath:it/dispatcher/test.property,classpath:it/dispatcher/test2.property"  />


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325602164&siteId=291194637