[英]Error for Raising a Web Service using Spring Boot
I'm doing these days my first steps with Spring Boot. 这些天,我正在使用Spring Boot做我的第一步。 I used this article https://spring.io/guides/gs/rest-service/#use-maven to build a simple web service. 我使用本文https://spring.io/guides/gs/rest-service/#use-maven构建了一个简单的Web服务。
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: 我通过“ sprint-boot:run”运行它。代码成功编译,并在几秒钟后退出,退出代码为1。错误为:
[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. [错误]无法在项目演示上执行目标org.springframework.boot:spring-boot-maven-plugin:1.4.3.RELEASE:run(default-cli):运行时发生异常。 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. null:InvocationTargetException:配置为在端口8080上侦听的连接器无法启动-> [帮助1] [ERROR] [ERROR]要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。 [ERROR] Re-run Maven using the -X switch to enable full debug logging. [错误]使用-X开关重新运行Maven以启用完整的调试日志记录。 [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 [错误] [错误]有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The fact that it stops right away indicates that Spring-Boot did not find tomcat in its classpath. 它立即停止的事实表明Spring-Boot在其类路径中未找到tomcat。
You need to include spring-boot-starter-web
so that tomcat is found, autoconfigured and launched at startup with your application. 您需要包括spring-boot-starter-web
以便在启动应用程序时找到,自动配置并启动tomcat。
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 配置为侦听端口8080的连接器无法启动
It's simply caused by another process already using port 8080. To bypass this, add the following in your application.properties
: 这仅是由于已经使用端口8080的另一个进程引起的。要绕过该进程,请在application.properties
添加以下内容:
server.port=8081
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.