Spring Boot初识(二)

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'

处理:程序跑一次后没有及时关掉
在这里插入图片描述
关调之前跑的

结果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值