user1201734
user1201734

Reputation: 21

Rest service is not working on spring boot application

I have created a spring boot application which is working fine but I am not able to get rest service which is clubbed with that application. Please find below code. I am able to access url http://localhost:8080/springbootr/ but not able to access web-service url http://localhost:8080/springbootr/Hello/, getting 404 at the moment of web service calling.

@Configuration
@ComponentScan(basePackages={"controller"})

@SpringBootApplication
public class Application {
    public static void main(String[] args) throws Exception {
         SpringApplication.run(new Object[] { Application.class }, args);
    }
}

@RestController
public class UserController {

    @RequestMapping(value ="/Hello/", method = RequestMethod.GET)
    public String greeting() {
        System.out.println("Achyut");
        return "HEllo";
    }
}

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.yash</groupId>
  <artifactId>springbootr</artifactId>
  <version>0.0.1-SNAPSHOT</version>


  <name>spring-resource</name>
  <description>spring-resource</description>
  <packaging>war</packaging>
  <properties>
     <java.version>1.7</java.version>
  </properties>

  <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>1.2.3.RELEASE</version>
  </parent>
  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
  </dependencies>
</project>

I am new to this application, please help me out.

Upvotes: 2

Views: 9153

Answers (2)

G. Demecki
G. Demecki

Reputation: 10596

You may try a slightly different URL: http://localhost:8080/Hello/. You can also take a look at option spring.data.rest.base-path.

If you fail to make it work, then let start from a working sample app like spring-boot-sample-data-rest available on the GitHub.

Upvotes: 1

DylanSt
DylanSt

Reputation: 29

Firstly u should try different paths http://localhost:8080/Hello/ Secondly I experienced like this issue, my solution is changing (package or param) paths because some versions dont know some params, if u will change in the xml part, It will running(sorry for my language :) )

Upvotes: 0

Related Questions