在用局部數據源去連數據庫的時候,在本地的項目中,都是可以的,可是一部署到服務器上,就報錯了。
報的錯誤是:javax.naming.NameNotFoundException:Name[ XXX] is not bound in this context.
查了下解決方案:在項目的web.xml中加入下面的代碼
<resource-ref> <description>DB Connection</description> <res-ref-name>zjut_echarts</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
加入以后呢,這個錯誤是消失了,但是又來了一個新的錯誤。
怎么辦,好呢?目前的解決方案是:C:\apache-tomcat-7.0.37\conf目錄下面的context.xml刪掉,把我們項目中的META-INF目錄下的context.xml文件復制到C:\apache-tomcat-7.0.37\conf目錄下