Spring Boot acquaintance (b)

Spring Boot :Hello World

Simple function:
The browser sends hello request, the server receives and processes the response string hello world

Implementation steps

  • Configure the environment, create a Maven project
    Here Insert Picture DescriptionHere Insert Picture Description
  • The main program written 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);
}
}

  • Write 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!";
	}
}

About modifying the port number

Reference Bowen
Here Insert Picture Description

Port number occupied by error


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: 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'

Remedy: The program did not run after the first turn off the
Here Insert Picture Description
run before closing the tune of

result

Here Insert Picture Description

Published 73 original articles · won praise 20 · views 4461

Guess you like

Origin blog.csdn.net/lzl980111/article/details/103702925