Encountering a 404 Page in Spring Boot Application's Backend

I’m developing a Spring Boot application that utilizes a JSP front-end alongside a Java back-end. After deploying my project on a Tomcat server, the front-end loads successfully; however, accessing the backend URL results in a 404 error. For instance, visiting http://localhost:8090/orders leads to this issue.

I have properly defined the @RequestMapping for my endpoints, and I’m using a workbench for database management. Here are my settings in application.properties:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/csse_ass
spring.datasource.username=root
spring.datasource.password=1234

spring.jpa.hibernate.ddl-auto=create
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

In my pom.xml, which has numerous dependencies, I’ve included the key one:


  mysql
  mysql-connector-java
  8.0.11

Here is the relevant code from my controller:

private OrderService orderService;

@RequestMapping("/orders")
public List retrieveOrders() {
    return orderService.getAllOrders();
}

And in the service layer:

@Autowired
private OrderRepository orderRepository;

public List getAllOrders() {
    List ordersList = new ArrayList<>();
    for (Order order : orderRepository.findAll()) {
        ordersList.add(order);
    }
    return ordersList;
}

The repository interface looks like this:

public interface OrderRepository extends CrudRepository {}

I have also created the Order.java class, which I believe is unrelated to this issue. There are no errors appearing in the terminal, apart from common Tomcat errors.

My Question: Why am I facing a 404 error as mentioned before? I would appreciate any help to identify and resolve this issue.

Have you had a chance to check whether the URL path mappings are being recognized by Spring Boot? Maybe an issue in server’s context path or deployment structure? Also, have you verified if there is some firewall or network setting blocking any part of the backend communication? :thinking: Curious on your server logs too!

Try adding @RestController above your controller class or replace @RequestMapping with @GetMapping. This tells spring boot to handle the request properly. another thing, make sure the server has restarted and the endpoint is active after deployment. sometimes it’s simple stuff like this. good luck!

It sounds like you may have a controller mapping issue. Ensure your controller is properly annotated and the context path in the application.properties matches the URL pattern you’re using. Double-check that you’re not inadvertently missing or misconfiguring a component scan or classpath element relevant to your controller. Also, verify that the OrderService is properly injected and initialized. Without explicit errors, these configuration elements can be subtle but crucial in successfully mapping routes to their respective controller endpoints.

Ever considered creating a super simple endpoint first to check if it’s some wiring issue inside retrieveOrders? Like a basic hello world return to verify routing works? It’s weird how 404 pops up without clues. Could there be a conflict in Tomcat settings causing some overlap or misdirection?

Do you have multiple controllers that might be colliding or same mapping names being reused accidantally? Also, sometimes paths are case-sensitive, so double-check for that lil detail too. make sure your order-related services are being called in a flow where other services can’t affect routing.