Spring Boot :Hello World
实现简单功能:
浏览器发送hello请求,服务器接收并处理,响应hello world字符串
实现步骤
- 配置好环境,创建Maven项目
- 编写SpringBoot主程序
package com.springboot.test01.com.springboot.test01;
import java.awt.image.SampleModel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//用来标注一个主程序类,说明这是一个SpringBoot程序
@SpringBootApplication
public class HelloWorldMainApplication {
public static void main(String[] args) {
//Spring 应用启动
SpringApplication.run(HelloWorldMainApplication.class, args);
}
}
- 编写HelloController
package com.springboot.test01.com.springboot.test01;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
//接收来自浏览器的hello请求
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "Hello World!";
}
}
有关修改端口号
端口号占用错误
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.1.RELEASE)
2019-12-25 18:16:42.535 INFO 9604 --- [ main] c.s.t.c.s.t.HelloWorldMainApplication : Starting HelloWorldMainApplication on DESKTOP-1K1JJG0 with PID 9604 (G:\eclilianxi\com.springboot.test01\target\classes started by 10651 in G:\eclilianxi\com.springboot.test01)
2019-12-25 18:16:42.570 INFO 9604 --- [ main] c.s.t.c.s.t.HelloWorldMainApplication : No active profile set, falling back to default profiles: default
2019-12-25 18:16:48.530 INFO 9604 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8070 (http)
2019-12-25 18:16:48.660 INFO 9604 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-12-25 18:16:48.660 INFO 9604 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-12-25 18:16:49.400 INFO 9604 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-12-25 18:16:49.400 INFO 9604 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 6520 ms
2019-12-25 18:16:50.120 INFO 9604 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-12-25 18:16:50.790 INFO 9604 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-12-25 18:16:50.820 INFO 9604 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-25 18:16:50.830 ERROR 9604 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8070 was already in use.
Action:
Identify and stop the process that's listening on port 8070 or configure this application to listen on another port.
2019-12-25 18:16:50.835 INFO 9604 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
处理:程序跑一次后没有及时关掉
关调之前跑的