How do I search the database using a String in an Apirest?

Asked

Viewed 27 times

0

Hello, class!

I am studying developing Apirest with Spring Boot. But I am facing problem when I will make an appointment through String. Through id works normally, but when I add the search method by String an error message is displayed while climbing the application

"Error Starting Applicationcontext. To display the conditions report re-run your application with 'debug' enabled. 2021-07-11 09:53:28.132 ERROR 11188 --- [ restartedMain] o.s.boot.Springapplication : Application run failed

org.springframework.Beans.factory.Unsatisfieddependencyexception: Error Creating bean with name 'productResource': Unsatisfied dependency Expressed through field 'productRepository'... "

In the Repository class I have this method:

Produto findByCb(String cb);

and in the Resource class I call it so:

@GetMapping("/produto/{cb}")
@ApiOperation(value = "Lista um dado salvo no banco de dados apartir do código de barras")
public Produto listaProdutoUnicoCb(@PathVariable(value = "cb") String cb) {
    return produtoRepository.findByCb(cb);
}

I’m not understanding this problem, when I remove the String query method from the classes Repository and Resource works normally the application.

Remembering that the id search method follows the same implementation and works normally.

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.