tomcat配置jndi连接数据库(druid连接池)
·
tomcat配置jndi连接数据库(druid连接池)
1、将驱动包复制到tomcat安装目录下的lib文件夹
druid-1.1.9.jar
log4j-1.2.17.jar
2、在tomcat安装目录下conf/context.xml文件加入一个Resource
<Resource name="vtas"
factory="com.alibaba.druid.pool.DruidDataSourceFactory"
auth="Container"
type="javax.sql.DataSource"
url="jdbc:oracle:thin:@//txn-cluster:1521/shqhtxn"
driverClassName ="oracle.jdbc.driver.OracleDriver"
username="abc"
password="123456"
initialSize = "30"
maxActive="200"
minIdle="30"
maxWait="-1"
testOnBorrow="true"
validationQuery="select 1 from dual"
connectionProperties = "config.decrypt=false" filters= "config,stat,wall"
/>
3、spring的数据源配置
<!-- PRD环境 -->
<beans profile="prd">
<context:property-placeholder ignore-unresolvable="true" location="classpath:/env/configurations-prd.properties" />
<!-- 数据源配置,使用应用服务器的数据库连接池 -->
<jee:jndi-lookup id="dataSource" jndi-name="${jndi.name}" />
</beans>
4、配置密码密文的情况
1)将密码用com.alibaba.druid.filter.config.ConfigTools类加密
调用方法:
ConfigTools.encrypt(String cipherText); //这个是没有公私钥的加密
ConfigTools.encrypt(String key, String plainText); //这个是有公私钥的加密
2)修改Resource定义
password换成密文
没有公私钥时:connectionProperties = "config.decrypt=true" filters= "config,stat,wall"
有公私钥时:connectionProperties = "config.decrypt=true;config.decrypt.key=生成的publicKey" filters= "config,stat,wall"
参考资料:
https://www.cnblogs.com/wuyanshun/p/6763162.html
https://blog.csdn.net/qgnczmnmn/article/details/97394899
更多推荐

所有评论(0)