【问题标题】:Cannot upload my Web Applicartion in Jboss7 EAP7 EAP无法在 Jboss EAP7 EAP 中上传我的 Web 应用程序
【发布时间】:2018-04-01 12:44:48
【问题描述】:

我必须测试这个 web 应用程序,但是当我尝试在 JBoss 7 EAP 上部署时,这是错误,也许我忘记了什么?

这是应用程序抛出的异常:

Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"WebAppGuestbooks.war\".INSTALL" => 
"org.jboss.msc.service.StartException in service jboss.deployment.unit.\"WebAppGuestbooks.war\".INSTALL: WFLYSRV0153: 
Failed to process phase INSTALL of deployment \"WebAppGuestbooks.war\" Caused by: 
org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0041: Component class it.matteo.nesea.ejb.GuestDao for 
component GuestDao has errors: 
 WFLYJPA0033: Can't find a persistence unit named null in deployment
 \"WebAppGuestbooks.war\""},"WFLYCTL0180: Services with missing/unavailable dependencies" => 
["jboss.deployment.unit.\"WebAppGuestbooks.war\".weld.weldClassIntrospector is missing 
[jboss.deployment.unit.\"WebAppGuestbooks.war\".beanmanager]","jboss.deployment.unit.\"WebAppGuestbooks.war\".batch.environment 
is missing [jboss.deployment.unit.\"WebAppGuestbooks.war\".beanmanager]"]}

这是我的 persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">

  <persistence-unit name="GuestbookPU" transaction-type="JTA">
  <class>it.matteo.nesea.dao.jpa</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="$objectdb/db/guests.odb"/>
      <property name="javax.persistence.jdbc.user" value="admin"/>
      <property name="javax.persistence.jdbc.password" value="admin"/>
    </properties>
  </persistence-unit>
</persistence>

这是 Ejb GuestDAO:

package it.matteo.nesea.ejb;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import it.matteo.nesea.dao.jpa.Guest;

@Stateless
public class GuestDao {
    // Injected database connection:
    @PersistenceContext private EntityManager em;

    // Stores a new guest:
    public void persist(Guest guest) {
        em.persist(guest);
    }

    // Retrieves all the guests:
    public List<Guest> getAllGuests() {
        TypedQuery<Guest> query = em.createQuery(
                "SELECT g FROM Guest g ORDER BY g.id", Guest.class);
        return query.getResultList();
    }
}

这是 Jpa POJO 班级嘉宾:

package it.matteo.nesea.dao.jpa;

import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Guest implements Serializable {
    private static final long serialVersionUID = 1L;

    // Persistent Fields:
    @Id 
    @GeneratedValue
    Long id;
    private String name;
    private Date signingDate;

    // Constructors:
    public Guest() {
    }

    public Guest(String name) {
        this.name = name;
        this.signingDate = new Date(System.currentTimeMillis());
    }

    // String Representation:
    @Override
    public String toString() {
        return name + " (signed on " + signingDate + ")";
    }
}

这是一个 Servlet GuestServlet:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import it.matteo.nesea.dao.jpa.Guest;
import it.matteo.nesea.ejb.GuestDao;

@WebServlet(name="GuestServlet", urlPatterns={"/guest"})
public class GuestServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

    // Injected DAO EJB:
    @EJB GuestDao guestDao;

    @Override
    protected void doGet(
        HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // Display the list of guests:
        request.setAttribute("guests", guestDao.getAllGuests());
        request.getRequestDispatcher("/guest.jsp").forward(request, response);
    }

    @Override
    protected void doPost(
        HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // Handle a new guest:
        String name = request.getParameter("name");
        if (name != null)
            guestDao.persist(new Guest(name));

        // Display the list of guests:
        doGet(request, response);
    }
}

这是一个 JSP 页面:

<%@page contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.util.*,it.matteo.nesea.dao.jpa.Guest"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>JPA Guest Book Web Application</title>
    </head>

    <body>
        <form method="POST" action="guest">
            Name: <input type="text" name="name" />
            <input type="submit" value="Add" />
        </form>

        <hr><ol> <%
            @SuppressWarnings("unchecked") 
            List<Guest> guests = (List<Guest>)request.getAttribute("guests");
            if (guests != null) {
                for (Guest guest : guests) { %>
                    <li> <%= guest %> </li> <%
                }
            } %>
        </ol></hr>
     </body>

This is the path of Project

【问题讨论】:

  • 不用说HELP :)
  • 你的persistence.xml的路径是什么?
  • @AndréLuizdeGusmão 我添加了一张图片,其中显示了 persistence.xml 的路径。感谢您的宝贵时间! :)
  • 试试这个,把你的persistence.xml放到src/META-INF。字体:https://stackoverflow.com/a/9998463/8611893
  • 耶啊啊啊啊啊!在 src/META-INF 运行!!但我不明白为什么..你能给我解释一下吗? @AndréLuizdeGusmão

标签: java jakarta-ee web-applications jboss jboss7.x


【解决方案1】:

您的 persistence.xml 文件位于错误的位置。 JPA 使用约定来查找您的persistence.xml,因此您已将文件放在正确的位置。

根据Oracle docs

META-INF目录包含persistence.xml的JAR文件或目录称为持久化单元的根。

  • 如果将持久单元打包为 EJB JAR 文件中的一组类,则应将 persistence.xml 放在 EJB JAR 的 META-INF 目录中。
  • 如果将持久性单元打包为 WAR 文件中的一组类,persistence.xml 应位于 WAR 文件的 WEB-INF/classes/META-INF 目录中。

如果persistence.xml 文件位于src/META-INF/ 中(如果您使用MAVEN,则路径为src/resources/META-INF),它将被打包到WEB-INF/classes/META-INF 文件夹中的war 中,以root 身份运行持久化单元。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 2019-10-17
    • 1970-01-01
    • 2018-09-08
    • 1970-01-01
    • 2015-07-12
    • 2020-03-09
    相关资源
    最近更新 更多