4
我试图通过Tomcat JNDI资源建立到我的数据库的连接。我今天一直在看许多文章,我似乎无法找到答案。如何在JAX-RS(Jersey)应用程序中使用JNDI资源?
在我server.xml中我有:
<GlobalNamingResources>
<Resource name="jdbc/MyDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="tomcat" password="...."
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3333/tomcat?autoReconnect=true"/>
.....
</GlobalNamingResources>
在我的web服务,我试图与访问资源:
InitialContext ctx = new InitialContext();
DataSource data = (DataSource)ctx.lookup("java:comp/env/jdbc/MyDB");
Connection conn = data.getConnection();
当我运行代码,我得到这个异常:
Nov 2, 2011 1:06:20 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
...
我在我的web应用程序的lib和我的Tomcat的lib两个最新mysql-connector-java-5.1.18-bin.jar
。
你能帮我搞定这个工作吗?
你找到任何解决这个?我正在寻找一种方法来做到这一点 – Joelmob
我也在寻找一个解决方案 –