gpt4 book ai didi

jpa - 资源的 JNDI 查找失败

转载 作者:行者123 更新时间:2023-12-05 07:32:25 25 4
gpt4 key购买 nike

我想编写一些简单的 JPA 测试。我的项目结构是

├── pom.xml
└── src
└── main
├── java
│   └── guest
│   ├── GuestDao.java
│   ├── Guest.java
│   ├── GuestRest.java
│   └── Rest.java
└── resources
└── META-INF
└── persistence.xml

persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
version="2.2">
<persistence-unit name="guestDB" transaction-type="JTA">
<jta-data-source>jdbc/guestDB</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
<property name="eclipselink.logging.level" value="FINE" />
</properties>

</persistence-unit>
</persistence>

但是,如果我在 glassfish 5 上部署,使用 asadmin deploy target/joe.war,我会得到

remote failure: Error occurred during deployment: 
Exception while deploying the app [joe] :
JNDI lookup failed for the resource: Name: [guestDB], Lookup: [jdbc/guestDB], Type: [javax.sql.DataSource].
Please see server.log for more details.
Command deploy failed.

服务器日志告诉我:

...
Caused by: javax.naming.NameNotFoundException: guestDB not found
...

但我认为,因为

<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />

persistence.xml 中,我不必创建数据库,也不必创建任何连接池。

但是,如果我创建一个 JDBC 资源,如下图所示

enter image description here

我收到 connection refused 错误

remote failure: Error occurred during deployment: Exception while preparing the app : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException: Fehler beim Herstellen der Verbindung zu Server localhost auf Port 1.527 mit Meldung Verbindungsaufbau abgelehnt (Connection refused).
Error Code: 0. Please see server.log for more details.

好吧,您可能会说,“使用像 Netbeans 这样的 IDE”,但我正在努力学习基础知识,所以现在这不是一个选择。

最佳答案

关于jpa - 资源的 JNDI 查找失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51254176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com