JNDI在本项目中的应用
一,在tomcat的context文件中做如下配置
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/ORG" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/WX-PORTAL" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="oracle.jdbc.driver.OracleDriver" factory="com..seashell.encrypt.C3p0BeanFactory" jdbcUrl="jdbc:oracle:thin:@ip地址:1530:billdb" maxPoolSize="5" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="org.gjt.mm.mysql.Driver" factory="com..seashell.encrypt.C3p0BeanFactory" idleConnectionTestPeriod="3600" jdbcUrl="jdbc:mysql://ip地址:3306/b2b_portal?useUnicode=true&characterEncoding=UTF-8" maxIdleTime="3600" maxPoolSize="30" minPoolSize="3" name="/JDBC/-" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="org.gjt.mm.mysql.Driver" factory="com..seashell.encrypt.C3p0BeanFactory" idleConnectionTestPeriod="3600" jdbcUrl="jdbc:mysql://ip地址:3306/appmobile?useUnicode=true&characterEncoding=UTF-8" maxIdleTime="3600" maxPoolSize="30" minPoolSize="3" name="/JDBC/" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="org.gjt.mm.mysql.Driver" factory="com..seashell.encrypt.C3p0BeanFactory" idleConnectionTestPeriod="3600" jdbcUrl="jdbc:mysql://ip地址:3306/oss?useUnicode=true&characterEncoding=UTF-8" maxIdleTime="3600" maxPoolSize="30" minPoolSize="3" name="/JDBC/OSS" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
<Resource acquireIncrement="2" auth="Container" driverClass="org.gjt.mm.mysql.Driver" factory="com..seashell.encrypt.C3p0BeanFactory" idleConnectionTestPeriod="3600" jdbcUrl="jdbc:mysql://ip地址:3306/boss?useUnicode=true&characterEncoding=UTF-8" maxIdleTime="3600" maxPoolSize="30" minPoolSize="3" name="/JDBC/ORG" password="" type="com.mchange.v2.c3p0.ComboPooledDataSource" user=""/>
</Context>
二,在初始化的xml中进行配置,注意它要被写在web.xml中的扫描到。
例如:web.xml中的配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:context/*.xml,
classpath*:context/*.xml,
classpath*:context/ibatis/*.xml,
</param-value>
</context-param>
然后在在context的文件下建立一个xml文件,注意这里不一定非的和项目名字一样,随便写就行了。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="mobileDS" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env//JDBC/WX-PORTAL" />
</bean>
<bean id="bossDS" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/JDBC/ORG" />
</bean>
<!-- b2b-portal 数据源配置 -->
<bean id="dataSource" class="com..boss.ds.util.DynamicDataSource" >
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry key="appmobile" value-ref="mobileDS" ></entry>
<entry key="org" value-ref="bossDS" ></entry>
</map>
</property>
</bean>
<!--事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"/>
<aop:config>
<aop:advisor pointcut="execution(* com..*.service..*Service.*(..))"
advice-ref="txAdvice" order="1" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
</beans>
这样就可以随意的切换数据源了。
JNDI在本项目中的应用的更多相关文章
- 转 web项目中的web.xml元素解析
转 web项目中的web.xml元素解析 发表于1年前(2014-11-26 15:45) 阅读(497) | 评论(0) 16人收藏此文章, 我要收藏 赞0 上海源创会5月15日与你相约[玫瑰里 ...
- JNDI和在tomcat中配置DBCP连接池 元数据的使用 DBUtils框架的使用 多表操作
1 JNDI和在tomcat中配置DBCP连接池 JNDI(Java Naming and Directory Interface),Java命名和目录接口,它对应于J2SE中的javax.namin ...
- 通过JNDI从服务器容器中获取资源_Spring JNDI+Mysql+Tomcat
通过JNDI从服务器容器中获取DataSource资源 (由容器管理,不要关闭它,容器自己会处理)上一篇我们使用的是dbcp,这里使用JNDI: 使用JNDI连接数据: 在Spring可以注释 < ...
- tomcat项目中配置数据库连接池
1. 在项目中新建context.xml文件,不要在tomcat服务器的目录中修改context.xml(会对整个服务器生效).. 在web项目的META-INF中存放context.xml 2. ...
- 【J2EE】在项目中理解J2EE规范
J2EE平台由一整套服务(Service),应用程序接口(API)和协议构成,它对开发企业级应用提供了功能支持.13个核心技术各自是JDBC, JNDI, EJB, RMI, JSP ...
- VS项目中使用Nuget还原包后编译生产还一直报错?
Nuget官网下载Nuget项目包的命令地址:https://www.nuget.org/packages 今天就遇到一个比较奇葩的问题,折腾了很久终于搞定了: 问题是这样的:我的解决方案原本是好好的 ...
- ABP项目中使用Swagger生成动态WebAPI
本文是根据角落的白板报的<使用ABP实现SwaggerUI,生成动态webapi>一文的学习总结,感谢原文作者角落的白板报. 1 安装Swashbuckle.core 1.1 选择WebA ...
- iOS 之项目中遇到的问题总结
昨天去一家公司面试,面试官问了我在项目开发中遇到过哪些问题,是什么引起的,怎样解决的? 当时由于有点小紧张只说出了一两点,现在就来好好总结一下. 问题: 1.两表联动 所谓的两表联动就是有左右两个表格 ...
- My97DatePicker时间控件在项目中的应用
一.下载My97DatePicker的压缩包My97DatePicker.rar,解压. 注:My97DatePicker最新版本有开发包,项目中使用时删掉,以便节省空间,提高程序的运行效率. 二.在 ...
随机推荐
- 51NOD 1238 最小公倍数之和 V3 [杜教筛]
1238 最小公倍数之和 V3 三种做法!!! 见学习笔记,这里只贴代码 #include <iostream> #include <cstdio> #include < ...
- UVA概率练习[2]
UVa11021 Tribbles 你有K个麻球.一个只会存活一天.在死亡之前,一个麻球有P_i的概率生出i个麻球(i=0,1,…,n-1).m天后所有麻球都死亡的概率是多少?(包含在第m天前全部死亡 ...
- 利用Needleman–Wunsch算法进行DNA序列全局比对
生物信息学原理作业第二弹:利用Needleman–Wunsch算法进行DNA序列全局比对. 具体原理:https://en.wikipedia.org/wiki/Needleman%E2%80%93W ...
- zabbix_server 挂了原因及解决方法(内存溢出)
14721:20170714:095330.028 [file:dbconfig.c,line:452] zbx_mem_malloc(): out of memory (requested 80 b ...
- mdb导入SqlServer
弄了一份医案数据库,打开一看...命名全中文,好吧,导入SQLServer走起 SQL: SELECT * INTO newtable FROM OPENDATASOURCE ('Microsoft. ...
- Windows Server 2016-存储新增功能
本章给大家介绍有关Windows Server 2016 中存储方面的新增功能,具体内容如下: 1.Storage Spaces Direct: 存储空间直通允许通过使用具有本地存储的服务器构建高可用 ...
- Visual Studio 2017 Enterprise 发布 15.3.3 版,附离线安装包百度网盘下载。
Visual Studio 2017 Enterprise 发布 15.3.3 版,附离线安装包百度网盘下载. Visual Studio 2017 Enterprise 更新至 15.3.3 ,本安 ...
- slf4j-logback 日志以json格式导入ELK
同事整理的,在此分享.logback,log4j2 等slf4j的日志实现都可以以json格式输出日志, 这里采用的是logback.当然也可以以文本行的格式输出,然后在logstash里通过grok ...
- SpringBoot Hello World
本文首发于我的github博客 前言 SpringBoot是Spring MVC升级版,基于『约定优于配置』的原则,快速开发出web程序. 环境 本系列笔记环境如下: Sun JDK1.8.0_20 ...
- Spring data mongodb 聚合,投射,内嵌数组文档分页.
尽量别直接用 DBObject ,Spring data mongodb 的api 本来就没什么多大用处,如果还直接用 DBObject 那么还需要自己去解析结果,说动做个对象映射,累不累 Spri ...