.
I’m unable to route requests to my Spring Boot application, even though I’ve tried the following:
- Added the regex
/app/**
to the Rest Controller and**/api
to the Method, as suggested in this Stack Overflow question. - Added
<packaging>jar</packaging>
to my pom.xml, as suggested in this Stack Overflow question. - Visited the correct endpoint,
localhost:8080/api
(port is not in use), as suggested in this Stack Overflow question. - Verified that the issue isn’t related to the mapping, as suggested in this Stack Overflow question.
The pom.xml
and RestController
class are provided below for reference.
- My
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>myrest</groupId>
<artifactId>remoteapi</artifactId>
<version>0.0.1</version>
<name>remoteapi</name>
<description>Rest Mobile Dev ICSD Api</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
- My
RestController
class
package Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MainController {
@RequestMapping(value="/api")
public String test()
{
return "Hello World";
}
}
I’m unable to route requests to my Spring Boot application. I’m accessing it from localhost:8080/api
and the MainController
class is located within the Controller
package.
I have tried the following solutions suggested on Stack Overflow, but none of them worked:
-
RequestMapping leads to 404 Error: Added the regex
/app/**
to the Rest Controller and**/api
to the Method. -
Spring @RequestMapping, 404 error: Added
<packaging>jar</packaging>
to my pom.xml. -
Request Mapping returning error 404: Visited the correct endpoint,
localhost:8080/api
(port is not in use). - Spring RequestMapping 404 error: Verified that the issue isn’t related to the mapping.
I have not encountered this issue before, as I have successfully run the same method with the same mapping on an older project.