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. javascript - JS設(shè)置Video視頻對象的currentTime時出現(xiàn)了問題,IE,Edge,火狐,都可以設(shè)置,反而chrom卻...2. java固定鍵值轉(zhuǎn)換,使用枚舉實現(xiàn)字典?3. 如何為每個應(yīng)用程序配置tomcat 6的logs / catalina.out。(為sys.out,sys.err配置Web應(yīng)用程序特定的日志文件)4. css - ionic中的柵格布局如何讓文字內(nèi)容多少不同的每一列中的內(nèi)容都能垂直居中?5. php自學(xué)從哪里開始?6. phpstady在win10上運行7. java - 我設(shè)置了cookie的max age,但是cookie依然在關(guān)閉游覽器后消失了8. python - flask學(xué)習(xí),user_syy添加報role is invalid keyword for User.9. 這是什么情況???10. javascript - 用jsonp抓取qq音樂總是說回調(diào)函數(shù)沒有定義
