确定。我想我已经浏览了互联网上所有可能的教程,仍然无法理解为什么我会收到此错误。所以我在这里使用NetBeans并且不使用Maven:
库
hibernate-validator-4.2.0.Final.jar
slf4j-api-1.6.1.jar
spring libraries (netbeans default)
hibernate libraries (netbeans default)
spring security libraries (3.0.7)
spring-config.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:annotation-driven />
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<context:annotation-config />
<bean id="menuDao" class="lt.database.dao.MenuDao" />
<bean id="userDao" class="lt.database.dao.UserDao" />
<tx:annotation-driven />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- Scans within the base package of the application for @Components to configure as beans -->
<!-- @Controller, @Service, @Configuration, etc. -->
<context:component-scan base-package="lt.controller" />
<context:component-scan base-package="lt.database.service" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- Load Hibernate related configuration -->
<import resource="hibernate-config.xml" />
</beans>
Controller
:
package lt.controller;
import javax.validation.Valid;
import lt.database.dao.MenuDao;
import lt.database.dao.UserDao;
import lt.database.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@Autowired
private UserDao userDao;
@Autowired
private MenuDao menuDao;
@Transactional
@RequestMapping(value = "/registracija/new", method = RequestMethod.POST)
public String registracijaNew(@ModelAttribute("user") @Valid User user, BindingResult result) {
userDao.saveUser(user);
return "redirect:/registracija";
}
}
Entity
:
package lt.database.model;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
/**
*
* @author Minutis
*/
@Entity
@Table(name = "user")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotEmpty(message = "Vartotojo vardas privalomas.")
@Size(min = 1, max = 50, message = "Vartotojo vardas turi būti tarp 1 ir 50 simbolių.")
@Column(name = "username")
private String username;
@Basic(optional = false)
@NotEmpty(message = "Slaptažodis yra privalomas.")
@Size(min = 1, max = 64, message = "Slaptažodis turi būti tarp 1 ir 64 simbolių.")
@Column(name = "password")
private String password;
@Email(message = "Netinkamai įvestas el. paštas.")
@Basic(optional = false)
@NotEmpty(message = "El. paštas yra privalomas.")
@Size(min = 1, max = 100, message = "El. paštas turi būti tarp 1 ir 100 simbolių.")
@Column(name = "email")
private String email;
@Basic(optional = false)
@NotNull
@Column(name = "user_type")
private byte userType;
@Size(max = 100, message = "Vardas neturi viršyti 100 simbolių.")
@Column(name = "first_name")
private String firstName;
@Size(max = 100, message = "Pavardė neturi viršyti 100 simbolių.")
@Column(name = "last_name")
private String lastName;
@Size(max = 100, message = "Adresas neturi viršyti 100 simbolių.")
@Column(name = "address")
private String address;
@Size(max = 100, message = "Telefonas neturi viršyti 100 simbolių.")
@Column(name = "phone")
private String phone;
@Size(max = 100, message = "Pašto kodas neturi viršyti 100 simbolių.")
@Column(name = "postcode")
private String postcode;
public User() {
}
public User(Integer id) {
this.id = id;
}
public User(Integer id, String username, String password, String email, byte userType) {
this.id = id;
this.username = username;
this.password = password;
this.email = email;
this.userType = userType;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes("UTF-8"));
byte[] digest = md.digest();
StringBuffer hashPassword = new StringBuffer();
for (int i = 0; i < digest.length; i++) {
hashPassword.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1));
}
this.password = hashPassword.toString();
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public byte getUserType() {
return userType;
}
public void setUserType(byte userType) {
this.userType = userType;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof User)) {
return false;
}
User other = (User) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "lt.database.model.User[ id=" + id + " ]";
}
}
ERROR:
INFO: test was successfully deployed in 17,875 milliseconds.
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_ where this_.name=?
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_ where this_.name=?
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_ where this_.name=?
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_
INFO: Hibernate: select this_.id as id28_0_, this_.link as link28_0_, this_.name as name28_0_ from aukcionas.menu this_
WARNING: StandardWrapperValve[spring]: PWC1406: Servlet.service() for servlet spring threw exception
java.lang.AbstractMethodError
at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Unknown Source)
at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:62)
at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:94)
at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:757)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:324)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:273)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:256)
at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:210)
at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:74)
at org.springframework.validation.DataBinder.validate(DataBinder.java:692)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:797)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:349)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:169)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:421)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:409)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
将空表单提交到控制器中的url时出现此错误。请帮忙,我会放松心情......
答案 0 :(得分:0)
我猜想hibernate验证器正在尝试使用JPA2方法,而构建路径上只有JPA 1。
答案 1 :(得分:0)
我将Hibernate从3.2.5更新到3.6.9,将Spring从3.0.2更新到3.1.0,问题解决了。 NOT 是否需要添加其中任何一项:
hibernate-validator-4.2.0.Final.jar
validation-api-1.0.0.GA.jar
答案 2 :(得分:0)
我有相同的错误消息,但不是相同的解决方案...... 因此对于那些使用Netbeans和Glassfish的人来说,这是给你的:
在Netbeans中运行你的项目并且它应该可以工作(如果它仍在运行则重新启动它并确保,如果你安装了多个glassfish服务器,你使用的是正确的)
我希望它有所帮助...