我使用hibernate-search-5.3.0.Beta2-dist,Eclipsse Indigo,Apache Tomcat v0.47
persitence.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="Hibernate Tutozone" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>info.tutozone.food.Food</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/tutozonedb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
</persistence-unit>
</persistence>
Food.java:
package info.tutozone.food;
import java.io.Serializable;
import java.lang.String;
import javax.persistence.*;
/**
* Entity implementation class for Entity: Food
*
*/
@Entity
public class Food implements Serializable {
@Id
private int id;
private String name;
private float price;
private int quantity;
private static final long serialVersionUID = 1L;
public Food() {
super();
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public float getPrice() {
return this.price;
}
public void setPrice(float price) {
this.price = price;
}
public int getQuantity() {
return this.quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
@Override
public String toString() {
return "Food [id=" + id + ", name=" + name + ", price=" + price
+ ", quantity=" + quantity + "]";
}
}
TestServlet.java:
package info.tutozone.food;
import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class TestServlet
*/
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
// TODO Auto-generated constructor stub
}
/*
* Tuto Hibernate avec Eclipse
* author : Zied
* www.tutozone.info
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
EntityManager manager=Persistence.createEntityManagerFactory("Hibernate Tutozone").createEntityManager();
manager.getTransaction().begin();
manager.getTransaction().commit();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
// TODO Auto-generated method stub
EntityManager manager = Persistence.createEntityManagerFactory(
"Hibernate Tutozone").createEntityManager();
manager.getTransaction().begin();
// add a new row in table
Food food = new Food();
food.setId(1);
food.setName("Cacke");
food.setQuantity(new Integer(20));
food.setPrice(new Float(2500));
manager.persist(food);
manager.getTransaction().commit();
manager.close();
}}
当我在tomcat上部署此项目时,我在http://localhost:8080/HibernateTutoZone/TestServlet
上出现此错误输入异常报告 消息Servlet执行引发异常描述服务器 遇到内部错误,导致无法完成此操作 请求。异常javax.servlet.ServletException:Servlet执行 抛出一个例外 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) 根本原因java.lang.NoClassDefFoundError:org / jboss / jandex / IndexView org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
我在Eclipsse Indigo的控制台上出现此错误:
SEVERE:servlet [info.tutozone.food.TestServlet]的Servlet.service()在路径[/ HibernateTutoZone]的上下文中引发了异常[Servlet执行抛出异常]的根本原因 java.lang.ClassNotFoundException:org.jboss.jandex.IndexView
如果我在项目运行中运行as-&gt;运行configuation-&gt; Apache Tomcat-&gt; classpath-&gt; user Entries-&gt;我没有错误添加外部jar - &gt; jandex-1.1.0.final.jar
但即使我没有错误,如果我这样做,TestServlet.java的main()也无法正常工作
然后我想了解问题是什么,我该如何解决?
答案 0 :(得分:0)
在这种情况下,您无法使用外部jar。 Tomcat本身在运行时负责决定它接受哪些罐作为应用程序的一部分,这意味着将它们以某种方式进入您的Web应用程序WEB-INF/lib
。
请停止使用Indigo,它已经快4岁了。