Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot App Terminating at Startup

I am trying out a simple spring boot application it always shuts down automatically

 :: Spring Boot ::        (v1.4.1.RELEASE)
2016-10-23 13:05:21.681  INFO 16532 --- [           main] com.example.RestBootApplication          : No active profile set, falling back to default profiles: default
2016-10-23 13:05:21.766  INFO 16532 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.682  INFO 16532 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-10-23 13:05:23.704  INFO 16532 --- [           main] com.example.RestBootApplication          : Started RestBootApplication in 2.632 seconds (JVM running for 5.168)
2016-10-23 13:05:23.705  INFO 16532 --- [       Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6e20b53a: startup date [Sun Oct 23 13:05:21 EDT 2016]; root of context hierarchy
2016-10-23 13:05:23.708  INFO 16532 --- [       Thread-2] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

pom.xml

<?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>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>rest-boot</name>
    <description>Demo project for Spring Boot</description>

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


</project>

Main Class

@SpringBootApplication
public class RestBootApplication {

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

Controller

@Controller
public class HelloController {

    @RequestMapping("/hello")
    String helloWorld(){
        return "helloWorld";
    }

}

Trying to run in spring tool suite. it always stops after starting. I even added "spring-boot-starter-web" after looking at some stackoverflow questions, but still facing the issue.

Please can you someone point out the issue.

like image 746
Umar Avatar asked Oct 23 '16 17:10

Umar


People also ask

How do I fix spring boot application failed to start?

Fixing the Error The simple solution to fix our error would be to annotate our MainEntryPoint class with the @SpringBootApplication annotation. By using this annotation, we tell Spring Boot to auto-configure the necessary beans and register them in the context.

How do you stop the spring application immediately if the system parameter goes wrong?

Use the static exit() method in the SpringApplication class for closing your spring boot application gracefully.

What happens when spring boot app starts?

Spring Boot automatically configures your application based on the dependencies you have added to the project by using @EnableAutoConfiguration annotation. For example, if MySQL database is on your classpath, but you have not configured any database connection, then Spring Boot auto-configures an in-memory database.

How to shut down a Spring Boot application?

To shut down the Spring Boot application, we simply call a POST method like this: In this call, the port represents the actuator port. 3. Close Application Context We can also call the close () method directly using the application context. Let's start with an example of creating a context and closing it:

How do I start a command line application in Spring Boot?

When Spring Boot finds a CommandLineRunner bean in the application context, it will call its run () method after the application has started up and pass in the command-line arguments with which the application has been started. We can now start the application with a command-line parameter like this: java -jar application.jar --foo=bar

Does Spring Boot add templates to your application?

Spring Boot adds them for you. These are just a few examples of the automatic configuration Spring Boot provides. At the same time, Spring Boot does not get in your way. For example, if Thymeleaf is on your path, Spring Boot automatically adds a SpringTemplateEngineto your application context.

What is Spring-Boot-starter-web dependency?

The spring-boot-starter-web dependency is a starter for building web apps, including RESTful applications, using Spring MVC.


2 Answers

In my case just adding following to pom file

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
like image 145
jdev Avatar answered Sep 28 '22 03:09

jdev


Check what exit code you are getting.

If you get "Process finished with exit code 1" means an exception is being thrown. Thus you can put a try catch block around your SpringApplication.run() statement and print out the stack trace.

public static void main(String[] args) {
    try {
        SpringApplication.run(MyApplication.class, args);
    } catch (Exception e) {
        e.printStackTrace(); 
    }
}

Example talen from: https://stackoverflow.com/a/59017774/9531109

like image 42
JaredCS Avatar answered Sep 28 '22 03:09

JaredCS