Reputation: 14988
I'm doing these days my first steps with Spring Boot. I used this article https://spring.io/guides/gs/rest-service/#use-maven to build a simple web service.
This is the code I wrote:
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
package com.example;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String sayHi() {
return "Hi";
}
}
I run it by "sprint-boot:run".The code compiles successfully and after a few seconds exits with exit code 1. The error is:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.3.RELEASE:run (default-cli) on project demo: An exception occurred while running. null: InvocationTargetException: Connector configured to listen on port 8080 failed to start -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Upvotes: 0
Views: 1551
Reputation: 17025
The fact that it stops right away indicates that Spring-Boot did not find tomcat in its classpath.
You need to include spring-boot-starter-web
so that tomcat is found, autoconfigured and launched at startup with your application.
So basically, just add:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
The other issue isn't a true problem:
Connector configured to listen on port 8080 failed to start
It's simply caused by another process already using port 8080. To bypass this, add the following in your application.properties
:
server.port=8081
Upvotes: 1