0
votes

I am running sample spring boot application in spring tool suite tool. After configuring the port I am unable to start application from browser. I am getting 404 Not found error. Spring boot is running properly on tomcat.

application.properties

hello.greeting= nice to see you

server.port=9874

Could some one please help me to correct the problem.

package demo;

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

@SpringBootApplication
public class HelloBootApplication {

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


package demo;

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

@RestController
public class HelloController {

    @Autowired
    HelloProperties props;

    @RequestMapping("/hello")
    public String hello(@RequestParam String name) {
        return props.getGreeting()+name;
    }

}

package demo;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties("hello")
public class HelloProperties {
    private String greeting = "Welcome ";

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }
}

2018-07-22 17:17:32.798  INFO 11824 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-22 17:17:32.952  INFO 11824 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-07-22 17:17:33.000  INFO 11824 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9874 (http) with context path ''
2018-07-22 17:17:33.006  INFO 11824 --- [           main] demo.HelloBootApplication                : Started HelloBootApplication in 2.083 seconds (JVM running for 2.862)

This is spring boot application, getting 404 Not Found on below link http://localhost:9874/

1
without seeing the code how can i give solution to your problem? Please provide the code that causes problemKathirvel Subramanian
try it with localhost:9874/hellogit-flo
You specified only "/hello" context path, so you need to request it localhost:9874/hello instead of just localhost:9874Timur Levadny
I had tried that too, still 404 error is getting localhost:9874/hello Server is running without any errorsMurali krishna
I am thinking, whether I had missed any other configurations.Murali krishna

1 Answers

2
votes

Your url is wrong . You have to call the url with RequestParam name.

use this url http://localhost:9874/hello?name=test