类javax.el.BeanELResolver无法访问Spring Boot,JSP中的类java.util.Collections $ UnmodifiableCollection的成员

时间:2016-12-24 10:51:05

标签: spring jsp spring-mvc spring-el

我的代码中存在此问题,我无法在jsp中提交注册表单。以下是介入注册操作的代码。

User.java

@Entity 
@Table(name = "user", catalog = "spring_abc", uniqueConstraints = {@UniqueConstraint(columnNames = "email"),
 @UniqueConstraint(columnNames = "username")})
 public class User implements java.io.Serializable {

public static final String ROLE_ADMIN = "admin";
public static final String ROLE_MEMBER = "member";


private static final long serialVersionUID = 7376961072110620611L;
private Integer id;
private Long commentCount;
private Date createAt;
private String description;
@Email(message = "Entrez le format de l'email correct")
private String email;

private long number;

private String password;

public void setDepartement(String departement) {
    this.departement = departement;
}

private long points;

private String role;

@Size(max = 60, message = "Pas plus de soixante caractères")
private String signature;

private Long topicCount;

@Size(max = 60, message = "Pas plus de soixante caractères")
private String twitter;

private Date updateAt;

@Pattern(regexp = "^(?!_)(?!.*?_$)[A-Za-z0-9|_]{3,9}", message = "Nom d'utilisateur, ne peut pas commencer ou se terminer par un trait de soulignement")
private String username;

private Set<Follow> followsForFollowerId = new HashSet<Follow>(0);
private Set<Notification> notifications = new HashSet<Notification>(0);
private Set<Topic> topics = new HashSet<Topic>(0);
private Set<Comment> comments = new HashSet<Comment>(0);
private Set<Focus> focuses = new HashSet<Focus>(0);
private Set<Collection> collections = new HashSet<Collection>(0);
private Set<Follow> followsForFollowingId = new HashSet<Follow>(0);
private Set<Comment> likeComments = new HashSet<Comment>();

方法注册服务Part。

@Transactional
public User signup(User user, String password1, Errors errors) {
    if (errors.hasErrors()) {
        return null;
    }
    String username = user.getUsername();
    String password = user.getPassword();
    String email = user.getEmail();

    if (userRepo.findOneByUsername(username) != null) {
        errors.rejectValue("username", "username", "Nom d'utilisateur déjà enregistré");
    } else if (userRepo.findOneByEmail(email) != null) {
        errors.rejectValue("email", "email", "E-mail est déjà enregistré");
    } else if (!password.equals(password1)) {
        errors.rejectValue("password", "password", "Les mots de passe ne se correspondent pas");
    }
    if (errors.hasErrors()) {
        return null;
    }

    user.setPassword(EncryptUtil.encryptUsernameAndPassword(username, password));

    user.setCreateAt(new Date());
    return userRepo.save(user);
}

Controller Account.java

@RequestMapping(value = "/signup", method = RequestMethod.POST)
public String singupAction(@Validated User user,
                           Errors erros,
                           String password1,
                           RedirectAttributes attributese,
                           HttpServletRequest request) {
    User signinUser = userServ.signup(user, password1, erros);

    if (erros.hasErrors()) {
        attributese.addFlashAttribute("user", user);
        attributese.addFlashAttribute("error", erros.getAllErrors());
        return "redirect:/account/signup";
    }


    request.getSession().setAttribute("user", signinUser);
    attributese.addFlashAttribute("msg", "Vous êtes inscrit avec succès");

    return "redirect:/";
} 

Signup.jsp,当我尝试验证信息时出现问题。

<form action="${x}/account/signup" data-toggle="validator" role="form" method="POST">
<input class="form-control" data-error="S'il vous plaît entrer une adresse email valide" placeholder="E-mail" type="email" id="email" name="email" value="${user.email}" />
 <input class="form-control" id="username" data-error="Entre 6 et 18 caractères" pattern="^[_A-z0-9]{6,18}$" placeholder="Votre username" type="text" name="username" value="${user.username}"   />
 <input class="form-control" data-minlength="6" type="password" name="password" id="password" placeholder="Mot de passe" data-error="Entre 6 et 18 caractères" />
 <input type="submit" class="btn btn-info btn-block" value="S'inscrire">

我得到的堆栈对我没有任何意义。它没有指出问题

org.apache.jasper.JasperException: javax.el.ELException: java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:501)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)

Caused by: javax.el.ELException: java.lang.IllegalAccessException: Class javax.el.BeanELResolver can not access a member of class java.util.Collections$UnmodifiableCollection with modifiers "public"
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:742)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:470)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)

1 个答案:

答案 0 :(得分:0)

您需要在getters中为每个setters添加entityfield

e.g。私人长号;

应在entity

中定义以下内容
public long getNumber(){ return this.number;}
public void setNumber(long number){ this.number = number; }
来自你的堆栈跟踪

很明显它正在尝试使用public getter方法访问字段,但是它无法找到它所引发的异常。