zoukankan      html  css  js  c++  java
  • spring配置JNDI(Java Naming and Directory Interface,Java命名和目录接口)数据源

    1.在tomcat下的server.xml的 <GlobalNamingResources> </GlobalNamingResources>添加下面代码

        <Resource name="jdbc/mysql" auth="Container"   
                    type="javax.sql.DataSource"  
                    driverClassName="com.mysql.jdbc.Driver"  
                    url="jdbc:mysql://127.0.0.1:3306/test"  
                    username="root"  
                    password="123456"  
                    maxActive="50"  
                    maxIdle="30"  
                    maxWait="10000" />  

    2.在于server.xml同目录的context.xml中的<context></context>添加下代码

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

    3.web.xml中可加也可不加下边的代码

      <resource-ref>
        <res-ref-name>jdbc/mysql</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-sharing-scope>Unshareable</res-sharing-scope>
      </resource-ref>

    4.spring的配置文件中添加下面代码

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

    5.测试,在jsp中测试

    <% Context context = new InitialContext();
       DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/mysql");
       Connection connection = ds.getConnection();
       connection.close();
    %>
  • 相关阅读:
    android system.img
    ab压力测试和CC预防
    ubuntu工具积累
    ViewManager
    PopupWindow
    singleton注意
    java byte[]生成
    java有符号无符号的转换
    C#垃圾回收Finalize 和Dispose的理解
    Silverlight 获取汉字拼音首字母
  • 原文地址:https://www.cnblogs.com/yxqing/p/10785771.html
Copyright © 2011-2022 走看看