javax.naming.NameNotFoundException:在此Context中未绑定Name。无法找到 [英] javax.naming.NameNotFoundException: Name is not bound in this Context. Unable to find

查看:534
本文介绍了javax.naming.NameNotFoundException:在此Context中未绑定Name。无法找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出我的网络应用程序抛出的原因

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.

我有:


  1. 通过右键单击并选择新持久性从netbeans创建新的持久性,我不关心我给出的实际值,但我只需要在正确的目录中创建persistence.xml文件。

  2. 编辑我的context.xml,如下所示匹配一个来自工作姐妹项目

  3. 编辑我的web.xml以包含资源DataSource,如下所示

  4. 编辑我的persistence.xml,如下所示再次匹配相同的在姐妹项目中工作的值。

  5. 添加了我的lib文件夹中的另一个项目中存在的所有库,并从NetBeans中添加它们以正确地置于战争之中。

  1. create from netbeans a new persistence by right clicking and selecting "new persistence", I don't care about the actual values I give but I just need for the persistence.xml file to be created in the right directory.
  2. edited my context.xml as below matching the one from working sister project
  3. edited my web.xml to contain a resource DataSource as shown below
  4. edited my persistence.xml as below again matching the same values which on the sister project work.
  5. added all libraries present in the other project inside the lib folder of mine and adding them also from NetBeans to be correctly put inside war.



context.xml



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



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



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>

现在我的syster项目有些如何设法在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

推荐答案

好的发现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:在此Context中未绑定Name。无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆