Issue
I have created a spring boot project using spring initilizer. I use spring-boot-cli version v1.5.3.RELEASE.
I just try to run:
mvn clean install spring-boot:run -e
But my server won't stay running, it is closing automatically. On port 8080 I have no other connection:
2017-04-27 17:19:28.306 INFO 1895 --- [ main] com.example.EmaApplication : Starting EmaApplication on robucslvm03 with PID 1895 (/home/ge/SpringTest/ema/target/classes started by ge in /home/ge/SpringTest/ema)
2017-04-27 17:19:28.308 INFO 1895 --- [ main] com.example.EmaApplication : No active profile set, falling back to default profiles: default
2017-04-27 17:19:28.336 INFO 1895 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6603c38b: startup date [Thu Apr 27 17:19:28 EEST 2017]; root of context hierarchy
2017-04-27 17:19:28.787 INFO 1895 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2017-04-27 17:19:28.795 INFO 1895 --- [ main] com.example.EmaApplication : Started EmaApplication in 0.688 seconds (JVM running for 5.119)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.263 s
[INFO] Finished at: 2017-04-27T17:19:28+03:00
[INFO] Final Memory: 29M/407M
[INFO] ------------------------------------------------------------------------
2017-04-27 17:19:28.919 INFO 1895 --- [ Thread-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6603c38b: startup date [Thu Apr 27 17:19:28 EEST 2017]; root of context hierarchy
2017-04-27 17:19:28.921 INFO 1895 --- [ Thread-2] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
LATER EDIT:
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DemoController {
@RequestMapping(value="/echo")
public String echo(@RequestParam(value="request", defaultValue="Hello!") String request) {
return request;
}
}
Still not working. EDIT: here is the pom file:
<?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>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.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</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>
Solution
I added in the pom file a tomcat dependency and it worked.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Answered By - georgiana_e
Answer Checked By - Pedro (JavaFixing Volunteer)