SSH项目配置数据源的方法(jndi)

1.在tomcat6.0/conf/context.xml加入以下代码

[xhtml] view plain copy

    <Resource name="jdbc/oracleDB" auth="Container" type="javax.sql.DataSource"   
            driverClassName="oracle.jdbc.driver.OracleDriver"   
            username="***" password="**"  
            url="jdbc:oracle:thin:@192.168.*.*:1521:test"  
            maxActive="50"   maxIdle="10" maxWait="20000" initialSize="5"   
               
            />  

 

2.在项目的配置文件中applicationContext.xml文件中加入以下代码:

[xhtml] view plain copy

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

3.在web.xml文件中加入以下代码

[xhtml] view plain copy

    <resource-ref>  
            <res-ref-name>jdbc/oracleDB</res-ref-name>  
            <res-type>javax.sql.DataSource</res-type>  
            <res-auth>Container</res-auth>  
        </resource-ref> 
posted @ 2016-01-19 14:07  宝贝企鹅  阅读(797)  评论(0编辑  收藏  举报