如何在Tomcat中创建没有池的数据源 [英] How to Create Data Source without Pooling in Tomcat

查看:150
本文介绍了如何在Tomcat中创建没有池的数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JNDI上下文在Tomcat的context.xml文件中为JDBC驱动程序创建数据源,如下所示,

I use JNDI context to create datasource for JDBC drivers in Tomcat's context.xml file like this,

<Resource name="db/test" 
          type="javax.sql.DataSource" 
          driverClassName="com.test.jdbc.Driver"
          url="jdbc:fastdb://localhost:3306/session_db?autoReconnect=true&amp;connectTimeout=5000&amp;socketTimeout=5000"
          zeroDateTimeBehavior="convertToNull"
          username="dbuser"
          password="password"
          maxActive="100"
          maxWait="2"
          removeAbandoned="true"
          removeAbandonedTimeout="60"
          logAbandoned="true" />

默认情况下,Tomcat将使用DBCP数据源工厂并创建池化数据源。我们使用的特定数据库和驱动程序已经支持较低级别的池,而额外的池实际上会损害性能。有没有使用像这样的JNDI资源创建基本数据源(没有池)所以我可以在最小配置更改的情况下在不同的数据库之间切换?

By default, Tomcat will use DBCP data source factory and created pooling data sources. The specific database and driver we use already supports pooling in lower level and the extra pooling actually hurts performance. Is there anyway to create basic datasource (without pooling) using JNDI resource like this so I can switch between different databases with minimum configuration changes?

我知道我可以自己编写数据源工厂或使用其他驱动程序来实现这一点,但我正在寻找一个更简单的解决方案。

I know I can write my own datasource factory or use the ones from other drivers to achieve this but I am looking for an easier solution.

推荐答案

不太确定,如果这是满足你的东西,但你总是可以使用 Spring JDBC支持,不使用Tomcat管理的数据源。

Not quite sure, if this is something that would satisfy you, but you can always use Spring JDBC support without using datasources managed by Tomcat.

这篇关于如何在Tomcat中创建没有池的数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆