MyBatis XML configuration file extension element properties

Three configurations mentioned in the analysis of MyBatis XML configuration file properties of elements, of which property sub-elements and properties files are easier to understand, but why provide a way of code parameters passed it?

Using a scenario is assumed, production contact database is encrypted, it need jdbc.properties file stored as ciphertext, and decryption MyBatis default does not support direct reading, this time reading the need to decrypt the program.

1
2
3
4
5
6
7
8
9
10
String configResource = "mybatis-config.xml";
InputStream configInputStream = Resources.getResourceAsStream(configResource);

Big Box   MyBatis XML configuration file extension element properties > String propertiesResource = "jdbc.properties";
InputStream propertiesInputStream = Resources.getResourceAsStream (propertiesResource);
the Properties properties = new new the Properties ();
Properties.load (propertiesInputStream);

properties.setProperty(decode(properties.getProperty("key")));
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream, properties);

Decryption methods to achieve:

1
2
3
private String decode(String value) {
// TODO
}

Here are just introduce the idea of ​​using

Guess you like

Origin www.cnblogs.com/lijianming180/p/12037716.html