Spring JPA Error

I am getting a error like this ->
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shelfBookController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'userRepository' defined in com.ShelfSpace.ShelfSpace.repository.UserRepository defined in @EnableJpaRepositories declared on ShelfSpaceApplication: Not a managed type: class com.ShelfSpace.ShelfSpace.model.UserDto
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:787) ~[spring-beans-6.1.10.jar:6.1.10]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shelfBookController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'userRepository' defined in com.ShelfSpace.ShelfSpace.repository.UserRepository defined in @EnableJpaRepositories declared on ShelfSpaceApplication: Not a managed type: class com.ShelfSpace.ShelfSpace.model.UserDto
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:787) ~[spring-beans-6.1.10.jar:6.1.10]
When i am trying to
@GetMapping("/register")
public String registerPage(Model model) {
model.addAttribute("user", new UserDto());
return "registration"; // This corresponds to registration.html in templates folder
}

@PostMapping("/registrationPage")
public String registerUser(@ModelAttribute("user") UserDto dto) {
UserDetails details = User.builder().username(dto.getName()).
password(new BCryptPasswordEncoder()
.encode(dto.getPassword()))
.roles("ROLE_USER").build();

repository.saveUser(details);

return "success"; // This corresponds to success.html in templates folder (if you have one)
}
@GetMapping("/register")
public String registerPage(Model model) {
model.addAttribute("user", new UserDto());
return "registration"; // This corresponds to registration.html in templates folder
}

@PostMapping("/registrationPage")
public String registerUser(@ModelAttribute("user") UserDto dto) {
UserDetails details = User.builder().username(dto.getName()).
password(new BCryptPasswordEncoder()
.encode(dto.getPassword()))
.roles("ROLE_USER").build();

repository.saveUser(details);

return "success"; // This corresponds to success.html in templates folder (if you have one)
}
Can anyone help
12 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Peter Rader
Peter Rader6mo ago
Please show the code of the class com.ShelfSpace.ShelfSpace.repository.UserRepository.
Danix
DanixOP6mo ago
help i am stuck in it @Peter Rader
Peter Rader
Peter Rader6mo ago
ok
Danix
DanixOP6mo ago
this issue is cleared out but i am stuck into another one actually i am making a spring security registration page and login page as well but dont know what to do now ? https://sourceb.in/c0q3R1R0Lw here is my current code @Peter Rader are u there ?
Peter Rader
Peter Rader6mo ago
yea
Danix
DanixOP6mo ago
did u know what to do now bcz i am getting error like this
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shelfBookController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'userRepository' defined in com.ShelfSpace.ShelfSpace.repository.UserRepository defined in @EnableJpaRepositories declared on ShelfSpaceApplication: Could not create query for public abstract void com.ShelfSpace.ShelfSpace.repository.UserRepository.saveUser(org.springframework.security.core.userdetails.UserDetails); Reason: Failed to create query for method public abstract void com.ShelfSpace.ShelfSpace.repository.UserRepository.saveUser(org.springframework.security.core.userdetails.UserDetails); No property 'saveUser' found for type 'UserEntity'
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shelfBookController': Unsatisfied dependency expressed through field 'repository': Error creating bean with name 'userRepository' defined in com.ShelfSpace.ShelfSpace.repository.UserRepository defined in @EnableJpaRepositories declared on ShelfSpaceApplication: Could not create query for public abstract void com.ShelfSpace.ShelfSpace.repository.UserRepository.saveUser(org.springframework.security.core.userdetails.UserDetails); Reason: Failed to create query for method public abstract void com.ShelfSpace.ShelfSpace.repository.UserRepository.saveUser(org.springframework.security.core.userdetails.UserDetails); No property 'saveUser' found for type 'UserEntity'
Peter Rader
Peter Rader6mo ago
Hm, your code is well designed. Would you mind post your answer to the original question here? Would you agree to open up another question targeting your new question?
Danix
DanixOP6mo ago
i did it @Peter Rader
Peter Rader
Peter Rader6mo ago
Wunderful, I am sure there are ppl focusing your new problem. Could you tell the solution to your original question here? It can be broad, must not go into detail. Just the core idea to solve this original question. Please, kind regards!
Danix
DanixOP6mo ago
My last Problem was solved can u help me to solve my new problem ? @Peter Rader
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server