jetty jdbc mysql 实例,Jetty mysql连接池配置错误:javax.naming.NameNotFoundException;剩余名称'env / jdbc / ---(mysq...

My configuration files

project/WEB-INF/web.xml:

ConnectionPool DataSource Reference

jdbc/mysql

javax.sql.DataSource

Container

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

jdbc/mysql

com.mysql.jdbc.Driver

jdbc:mysql://localhost:3306/db

user

pwd

50

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:

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

Thank you!

解决方案

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:

org.eclipse.jetty.webapp.configuration

org.eclipse.jetty.webapp.WebInfConfiguration

org.eclipse.jetty.webapp.WebXmlConfiguration

org.eclipse.jetty.webapp.MetaInfConfiguration

org.eclipse.jetty.webapp.FragmentConfiguration

org.eclipse.jetty.plus.webapp.EnvConfiguration

org.eclipse.jetty.plus.webapp.PlusConfiguration

org.eclipse.jetty.webapp.JettyWebXmlConfiguration

org.eclipse.jetty.webapp.TagLibConfiguration

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值