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