john doe
john doe

Reputation: 9680

Spring Boot Application Tomcat Server not running

I have the following code in my CourseApiApp.java file:

package io.myapp.hellospringboot;

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

@SpringBootApplication
public class CourseApiApp {

    public static void main(String[] args) {

        SpringApplication.run(CourseApiApp.class, args);

    }

}

When I press the play button I see the following console messages:

main] i.a.hellospringboot.CourseApiApp         : Starting CourseApiApp on johndoe-MacBook-Pro.local with PID 22730 (/Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot/target/classes started by john doe in /Users/johndoe/Documents/workspace-sts-3.8.4.RELEASE/com.myapp.hello-spring-boot)
2017-05-02 21:28:29.454  INFO 22730 --- [           main] i.a.hellospringboot.CourseApiApp         : No active profile set, falling back to default profiles: default
2017-05-02 21:28:29.552  INFO 22730 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.838  INFO 22730 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-05-02 21:28:30.917  INFO 22730 --- [           main] i.a.hellospringboot.CourseApiApp         : Started CourseApiApp in 2.122 seconds (JVM running for 2.614)
2017-05-02 21:28:30.919  INFO 22730 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5427c60c: startup date [Tue May 02 21:28:29 CDT 2017]; root of context hierarchy
2017-05-02 21:28:30.920  INFO 22730 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

UPDATE: Here is the POM.xml file:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.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>

And my GreetingController.java file:

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

@RestController
public class GreetingController {

    @RequestMapping("/hello/{name}")
      String hello(@PathVariable String name) {
        return "Hello, " + name + "!";
      }

}

Upvotes: 5

Views: 25844

Answers (5)

Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27255

This almost drove me nuts. Well, looking at @PhilWebb's comment above:

That either means your classpath is wrong (no Tomcat) or you have a property set that's disabling web support.

I had to go back to my Application class and discovered I was doing this:

 public static void main(String[] args) {


        new SpringApplicationBuilder(OasisEstoreManagerApiApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);
    }

I had set the WebApplicationType to NONE

I changed it to WebApplicationType.SERVLET and it worked.

This was after I had tried everything including deleting the .m2 directory.

Hope this helps someone.

Upvotes: 1

Hemant
Hemant

Reputation: 51

Please delete the files in .m2 repository.
Mainly delete the files from the following location:
C:\Users\{UserName}\.m2\repository\org\apache

Again build application by updating the POM file and issue gets resolved.

Upvotes: 3

Jawad K.
Jawad K.

Reputation: 115

I faced the same issue due to corrupt jar files so I decided to use latest spring boot dependencies and its worked fine. All you need to update your POM file and build again.

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.javabrains.springbootquickstart</groupId>
<artifactId>course.api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>springbootapi</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-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

Upvotes: 0

Denis Pavlov
Denis Pavlov

Reputation: 126

You must add a dependency to file pom.xml :

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

Upvotes: 9

Phil Webb
Phil Webb

Reputation: 8642

The root cause was a corrupt jar in the maven cache. Deleting ~/.m2/repository solved the issue.

Another option would have been to run mvn dependency:purge-local-repository

Upvotes: 9

Related Questions