一、J2EE数据源配置的标准是,
1、首先需要在Server.xml中配置数据源:
<Context docBase="TestDataSource" path="/TestDataSource" reloadable="true" source="org.eclipse.jst.j2ee.server:TestDataSource">
<Resource name="jdbc/TaskDB" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="neddy"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/task?autoReconnect=true"/>
</Context>
2、然后必须在web.xml中加入<resource-ref>元素<resource-ref>元素表示在Web应用中引用JNDI资源
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TaskDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
二、上面的过程为J2EE配置数据源的标准,比较麻烦并且比较单一(当然可能还有其他方法)
下面列举Tomcat配置数据源的方法:
1、如果是在Tomcat中配置数据源的话的,如果按照上面的方法配置数据源的话,只需要在Server.xml中配置数据源即可,无需再Web.xml中加入<resource-ref>元素<resource-ref>元素表示在Web应用中引用JNDI资源。
2、Tomcat应用服务器下的项目,数据源也可以在项目Application下META-INF/context.xml,路径创建context.xml文件,内配置数据源,如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/TaskDB" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="neddy"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/task?autoReconnect=true"/>
</Context>
三、英文文档链接和说明如下:
http://wiki.apache.org/tomcat/UsingDataSources
How do I use DataSources with Tomcat?
When developing J2EE web applications, the task of database connection management can be daunting. Best practice involves using a J2EE DataSource to provide connection pooling, but configuring DataSources in web application servers and connecting your application to them is often a cumbersome process and poorly documented.
The usual procedure requires the application developer to set up a DataSource in the web application server, specifying the driver class, JDBC URL (connect string), username, password, and various pooling options. Then, the developer must reference the DataSource in his application's web.xml configuration file, and then access it properly in his servlet or JSP. Particularly during development, setting all of this up is tedious and error-prone.
With Tomcat the process is vastly simplified. Tomcat allows you to configure DataSources for your J2EE web application in a context.xml file that is stored in your web application project. You don't have to mess with configuring the DataSource separately in the Tomcat server.xml, or referencing it in your application's web.xml file.
相关推荐
guns企业版多数据源配置,集成dynamic-datasource,同时支持mysql,oracle,支持多数据源数据分页
可以帮助你了解,以及配置实现DruidDataSource数据源的配置
tomcat配置datassource的详细过程
一个springboot的多数据配置,从mapper到controller完整的一个业务流程
spring mvc配置datasource数据源的三种方式,对spring的数据库连接源配置,有很大帮助,使你更加准确地了解数据源、连接池的实际使用方法
java SpringMVC动态数据源的DataSource工具类,springmvc中配置数据源为工具类中的数据源,多线程使用不同数据源配置
weblogic配置jdbc数据源weblogic配置jdbc数据源weblogic配置jdbc数据源
Spring Boot+Jpa多数据源配置Demo,可同时支持多种数据库,不同数据库,同时支持不同数据库的JdbcTemplate
p6spy dataSource 配置 监听真实sql语句
SpringBoot+dynamic-datasource实现多数据源(msyql、sqlserver)手动切换示例代码 https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/135701561
springboot配置多数据源,mysql,sqlserver;真实可用;
IOC容器数据源配置 <!-- 配置数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <value>org.gjt.mm.mysql.Driver <value>jdbc:mysql:/...
3, application.yml中配置了双数据源,根据需要可以加多个数据源,同时要在datasource包中新建数据源配置,参考那两个配置。 4, 启动项目,测试接口在DataSourceController中,只用注入相关的bean就能使用。 5, 使用...
自己学习:多数据源加载,定时任务 1、在application.yml中配置好数据源; 2、在datasource包下新建一个加载数据源的类; 3、在DataSourceConfiguration.java类中添加dao、mapper的路径常量。
多数据源配置代码 DataSource2Config.java
相信在很多使用MybatisPlus框架的小伙伴都会遇到多数据源的配置问题,并且官网也给出了推荐使用多数据源 (dynamic-datasource-spring-boot-starter) 组件来实现。由于最近项目也在使用这个组件来实现多数据源切换,...
在TomcatWeb服务器上配置数据源, 在TomcatWeb服务器上配置数据源,
Hikari连接池是Spring Boot 2.0+默认也是官方推荐的连接池,其卓越的性能,更适合高并发下的业务场景。
通过使用sharding-jdbc分库分表,以及多数据源的切换
配置MSSQL数据源连接步骤 [很卡,设置下了分辨率了] 1.打开MSSQL ,首先确定你这MSSQL是否为启动状态,从这看,应该是没有启动的 那好,现在启动SQL 好,现在已经启动 2.配置数据源 开始->控制面版->性能和维护...