1
Complete error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'applicationStart': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract void br.com.backSpringBoot.awesome.repository.LoginRepository.delete(java.lang.Long)! No property delete found for type Login!
I am creating the HTTP methods for my Login class, and I came across this error, and I can’t figure out how to fix it!!! Anyone understands this error ?
Login.java:
@Entity
public class Login extends AbstractEntity {
private String empresa;
private String usuario;
private String senha;
public String getEmpresa() {
return empresa;
}
public void setEmpresa(String empresa) {
this.empresa = empresa;
}
public String getUsuario() {
return usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
Endpointlogin.java:
@RestController
@RequestMapping("login")
public class EndpointLogin {
private final LoginRepository loginDAO;
@Autowired
public EndpointLogin(LoginRepository loginDAO) {
this.loginDAO = loginDAO;
}
@GetMapping
public ResponseEntity<?> listAllLogin() {
// System.out.println("DATA AQUI"+dateUtil.formatLocalDateTimeToDatabaseStyle(LocalDateTime.now()));
return new ResponseEntity<>(loginDAO.findAll(), HttpStatus.OK);
}
@GetMapping(path = "/{id}")
public ResponseEntity<?> getLoginById(@PathVariable("id") Long id) {
Login login = loginDAO.findOne(id);
if (login == null) {
return new ResponseEntity<>(new CustomErrorType("Login não encontrado"), HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(login, HttpStatus.OK);
}
}
@PostMapping
public ResponseEntity<?> save(@RequestBody Login login) {
return new ResponseEntity<>(loginDAO.save(login), HttpStatus.OK);
}
@DeleteMapping(path ="/{id}")
public ResponseEntity<?> delete(@PathVariable Long id) {
loginDAO.delete(id);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping
public ResponseEntity<?> update(@RequestBody Login login) {
loginDAO.save(login);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Loginrepository.java:
public interface LoginRepository extends CrudRepository<Login, Long> {
List<Login> findByEmpresa(String empresa);
List<Login> findByUsuario(String usuario);
List<Login> findBySenha(String senha);
public Login findOne(Long id);
public void delete(Long id);
}
Abstractentity.java:
@MappedSuperclass
public class AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Override
public int hashCode() {
int hash = 3;
hash = 59 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final AbstractEntity other = (AbstractEntity) obj;
if (!Objects.equals(this.id, other.id)) {
return false;
}
return true;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
See if this case helps you: https://answall.com/questions/333829/erro-ao-executar-applies%C3%A7%C3%A3o-unsatisfieddependencyexception-error-Creating-bean
– Victor Carnaval
I changed the class name but did not solve the error :/
– Verônica Emschermann
You even annotated the Loginrepository interface with @Repository ?
– Diego Aguiar
@Diegoaguide is I had forgotten it! But now I see another mistake.... "Caused by: java.lang.Classnotfoundexception: id"
– Verônica Emschermann