【问题标题】:embedded jetty with weld - how to set up jdbc带焊接的嵌入式码头 - 如何设置 jdbc
【发布时间】:2013-12-25 16:32:36
【问题描述】:

我正在从 glassfish 迁移到嵌入式码头。 我已经将嵌入式码头配置为使用焊接的 CDI 并且它可以工作。 我想连接到 AS400 DB2 数据库,但在配置时遇到了问题。

我的 glassfish-resources.xml 如下所示:

<jdbc-connection-pool name="db2_pool"
                      datasource-classname="com.ibm.as400.access.AS400JDBCDataSource"
                      res-type="javax.sql.ConnectionPoolDataSource"
                      driver-classname="">
    <description />
    <property name="DatabaseName" value="xxx"></property>
    <property name="ServerName" value="1.1.1.1"></property>
    <property name="naming" value="SYSTEM"></property>
    <property name="User" value="user"></property>
    <property name="Password" value="pass"></property>
    <property name="URL" value="jdbc:as400://1.1.1.1;libraries=db2"></property>
    <property name="libraries" value="DB2"></property>          
</jdbc-connection-pool>

有谁知道如何配置 jetty-env.xml 和 web.xml 以与 jetty 9.1 相同

谢谢!

【问题讨论】:

  • 什么版本的 Jetty? (具体一点!它很重要)
  • 您找到问题的答案了吗?

标签: embedded-jetty


【解决方案1】:

假设 Jetty 9.1

见:http://www.eclipse.org/jetty/documentation/current/jndi-configuration.html#configuring-datasources

在你的WEB-INF/jetty-env.xml

<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="db2_pool" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg><Ref refid="wac"/></Arg>
    <Arg>jdbc/db2_pool</Arg>
    <Arg>
      <New class="com.ibm.as400.access.AS400JDBCDataSource">
        <Set name="DatabaseName">xxx</Set>
        <Set name="ServerName">1.1.1.1</Set>
        <Set name="naming">SYSTEM</Set>
        <Set name="User">user</Set>
        <Set name="Password">pass</Set>
        <Set name="URL">jdbc:as400://1.1.1.1;libraries=db2"></Set>
        <Set name="libraries">DB2</Set>
      </New>
    </Arg>
  </New>
</Configure>

然后你有一个 WEB-INF/web.xml 部分

<resource-ref>
  <res-ref-name>jdbc/db2_pool</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

最后,在您的代码中,您可以通过...访问它

import javax.naming.InitialContext;
import javax.sql.DataSource;

public class MyClass {

  public void myMethod() {

    InitialContext ic = new InitialContext();
    DataSource myDS = (DataSource)ic.lookup("java:comp/env/jdbc/db2_pool");     

    ...
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-23
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    相关资源
    最近更新 更多