ITeye博客

tomcat配置数据源(转载)

dingjun1 · 2012-02-23 10:57 · 数据库 · 企业应用设计 · 数据库 · Markdown

转载:http://www.douban.com/note/78355269/

修改Tomcat_Home/conf/server.xml,在GlobalNamingResources中加入:

Xml代码

  1. <Resource name="jdbc/DataSource" auth="Container"
  2. type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
  3. url="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
  4. username="user" password="password" maxActive="20" maxIdle="10"
  5. maxWait="-1"/>

再在Context中加入引用:

Xml代码

如果不加,则在使用的时候会出现:Cannot create JDBC driver of class '' for connect URL 'null' 错误

在web.xml定义:

Xml代码

  1. <description>popuserDataSource</description>  
    
  2. <res-ref-name>jdbc/DataSource</res-ref-name>  
    
  3. <res-type>javax.sql.DataSource</res-type>  
    
  4. <res-auth>Container</res-auth>  
    
<resource-ref>
    <description>popuserDataSource</description>
    <res-ref-name>jdbc/DataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

在Spring中引用:

Xml代码

  1.   <property name="jndiName" value="java:comp/env/jdbc/DataSource"/>  
    
  2.   <property name="expectedType" value="javax.sql.DataSource"/>  
    

完成。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。