我正在尝试使用 JPA 和 Wildfly 14 作为网络服务器连接到我的 PostgreSQL 数据库。我跟着几个教程,但我总是得到:
找不到名为“test”的持久性单元
我做了什么:
下载 postgresql-42.2.5.jar 并将其复制到同一目录中的“wildfly-14.0.1.Final\modules\system\layers\base\org\postgres\main\”module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.postgresql">
<resources>
<resource-root path="postgresql-42.2.5.jar"/>
<!-- Make sure this matches the name of the JAR you are installing -->
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
然后修改了standallone-full.xml
<datasource jta="true" jndi-name="java:jboss/datasources/test" pool-name="test" enabled="true" use-ccm="true">
<connection-url>jdbc:postgresql://localhost:5432/test</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>8a6rbd7a5c3a3fsavf4rq</password>
</security>
和
<driver name="postgres" module="org.postgres">
<driver-class>org.postgresql.Driver</driver-class>
</driver>
现在的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
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_1.xsd">
</persistence>
在那之后,当然,有点java:
@PersistenceContext(unitName = "test")
private EntityManager em;
所以,这就是我所做的 - 但尝试了更多......在部署中出现了错误:
WFLYWELD0037:将持久性单元注入 CDI 托管 bean 时出错。在部署中找不到名为“test”的持久性单元...
我不知道该怎么做。我是否忘记了一些 Maven 依赖项?
ABOUTYOU
相关分类