博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JNDI+Tomcat配置数据源的两种方式
阅读量:6293 次
发布时间:2019-06-22

本文共 3248 字,大约阅读时间需要 10 分钟。

非全局jndi配置步骤 :此种配置方式不需要在server.xml中配置数据源,而只在tomcat/conf/Catalina/localhost下的启动配置中配置即可。注意红色字体名称必须和相同。

0、需要在tomcat/common/lib下加入数据库连接的jar包

1、web.xml配置

<resource-ref>
     
<description>my DB Connection</description>
     
<res-ref-name>mydataSource </res-ref-name>  
     
<res-type>javax.sql.DataSource</res-type>
     
<res-auth>Container</res-auth>
 
</resource-ref>

2、applicationContext.xml下配置

<bean id=
"dataSource"
    
class
=
"org.springframework.jndi.JndiObjectFactoryBean"
>
    
<property name=
"jndiName" 
value=
"java:comp/env/mydataSource " 
/>
</bean>

3、在tomcat的conf下的localhost下的配置如下

<?xml version=
"1.0" 
encoding=
"UTF-8"
?>
<Context docBase=
"F:/workspace/cuapp/WebRoot" 
path=
"cuapp" 
reloadable=
"false"
>
<Resource name=
"mydataSource" 
auth=
"Container" 
type=
"javax.sql.DataSource"
                   
url=
"jdbc:oracle:thin:@192.168.2.104:1521:ora10g"
                
driverClassName=
"oracle.jdbc.driver.OracleDriver"
                
password=
"aa"
                
username=
"aa"
                
initialSize=
"2"
                
maxActive=
"3"
                
maxIdle=
"1"
                
minIdle=
"1"
                
maxWait=
"10000"
                
removeAbandoned=
"true"
                
logAbandoned=
"true"
                
removeAbandonedTimeout=
"60"
                
timeBetweenEvictionRunsMillis=
"900000"
                
minEvictableIdleTimeMillis=
"1800000"
                
numTestsPerEvictionRun=
"100"
                
validationQuery=
"select count(0) from dual"
                
poolPreparedStatements=
"true"
                
maxOpenPreparedStatements=
"100"
/>
</Context>

 

全局jndi配置 :此种配置需要在server.xml中配置数据源。 

0、需要在tomcat下加入数据库连接的jar包

1、web.xml配置

<resource-ref>
    
<description>my DB Connection</description>
    
<res-ref-name>mydataSource </res-ref-name>   must be same as server.xml
    
<res-type>javax.sql.DataSource</res-type>
    
<res-auth>Container</res-auth>
</resource-ref>

2、applicationContext.xml下配置

<bean id=
"dataSource"
    
class
=
"org.springframework.jndi.JndiObjectFactoryBean"
>
    
<property name=
"jndiName" 
value=
"java:comp/env/mydataSource " 
/>
</bean>

3、server.xml中配置为

<!-- Global JNDI resources -->
 
<GlobalNamingResources>
   
<!-- Test entry
for 
demonstration purposes -->
   
<Environment name=
"simpleValue" 
type=
"java.lang.Integer" 
value=
"30"
/>
   
<!-- Editable user database that can also be used by
        
UserDatabaseRealm to authenticate users -->
   
<Resource name=
"UserDatabase" 
auth=
"Container"
             
type=
"org.apache.catalina.UserDatabase"
      
description=
"User database that can be updated and saved"
          
factory=
"org.apache.catalina.users.MemoryUserDatabaseFactory"
         
pathname=
"conf/tomcat-users.xml" 
/>
   
<Resource name=
"mydataSource" 
auth=
"Container" 
type=
"javax.sql.DataSource"
                               
url=
"jdbc:oracle:thin:@192.168.2.104:1521:ora10g"
                           
driverClassName=
"oracle.jdbc.driver.OracleDriver"
                           
password=
"aa"
                           
username=
"aa"
                           
initialSize=
"5"
                           
maxActive=
"10"
                           
maxIdle=
"5"
                           
minIdle=
"2"
                           
maxWait=
"10000"
                           
removeAbandoned=
"true"
                           
logAbandoned=
"true"
                           
removeAbandonedTimeout=
"60"
                           
timeBetweenEvictionRunsMillis=
"900000"
                           
minEvictableIdleTimeMillis=
"1800000"
                           
numTestsPerEvictionRun=
"100"
                           
validationQuery=
"select count(0) from dual"
                           
poolPreparedStatements=
"true"
                           
maxOpenPreparedStatements=
"100"
/>
 
</GlobalNamingResources>

4、tomcat/conf下localhost下的配置如下

<?xml version=
"1.0" 
encoding=
"UTF-8"
?>
<Context docBase=
"F:/workspace/cuapp/WebRoot" 
path=
"xj-adminportal" 
reloadable=
"false"
>
    
<ResourceLink name=
"mydataSource " 
global=
"mydataSource " 
type=
"javax.sql.DataSource"
/>
</Context>
 
当一个人找不到出路的时候,最好的办法就是将当前能做好的事情做到极致,做到无人能及。

转载于:https://www.cnblogs.com/xuehen/p/4845619.html

你可能感兴趣的文章
mac pro 入手,php环境配置总结
查看>>
MyBatis-Plus | 最简单的查询操作教程(Lambda)
查看>>
rpmfusion 的国内大学 NEU 源配置
查看>>
spring jpa 配置详解
查看>>
IOE,为什么去IOE?
查看>>
Storm中的Worker
查看>>
dangdang.ddframe.job中页面修改表达式后进行检查
查看>>
Web基础架构:负载均衡和LVS
查看>>
Linux下c/c++相对路径动态库的生成与使用
查看>>
SHELL实现跳板机,只允许用户执行少量允许的命令
查看>>
SpringBoot 整合Redis
查看>>
2014上半年大片早知道
查看>>
Android 6.0指纹识别App开发案例
查看>>
正文提取算法
查看>>
轻松学PHP
查看>>
Linux中的网络监控命令
查看>>
this的用法
查看>>
windows下安装redis
查看>>
CentOS7 yum 安装git
查看>>
启动日志中频繁出现以下信息
查看>>