EJB,JPA persistence.xml问题Wildfly 8.2 intellij
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EJB,JPA persistence.xml问题Wildfly 8.2 intellij相关的知识,希望对你有一定的参考价值。
我正在使用intellij Idea创建一个带有JPA和Jboss 8.2的EJB:我正在构建一个jar文件作为输出,当我解压缩jar文件时,在meta-info文件夹中找不到persistance.xml,当我在那里运行服务器时它给出了我找不到一个例外单位名称。是否有解决方案和thanx很多。
这个persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="EJBUser" transaction-type="JTA">
<jta-data-source>java:/EJBUser</jta-data-source>
<class>entities.User</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
这是我的豆子
package ejb;
import bl.UserLocal;
import entities.User;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
* Created by mehdi on 04/02/2019.
*/
@Stateless(name = "UserImpLocalEJB")
public class UserImpLocalBean implements UserLocal{
@PersistenceContext(unitName = "EJBUser")
private EntityManager em;
public UserImpLocalBean() {
}
@Override
public User addUser(User user) {
em.persist(user);
return user;
}
}
最后这是例外;
20:10:40,122 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "EJBUser_ejb exploded.jar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_191]
at java.lang.Thread.run(Thread.java:748) [rt.jar:1.8.0_191]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class ejb.UserImpLocalBean for component UserImpLocalEJB has errors:
JBAS011440: Can't find a persistence unit named EJBUser in deployment "EJBUser_ejb exploded.jar"
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:159)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:152)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:145)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
... 5 more
20:10:40,133 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "EJBUser_ejb exploded.jar")]) - failure description: {
"JBAS014671: Failed services" => {"jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "EJBUser_ejb exploded.jar"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class ejb.UserImpLocalBean for component UserImpLocalEJB has errors:
JBAS011440: Can't find a persistence unit named EJBUser in deployment "EJBUser_ejb exploded.jar""},
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit."EJBUser_ejb exploded.jar".weld.weldClassIntrospector is missing [jboss.deployment.unit."EJBUser_ejb exploded.jar".beanmanager]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.Validator is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InAppClientContainer is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InstanceName is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.ValidatorFactory is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]"
]
}
20:10:40,137 ERROR [org.jboss.as.server] (management-handler-thread - 2) JBAS015870: Deploy of deployment "EJBUser_ejb exploded.jar" was rolled back with the following failure message:
{
"JBAS014671: Failed services" => {"jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "EJBUser_ejb exploded.jar"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class ejb.UserImpLocalBean for component UserImpLocalEJB has errors:
JBAS011440: Can't find a persistence unit named EJBUser in deployment "EJBUser_ejb exploded.jar""},
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit."EJBUser_ejb exploded.jar".weld.weldClassIntrospector is missing [jboss.deployment.unit."EJBUser_ejb exploded.jar".beanmanager]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.Validator is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InAppClientContainer is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InstanceName is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]",
"jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.ValidatorFactory is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]"
]
}
20:10:40,150 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) JBAS015877: Stopped deployment EJBUser_ejb exploded.jar (runtime-name: EJBUser_ejb exploded.jar) in 13ms
20:10:40,152 INFO [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.deployment.unit."EJBUser_ejb exploded.jar".beanmanager (missing) dependents: [service jboss.deployment.unit."EJBUser_ejb exploded.jar".weld.weldClassIntrospector]
service jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB (missing) dependents: [service jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InstanceName, service jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.Validator, service jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InAppClientContainer, service jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.ValidatorFactory]
JBAS014777: Services which failed to start: service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL
[2019-02-04 08:10:40,229] Artifact EJBUser:ejb exploded: Error during artifact deployment. See server log for details.
[2019-02-04 08:10:40,250] Artifact EJBUser:ejb exploded: java.lang.Exception: {"JBAS014671: Failed services" => {"jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit."EJBUser_ejb exploded.jar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "EJBUser_ejb exploded.jar"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011047: Component class ejb.UserImpLocalBean for component UserImpLocalEJB has errors:
JBAS011440: Can't find a persistence unit named EJBUser in deployment "EJBUser_ejb exploded.jar""},"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.deployment.unit."EJBUser_ejb exploded.jar".weld.weldClassIntrospector is missing [jboss.deployment.unit."EJBUser_ejb exploded.jar".beanmanager]","jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.Validator is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]","jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InAppClientContainer is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]","jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.InstanceName is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]","jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB.ValidatorFactory is missing [jboss.naming.context.java.comp."EJBUser_ejb exploded"."EJBUser_ejb exploded".UserImpLocalEJB]"]}
答案
正如您已经从错误日志中发现的那样,Wildfly抱怨它无法在EJB中找到持久性上下文,因为JAR中缺少persistence.xml文件。它必须保存在META-INF目录的根级别。
如果您希望IntelliJ自动将其打包到JAR中的META-INF目录中,META-INF/persistence.xml
应该位于IntelliJ的源根目录下。
另一答案
我通过从项目结构the image describe how to add it 添加JPA描述符来解决它
以上是关于EJB,JPA persistence.xml问题Wildfly 8.2 intellij的主要内容,如果未能解决你的问题,请参考以下文章
如何为 JPA 和 Hibernate 创建一个 persistence.xml 文件?