ITeye博客

作为笔记:Tomcat配置DataSource

NetBus · 2010-06-24 11:50 · Apache & Tomcat · Web前端 · Markdown

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

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

 再在Context中加入引用:

 <ResourceLink name="jdbc/DataSource" global="jdbc/DataSource"  type="javax.sql.DataSource"/>

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

 

在web.xml定义:

    <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中引用:

  <bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:comp/env/jdbc/DataSource"/>
        <property name="expectedType" value="javax.sql.DataSource"/>
    </bean>

 完成。

 

不知道为什么Tomcat非得要改web.xml指定引后才能引用Resource 。真烦人。

评论(1)

  1. #1 楼 · bluemusic · 2010-06-29 15:07

    其实你配置下没多少烦吧 而且现在用spring2.x <jee:jndi-lookup id="dataSource" jndi-name="helloHtcDesire" resource-ref="true" lookup-on-startup="true"/>

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