봄 부팅 2.1.9 빠른 시작 참조 문서 주소의 버전 : HTTPS : //docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/getting-started-first-application.html#getting- 시작 - 첫 번째 애플리케이션 치어
- 새로운 메이븐 프로젝트를 만듭니다
에서의 pom.xml 파일 가져 오기 의존 증가
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
프로젝트가 필요한 구성 요소 중 일부는 업데이트되지 않습니다있을 수 있으므로 그런 다음 프로젝트에 작은 붉은 십자가가,이 다음과 같이 솔루션입니다 :
// 在项目上右键,选择Maven->Update Project...
// 可以看到小红叉消失了
- 클래스를 쓰기 시작
package com.fei;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by zxf on 2019年10月17日
*/
// @RestController注解是@Controller和@ResponseBody两个注解的组合
@RestController
@EnableAutoConfiguration
public class SpringBootDemoApplication {
/**
* 对外提供一个/服务
* @return
*/
@RequestMapping("/")
public String home() {
return "Hello World!";
}
// Spring Boot应用启动类
public static void main(String[] args) {
SpringApplication.run(SpringBootDemoApplication.class, args);
}
}
브라우저에서 직접 실행 한 다음 입력 자바 프로그램처럼
http://localhost:8080/
볼 수있는 액세스Hello world!
다음과 같은 정보 콘솔 로그 인쇄 할
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.9.RELEASE)
2019-10-17 23:27:00.528 INFO 9320 --- [ main] com.fei.SpringBootDemoApplication : Starting SpringBootDemoApplication on Dell-pc with PID 9320 (E:\Developing\workspace-sts\spring-boot-demo\target\classes started by Dell in E:\Developing\workspace-sts\spring-boot-demo)
2019-10-17 23:27:00.542 INFO 9320 --- [ main] com.fei.SpringBootDemoApplication : No active profile set, falling back to default profiles: default
2019-10-17 23:27:02.268 INFO 9320 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-10-17 23:27:02.348 INFO 9320 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-10-17 23:27:02.352 INFO 9320 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.26]
2019-10-17 23:27:02.568 INFO 9320 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-10-17 23:27:02.568 INFO 9320 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1945 ms
2019-10-17 23:27:02.930 INFO 9320 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-10-17 23:27:03.190 INFO 9320 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-10-17 23:27:03.195 INFO 9320 --- [ main] com.fei.SpringBootDemoApplication : Started SpringBootDemoApplication in 3.371 seconds (JVM running for 5.42)
2019-10-17 23:28:54.760 INFO 9320 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-10-17 23:28:54.761 INFO 9320 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-10-17 23:28:54.771 INFO 9320 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 10 ms
우리는 다음과 같은 정보를 알 수있는 로그의 정보 :
봄 부팅 사용되는 버전은 다음과 같습니다 2.1.9.RELEASE
:: Spring Boot :: (v2.1.9.RELEASE)
- 현재 봄 부트 프로세스의 PID를 실행 :
with PID 9320
포트 8080에 현재 임베디드 바람둥이를 사용하여 응용 프로그램 및 실행 :
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''