Reputation: 11
There is a User Bean as the model. The controller class is UserController and UserRepository is the repository class.
This is the model class
@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;
}
}
This is the Controller class:
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";
}
}
Repository Do I need to implement this interface?
public interface UserRepository extends JpaRepository<User, Long> {
}
The following exception is thrown:
Unsatisfied dependency expressed through field 'userRepos'; nested exception is org.springframework.beans.factory.BeanCreationException:
Upvotes: 1
Views: 1692
Reputation: 166
Welcome to the Stack Overflow.
Please annotate UserRepository class by @Repository annotation.
Please look here: UnsatisfiedDependencyException: Error creating bean with name
Upvotes: 1