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
我也在尋找一個解決方案 –