java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager
该程序是使用 JSP 和 Servlet 编写的。对于数据库操作,使用 Hibernate。当我尝试将数据保存到数据库中时,我的程序抛出异常。
我在 Whosebug 上找到了一些答案,但它们对我没有帮助。
我使用 IntelliJ IDEA 和 Apache Tomcat。
你能告诉我这里的问题是什么吗?
注册class:
@WebServlet(name = "Registration")
public class 注册扩展 HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = request.getReader().lines().collect(Collectors.joining());
System.out.println(str);
UserRegData userRegData = new ObjectMapper().readValue(str, UserRegData.class);
long tmpId = new Random().nextLong();
if (tmpId < 0) {
tmpId *= -1;
}
userRegData.setId(new Long(tmpId));
System.out.println("\n>>>>>> User registration Data :");
System.out.println(userRegData.toString());
//set user data into the object for inserting into table in Database
User user = new User();
user.setEmail(userRegData.getEmail());
user.setCity(userRegData.getCity());
user.setCountry(userRegData.getCountry());
user.setDateOfBirth(userRegData.getDateOfBirth());
user.setId(userRegData.getId());
user.setPhoneNumber(userRegData.getPhoneNumber());
user.setSex(user.getSex());
//set user login and password for inserting into table in Database
try {
UserAuthData userAuthData = new UserAuthData(userRegData.getId(), Hashing.hashString(userRegData.getLogin()),
Hashing.hashString(userRegData.getPassword()));
System.out.println("users login: " + userAuthData.getLogin());
System.out.println("users pass: " + userAuthData.getPassword());
boolean allusersTable = ManagingData.insIntoTable(user, user.getId());
boolean users_login_dataTable = ManagingData.insIntoTable(userAuthData, userAuthData.getId());
if (allusersTable == true && users_login_dataTable == true) {
System.out.println("user has been registered!");
}
}catch (NoSuchAlgorithmException e){
System.out.println("No such Algorithm!!!!!!!!");
e.printStackTrace();
}
response.setStatus(201);
response.sendRedirect("/page_of_user");
System.out.println("response has been sent!");
}
注释class:
@Entity
@Table(name = "allusers")
public class User {
@Id
private long id;
@Column(name = "email")
private String email;
@Column(name = "phone_number")
private long phoneNumber;
@Column(name = "country")
private String country;
@Column(name = "city")
private String city;
@Column(name = "date_of_birth")
private Date dateOfBirth;
@Column(name = "sex")
private String sex;
public User() {
}
public User(String email, long phoneNumber, String country, String city, Date dateOfBirth, String sex) {
this.email = email;
this.phoneNumber = phoneNumber;
this.country = country;
this.city = city;
this.dateOfBirth = dateOfBirth;
this.sex = sex;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
抛出异常的方法是:
public void setId(Long id) {
Configuration configuration = new Configuration().configure().addAnnotatedClass(User.class);
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
while(true) {
if (session.get(User.class, id) == null) {
this.id = id;
break;
}else{
id = new Random().nextLong();
if(id<0){
id *= (-1);
}
}
}
}
抛出的异常是:
14-Aug-2018 02:53:10.544 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service()
for servlet [Registration] in context with path [] threw exception
[Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException:
org.hibernate.annotations.common.reflection.ReflectionManager at
java.net.URLClassLoader.findClass(URLClassLoader.java:381) at
java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
Users.UserRegData.setId(UserRegData.java:102) at
Actions.Registration.doPost(Registration.java:35) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:407)
at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376)
at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Hibernate 的 Maven 依赖项是:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.4.Final</version>
</dependency>
该程序是使用 JSP 和 Servlet 编写的。对于数据库操作,使用 Hibernate。当我尝试将数据保存到数据库中时,我的程序抛出异常。 我在 Whosebug 上找到了一些答案,但它们对我没有帮助。 我使用 IntelliJ IDEA 和 Apache Tomcat。 你能告诉我这里的问题是什么吗?
注册class:
@WebServlet(name = "Registration")
public class 注册扩展 HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String str = request.getReader().lines().collect(Collectors.joining());
System.out.println(str);
UserRegData userRegData = new ObjectMapper().readValue(str, UserRegData.class);
long tmpId = new Random().nextLong();
if (tmpId < 0) {
tmpId *= -1;
}
userRegData.setId(new Long(tmpId));
System.out.println("\n>>>>>> User registration Data :");
System.out.println(userRegData.toString());
//set user data into the object for inserting into table in Database
User user = new User();
user.setEmail(userRegData.getEmail());
user.setCity(userRegData.getCity());
user.setCountry(userRegData.getCountry());
user.setDateOfBirth(userRegData.getDateOfBirth());
user.setId(userRegData.getId());
user.setPhoneNumber(userRegData.getPhoneNumber());
user.setSex(user.getSex());
//set user login and password for inserting into table in Database
try {
UserAuthData userAuthData = new UserAuthData(userRegData.getId(), Hashing.hashString(userRegData.getLogin()),
Hashing.hashString(userRegData.getPassword()));
System.out.println("users login: " + userAuthData.getLogin());
System.out.println("users pass: " + userAuthData.getPassword());
boolean allusersTable = ManagingData.insIntoTable(user, user.getId());
boolean users_login_dataTable = ManagingData.insIntoTable(userAuthData, userAuthData.getId());
if (allusersTable == true && users_login_dataTable == true) {
System.out.println("user has been registered!");
}
}catch (NoSuchAlgorithmException e){
System.out.println("No such Algorithm!!!!!!!!");
e.printStackTrace();
}
response.setStatus(201);
response.sendRedirect("/page_of_user");
System.out.println("response has been sent!");
}
注释class:
@Entity
@Table(name = "allusers")
public class User {
@Id
private long id;
@Column(name = "email")
private String email;
@Column(name = "phone_number")
private long phoneNumber;
@Column(name = "country")
private String country;
@Column(name = "city")
private String city;
@Column(name = "date_of_birth")
private Date dateOfBirth;
@Column(name = "sex")
private String sex;
public User() {
}
public User(String email, long phoneNumber, String country, String city, Date dateOfBirth, String sex) {
this.email = email;
this.phoneNumber = phoneNumber;
this.country = country;
this.city = city;
this.dateOfBirth = dateOfBirth;
this.sex = sex;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(long phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Date getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
抛出异常的方法是:
public void setId(Long id) {
Configuration configuration = new Configuration().configure().addAnnotatedClass(User.class);
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
while(true) {
if (session.get(User.class, id) == null) {
this.id = id;
break;
}else{
id = new Random().nextLong();
if(id<0){
id *= (-1);
}
}
}
}
抛出的异常是:
14-Aug-2018 02:53:10.544 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [Registration] in context with path [] threw exception [Servlet execution threw an exception] with root cause java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at Users.UserRegData.setId(UserRegData.java:102) at Actions.Registration.doPost(Registration.java:35) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:407) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
Hibernate 的 Maven 依赖项是:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.6.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.4.Final</version>
</dependency>