javax.naming.NameNotFoundException:在此上下文中未綁定名稱。找不到
確定發(fā)現(xiàn)Tomcat文件server.xml也必須配置為數(shù)據(jù)源正常工作。因此,只需添加:
<Resource auth='Container' driverClassName='org.apache.derby.jdbc.EmbeddedDriver' maxActive='20' maxIdle='10' maxWait='-1' name='ds/flexeraDS' type='javax.sql.DataSource' url='jdbc:derby:flexeraDB;create=true' />解決方法
我試圖找出為什么我的Web應(yīng)用程序拋出一個
javax.naming.NameNotFoundException: Name [flexeraDS] is not bound in this Context. Unable to find [flexeraDS].
當(dāng)我從中復(fù)制配置的一個姐妹悄悄地運行時。
我有:
通過右鍵單擊并選擇“新的持久性”從netbeans創(chuàng)建一個新的持久性,我不在乎我提供的實際值,但只需要在正確的目錄中創(chuàng)建persistence.xml文件即可。如下編輯我的context.xml,以匹配工作姐妹項目中的那個編輯了我的web.xml以包含資源DataSource,如下所示如下編輯我的persistence.xml,再次匹配在姐妹項目上工作的相同值。在我的lib文件夾中添加了另一個項目中存在的所有庫,還從NetBeans中添加了它們,以正確放入war。context.xml<?xml version='1.0' encoding='UTF-8'?><Context antiJARLocking='true' path='/PetLogin'> <ResourceLink global='ds/flexeraDS' name='ds/flexeraDS' type='javax.sql.DataSource'/></Context>web.xml
<?xml version='1.0' encoding='UTF-8'?><web-app ....><resource-ref><description>DB Connection</description><res-ref-name>ds/flexeraDS</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth> </resource-ref></web-app>persistence.xml
<?xml version='1.0' encoding='UTF-8'?><persistence version='1.0' xmlns='http://java.sun.com/xml/ns/persistence' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd '> <persistence-unit name='flexerajpa'><provider>org.eclipse.persistence.jpa.PersistenceProvider</provider><non-jta-data-source>java:/comp/env/ds/flexeraDS</non-jta-data-source><properties> <property name='eclipselink.ddl-generation' value='create-tables' /> <property name='eclipselink.ddl-generation.output-mode' value='database' /> <property name='eclipselink.weaving' value='static' /> <property name='eclipselink.logging.level' value='WARNING' /></properties> </persistence-unit></persistence>
現(xiàn)在,我的系統(tǒng)項目以某種方式設(shè)法在啟動時在apache-tomcat-7.0.40 / bin /exampleDB內(nèi)創(chuàng)建其數(shù)據(jù)庫文件夾,而我的系統(tǒng)未創(chuàng)建它并引發(fā)如上所述的錯誤。
引發(fā)錯誤的代碼是我第一次連接數(shù)據(jù)庫:
EntityManager entityManager = PersistenceProvider.createEntityManager();
其中PersistenceProvider類為:
public final class PersistenceProvider{ private static Map<String,Object> lOptions = new HashMap<String,Object>(); static {lOptions.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT,'false'); } private static EntityManagerFactory factory = Persistence .createEntityManagerFactory('flexerajpa',lOptions); private PersistenceProvider() { } /** * @return */ public static EntityManager createEntityManager() {return factory.createEntityManager(); } /** * @return */ public static Metamodel getMetamodel() {return factory.getMetamodel(); }}
我沒有這個可能的原因..如果有人有任何建議。謝謝
相關(guān)文章:
1. 隨機數(shù) - 有沒有用Python生成n個不重復(fù)隨機坐標(biāo)的算法?2. 學(xué)html時,點“運行實例”點“提交”,右邊的白框框沒任何反應(yīng)。3. python 字符串匹配問題4. javascript - vue 父子組件傳遞數(shù)據(jù)5. javascript - vue-router怎么不能實現(xiàn)跳轉(zhuǎn)呢6. docker不顯示端口映射呢?7. javascript - 怎么實現(xiàn)讓 div 里面的 img 元素 中心居中, 如下示例圖8. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下9. javascript - 微信小程序 如何實現(xiàn)這種左滑動出現(xiàn)刪除的辦法?有相關(guān)api嗎?10. javascript - 自執(zhí)行函數(shù)是當(dāng)加載到這個js就執(zhí)行函數(shù)了嗎
