javax.naming.NameNotFoundException:名称未在此上下文中绑定.找不到 [英] javax.naming.NameNotFoundException: Name is not bound in this Context. Unable to find
问题描述
我试图找出为什么我的 Web 应用程序抛出一个
I'm trying to find out why my web application throws a
javax.naming.NameNotFoundException: Name [flexeraDS] is not bound in this Context. Unable to find [flexeraDS].
当我正在从中复制配置的姊妹程序悄悄运行时.
when a sister one from which I'm copying the configuration quietly runs.
我有:
- 通过右键单击并选择新的持久性"从 netbeans 创建一个新的持久性,我不关心我给出的实际值,但我只需要在正确的目录中创建 persistence.xml 文件.莉>
- 将我的 context.xml 编辑如下,与工作姊妹项目中的相匹配
- 编辑我的 web.xml 以包含如下所示的资源数据源
- 再次编辑我的 persistence.xml 如下,匹配与姐妹项目相同的值.
- 将其他项目中存在的所有库添加到我的 lib 文件夹中,并将它们也从 NetBeans 添加到战争中.
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>
持久性.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>
现在我的系统项目以某种方式设法在启动时在 apache-tomcat-7.0.40/bin/exampleDB 中创建其数据库文件夹,而我的没有创建它并抛出上述错误.
Now my syster project some-how manages to create its database folder inside apache-tomcat-7.0.40/bin/exampleDB on startup while mine doesn't create it and throws an error as above.
抛出错误的代码是我第一次连接数据库:
The code where the error is thrown is the first time I connect to the database:
EntityManager entityManager = PersistenceProvider.createEntityManager();
PersistenceProvider 类在哪里:
where the PersistenceProvider class is:
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();
}
}
我没有可能的原因..如果有人有任何建议.谢谢
I'm out of possible reasons for this.. if anyone has any suggestion. Thank you
推荐答案
Ok 发现 Tomcat 文件 server.xml 也必须配置,数据源才能工作.所以只需添加:
Ok found out the Tomcat file server.xml must be configured as well for the data source to work. So just add:
<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"
/>
这篇关于javax.naming.NameNotFoundException:名称未在此上下文中绑定.找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!