Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称'env / jdbc / ---(mysql 5.0 + jetty 7.0.1) [英] Jetty mysql connection-pool configuration error: javax.naming.NameNotFoundException; remaining name 'env/jdbc/---(mysql 5.0+jetty 7.0.1)

查看:198
本文介绍了Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称'env / jdbc / ---(mysql 5.0 + jetty 7.0.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的配置文件

项目/ WEB-INF / web.xml

<resource-ref>
    <description>ConnectionPool DataSource Reference</description>
    <res-ref-name>jdbc/mysql</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

project / WEB-INF / jetty-env.xml:

project/WEB-INF/jetty-env.xml:

<New id="mysql" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
<Arg>jdbc/mysql</Arg>
    <Arg>
        <New class="org.apache.commons.dbcp.BasicDataSource">
            <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
            <Set name="url">jdbc:mysql://localhost:3306/db</Set>
            <Set name="username">user</Set>
            <Set name="password">pwd</Set>
            <Set name="maxActive">50</Set>
        </New>
    </Arg>
</New>






要调用的代码:




code to invoke:

ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mysql");
con=ds.getConnection();






启动码头的脚本:


scripts to start jetty:

java -DOPTIONS=plus -jar start.jar

java -jar start.jar

无论哪种方式启动码头,都会出现以下错误:

Either way to start jetty, I got following error:

javax.naming.NameNotFoundException; remaining name 'env/jdbc/mysql'
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:632)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:663)
        at org.eclipse.jetty.jndi.NamingContext.lookup(NamingContext.java:678)
        at org.eclipse.jetty.jndi.java.javaRootURLContext.lookup(javaRootURLContext.java:110)
        at javax.naming.InitialContext.lookup(Unknown Source)






问题是:


The questions are:


  • 这里有什么问题?

  • 需要其他任何配置吗?

  • 放置以下jar文件的位置:


    • commons-dbcp-1.2.2 .jar

    • mysql-connector-java-5.1.10-bin.jar

    • what is the problem here?
    • Any other configurations needed?
    • where to put following jar files:
      • commons-dbcp-1.2.2.jar
      • mysql-connector-java-5.1.10-bin.jar

      谢谢!

      推荐答案

      注意:以下假设您使用的是Jetty 7.2 .2+(可能适用于任何Jetty 7.0 +)。



      oblem是你缺少一个额外的间接层。即使你已经在webapp中配置了Jetty,你仍然需要告诉Jetty容器它需要在你的webapp中查找jetty-env.xml。为此,请将以下内容添加到您的jetty.xml($ {JETTY_INSTALL_DIR} / etc下:

      Note: The following assumes you're using Jetty 7.2.2+ (probably works with any Jetty 7.0+).

      The problem is you're missing ONE extra layer of indirection. Even though you've configured Jetty in your webapp, you still need to tell the Jetty container that it needs to look for jetty-env.xml in your webapp. To do that, add the following to your jetty.xml (under ${JETTY_INSTALL_DIR}/etc:

      <Call name="setAttribute">
        <Arg>org.eclipse.jetty.webapp.configuration</Arg>
        <Arg>
            <Array type="java.lang.String">
                <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
                <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
                <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
            </Array>
        </Arg>
      </Call>
      

      现在Jetty将知道解析你创建的jetty-env.xml。

      NOW Jetty will know to parse the jetty-env.xml you've created.

      这篇关于Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称'env / jdbc / ---(mysql 5.0 + jetty 7.0.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆