tomcat JNDI 设置

时间:2023-03-10 02:32:22
tomcat JNDI 设置
一、在Spring配置文件中的配置
  <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jndi/mybatis</value>
        </property>
    </bean>

二、在项目中web.xml的配置(这些标签就是用来建立当前应用环境到服务器资源的映射的)

<resource-ref>

  <description>JNDI DataSource</description>
  <res-ref-name>jndi/mybatis</res-ref-name>
  <res-ref-type>javax.sql.DataSource</res-ref-type>
  <res-auth>Container</res-auth>
</resource-ref>

三、在conf 中context.xml

<Resource name="jndi/mybatis" 
                auth="Container" 
                type="javax.sql.DataSource" 
                driverClassName="com.mysql.jdbc.Driver" 
                url="jdbc:mysql://localhost:3306/3dback" 
                username="root" 
                password="123456" 
                maxActive="20" 
                maxIdle="10" 
                maxWait="10000"/>