Search code examples
javaspring-boottomcat8

tomcat is not starting up when running app


this is pom xml i have main class and one simple controller which returns string as json. i am just running spring boot 2.x by adding below dependency. in console it shows tomcat is started and application is started.but when i am hitting from postman or url in browser it will 404.

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.kd</groupId>
<artifactId>restdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>restdemo</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <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-jersey</artifactId>
    </dependency>

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

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

this is my controller:

package com.kd.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ServiceControllerKd {

  @RequestMapping("/")
  public Hello greeting() {
     System.out.println("hello");
     return new Hello();
  }
}

Solution

  • I have taken your code, built it, ran it and hit the endpoint and have successfully received a response. However, it is difficult to assess what may be causing your issue without the full project.

    I have created an example project using the code you provided here that runs successfully. It may be best to compare this project against your own to attempt to find any inconsistencies.

    https://github.com/michaelmcfadyen/spring-boot-example