|
1
2
3
4
5
|
????<bean?id="dataSource"?class="org.springframework.jndi.JndiObjectFactoryBean">
?????????<property?name="jndiName">
??????????????<value>java:comp/env/jdbc/userDataSource</value>
?????????</property>
?????</bean>
|
|
1
2
3
4
5
6
|
??<resource-ref>
?????<description>my?DB?Connection</description>
?????<res-ref-name>jdbc/userDataSource</res-ref-name>
?????<res-type>javax.sql.DataSource</res-type>
?????<res-auth>Container</res-auth>
??</resource-ref>
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
????<Resource?name="jdbc/userDataSource"??????????????????auth="Container"
???????????????type="javax.sql.DataSource"?????????????? ??????????????????driverClassName="com.mysql.jdbc.Driver"??????????????????url="jdbc:mysql://ip/myDataDaseName"? ????????????????username="root"
???????????????password="password"
???????????????maxIdle="40"???????????????????maxWait="4000"????????????????maxActive="250"????????????????removeAbandoned="true"
???????????????removeAbandonedTimeout="180"
???????????????logAbandoned="true"
???????????????factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"?/>??
|
|
1
|
org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
value?=?properties.getProperty("password");
????if?(value?!=?null)?{
??????dataSource.setPassword(value);
????}
?
????value?=?properties.getProperty("url");
????if?(value?!=?null)?{
??????dataSource.setUrl(value);
????}
?
????value?=?properties.getProperty("username");
????if?(value?!=?null)?{
??????dataSource.setUsername(value);
????}
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
?value?=?properties.getProperty("password");
????if?(value?!=?null)?{
??????dataSource.setPassword(decode(value));?//解密操作
??}
??//自定义的解密方法,里面引用了AESEncrypt数字签名加密文件,config.properties里面配置了key钥
?private?static?String?decode(String?password)?throws?Exception?{
????byte[]?bas?=?AESEncrypt.parseHexStr2Byte(password);
????InputStream?is?=?new?FileInputStream("/opt/config/config.properties");
????Properties?prop?=?new?Properties();
?
????prop.load(is);
????String?key?=?prop.getProperty("key");
????is.close();
????byte[]?decr?=?AESEncrypt.decrypt(bas,?key);
????return?new?String(decr);
??}
|
|
1
|
?factory="org.apache.tomcat.dbcp.dbcp.DecodeBasicDataSourceFactory"
|
原文:http://jlins.iteye.com/blog/2162090