Skip to content
Advertisement

Java Spring Boot: Dependency Injection error: Change 1st parameter of abstract method to Optional

I am trying to use dependency injection in Java Spring Boot. Receiving Error below in controller in this line. productService.updateProduct(product);

Error: Change 1st parameter of abstract method from Product to Optional

How can this be resolved?

JavaScript

Interface:

JavaScript

Service:

JavaScript

Controller:

JavaScript

Advertisement

Answer

And check whether your Repository class return Optional<Product>. because findbyId return type of optional. Then your have to use like below.

JavaScript

And Better to add @Autowire @Controller annotation no need constructor.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement