Can’t access API endpoint

So I've started learning Spring recently by following a small course where we created a market api, when we started we created a simple hello world endpoint to test things out. Recently we just created an endpoint for accessing a list of products, but it seems all requests return a 404 error, since this error seems to be related with the controller I don't think posting all my code is needed.

This is my controller, I've only added the mapping for the first two methods (since I'm trying to fix this error still)

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class ProductController {
    private ProductService productService;

    public List<Product> getAll() {
        return productService.getAll();

    public Optional<Product> getProduct(@PathVariable("productId") int productId) {
        return productService.getProduct(productId);

    public Optional<List<Product>> getByCategory(int categoryId) {
        return productService.getByCategory(categoryId);

    public Product save(Product product) {

    public Boolean delete(int productId) {
        return productService.delete(productId);

I also had to deal with a bean not being found which translated domain objects into dto's (and vise versa) by using MapStruct with the following error:

I made sure to annotate my interface with @Mapper(componentModel="spring")



Field mapper in required a bean of type '' that could not be found.

The injection point has the following annotations:
        - @org.springframework.beans.factory.annotation.Autowired(required=true)


Consider defining a bean of type '' in your configuration.

I managed to fix this with this (source from another student's comment)

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = { "", })
public class PlatziMarketApplication {
    public static void main(String[] args) {, args);

But I'm not sure if this could be causing some interference with the controller class.

Are you accessing the correct endpoint?

This is my

And this is the active dev profile (


#  Database, values are altered

So the endpoint for accesing all product in my controller should be: localhost:8080/platzi-market/api/products/all which is returning a 404

I also checked if maybe I am using https so I made sure to use http:// in Postman, which also returned a 404

I double-checked the output in the terminal just to make sure the right port and context-path are being used:

2021-02-23 17:20:07.583  INFO 51334 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/platzi-market/api'
2021-02-23 17:20:07.594  INFO 51334 --- [           main]  : Started PlatziMarketApplication in 3.881 seconds (JVM running for 4.296)

If you would like to check the rest of the code here's a link to the repo:, hope this makes since since I'm going crazy with error XD

Read more here:

Content Attribution

This content was originally published by Jeremy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: