有一个用户Bean作为模型。控制器类为UserController,而UserRepository为存储库类。
这是模型类
@Entity
public class User {
@Id()
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
private String first_name;
private String last_name;
private String email;
private String password;
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
这是Controller类:
package com.prashant.flightreservation.controllers;
@Controller
public class UserController {
@Autowired
private UserRepository userRepos;
@RequestMapping("/showReg")
public String showRegistrationPage() {
return "registerUser";
}
@RequestMapping(value = "registerUser", method = RequestMethod.POST)
public String register(@ModelAttribute("user") User user) {
userRepos.save(user);
return "login";
}
}
存储库 我需要实现此接口吗?
public interface UserRepository extends JpaRepository<User, Long> {
}
引发以下异常:
通过字段“ userRepos”表示的不满意的依赖关系;嵌套的 异常是org.springframework.beans.factory.BeanCreationException:
答案 0 :(得分:0)
欢迎使用堆栈溢出。
请通过@Repository注释对UserRepository类进行注释。
请在这里查看:UnsatisfiedDependencyException: Error creating bean with name