jetty使用jndi資料來源,jettyjndi

來源:互聯網
上載者:User

jetty使用jndi資料來源,jettyjndi

  之前將項目正常的資料來源統一切換成jndi訪問的形式(是將c3p0以mbean形式安裝到jboss做的資料連線池),

  本地測試用的jetty伺服器,為了統一資料庫訪問部分,我也查看文檔找到了jetty提供jndi資料來源的配置方式,簡單如下:

 

1. 在項目路徑下建立jetty.xml, jetty預設的設定檔,在server添加如下內容

<Configure id="Server" class="org.eclipse.jetty.server.Server">
     <New id="scmsDs" class="org.eclipse.jetty.plus.jndi.Resource">
         <Arg></Arg>

         <!--jndiname-->
        <Arg>java:scmsDS</Arg>
        <Arg>
            <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
                 <Set name="driverClass">${jdbc.driverClassName}</Set>
                 <Set name="jdbcUrl">${jdbc.url}</Set>
                 <Set name="user">${jdbc.username}</Set>
                 <Set name="password">${jdbc.password}</Set>
           </New>

       </Arg>

     <!-- New  ...  another jndi datasource pool -->

</Configure>

如上,最簡單的配置,只需定義一個jndiname,和一個c3p0串連池,jetty同樣支援配置多個串連池。

2.配置jetty啟動時載入jetty.xml

我們項目是用maven外掛程式的形式啟動jetty的,其他形式應該也是大同小異吧。

注意datasouce需要對c3p0和jdbc驅動依賴,如果項目本身沒有這些依賴,在jetty中要

特別聲明。如下

<plugin>
     <groupId>org.mortbay.jetty</groupId>
     <artifactId>jetty-maven-plugin</artifactId>
     <version>8.1.2.v20120308</version>
     <dependencies>
         <dependency>
             <groupId>c3p0</groupId>
             <artifactId>c3p0</artifactId>
             <version>0.9.1.2</version>
         </dependency>
         <dependency>
             <groupId>com.oracle.jdbc</groupId>
             <artifactId>ojdbc5</artifactId>
             <version>11.2.0.3</version>
         </dependency>
      </dependencies>
      <configuration>
           <jettyXml>${project.build.outputDirectory}/jetty.xml</jettyXml>
           <!-- other configuration -->
      </configuration>
</plugin>

3. 在項目中使用該資料來源

和所有jndi服務一樣,如果有用架構的話,比如spring架構下,讓spring幫你完成lookup:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.