Decrypt the spring loaded properties file

Source: Internet
Author: User
Tags decrypt

In the spring framework, the Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer class can use the. Properties (Key/value form) In the file
Some dynamically set values (value), replaced in XML with a placeholder for the value of the key ($key $),
The. properties file can customize some of the relevant parameters according to customer requirements, so that the design provides the flexibility of the program.

The configuration file in XML

<BeanID= "Propertyconfigurer"class= "Com.datasure.util.filter.EncryptablePropertyPlaceholderConfigurer"> < Propertyname= "Locations"> <List><value>Classpath:jdbc.properties</value></List> </ Property> </Bean>
 Public classEncryptablepropertyplaceholderconfigurerextendsPropertyplaceholderconfigurer {Private Static FinalString key = "HelloWorld"; protected voidprocessproperties (configurablelistablebeanfactory beanfactory, Properties props)throwsbeansexception {Try{des des=NewDes (); String username= Props.getproperty ("Jdbc.username"); if(Username! =NULL) {Props.setproperty ("Jdbc.username", Des.                Decrypt (username, des.hex2byte (key))); } String Password= Props.getproperty ("Jdbc.password"); if(Password! =NULL) {Props.setproperty ("Jdbc.password", Des.                Decrypt (password, des.hex2byte (key))); } String URL= Props.getproperty ("Jdbc.url"); if(URL! =NULL) {Props.setproperty ("Jdbc.url", Des.                Decrypt (URL, des.hex2byte (key))); } String driverclassname= Props.getproperty ("Jdbc.driverclassname"); if(Driverclassname! =NULL) {Props.setproperty ("Jdbc.driverclassname", Des.                Decrypt (Driverclassname, Des.hex2byte (key))); }                                Super. Processproperties (beanfactory, props); } Catch(Exception e) {e.printstacktrace (); Throw Newbeaninitializationexception (E.getmessage ()); }        }    }

The configuration file can be decrypted by configuring it as above

Decrypt the spring loaded properties file

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.