Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP status 404 - Not Found while creating springBoot Application

This a springboot Application. It run perfectly but did not get output (it shows me HTTP Status 404 error in browser)

pom.xml

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.exaample.demo</groupId>
  <artifactId>SpringBootMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Maven spring boot project</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <java.version>1.8</java.version>   
    </properties>
</project>

Springboot start Class Main Method

package com.example.demo;

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

@SpringBootApplication
public class WebMainMethod {

    public static void main(String[] args) {
        SpringApplication.run(WebMainMethod.class, args);

    }

}

controller is loading after main class

**Rest Controller**


package com.example.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @RequestMapping("/hello")
    public String sayHi() {
        return "Hi";
    }
}

Url : http://localhost:8080/hello output

Browser Output

this console log os springboot Application

like image 784
Ankush Jane Avatar asked Apr 11 '26 11:04

Ankush Jane


1 Answers

You can try this. Using application.properties /yml

The most straightforward way of changing the context path is to set the property in the application.properties: server.servlet.context-path=/demoApp

Instead of putting the properties file in src/main/resources, we can also keep it in the current working directory (outside of the classpath). Java System Property.

http://localhost:8090/demoApp/hello for more info. https://www.baeldung.com/spring-boot-context-path

like image 141
Fany Gómez Avatar answered Apr 14 '26 16:04

Fany Gómez