手动创建一个Spring Boot 2.x项目
- spring boot 2.1.9版本quick start参考文档地址:https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/html/getting-started-first-application.html#getting-started-first-application-pom 
- 新建一个Maven项目 
- 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);
	}
}
- 直接像运行Java程序那样就可以了,然后在浏览器输入 - 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
从日志信息我们可以知道以下信息:
- 所用Spring Boot的版本为:2.1.9.RELEASE - :: Spring Boot :: (v2.1.9.RELEASE)
- 当前运行的Spring Boot进程PID: - with PID 9320
- 当前应用使用的是内嵌的tomcat,并且运行在8080端口上: - o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
手动创建一个Spring Boot 2.x项目的更多相关文章
- 创建一个 Spring Boot 项目,你会几种方法?
		我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ... 
- 社区版Intelij IDEA快速创建一个spring boot项目(找不到sping Initializer选项)
		首先作为一个初学spring boot的小白,在学习过程中肯定会遇到各种问题... So,问题出现:在我想快速创建spring boot项目时,却在新建列表中找不到sping Initializer这 ... 
- eclipse快速创建一个Spring Boot应用
		1,创建一个空的maven项目 2,添加parent <parent> <groupId>org.springframework.boot</groupId> &l ... 
- spring boot学习01【搭建环境、创建第一个spring boot项目】
		1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ... 
- Spring Boot 多模块项目创建与配置 (一) (转)
		Spring Boot 多模块项目创建与配置 (一) 最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都 ... 
- Spring Boot 多模块项目创建与配置  (一)
		最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都使用spring boot框架.之前有零零散散学过一些 ... 
- Spring Boot 多模块项目创建与配置 (转)
		转载:https://www.cnblogs.com/MaxElephant/p/8205234.html 最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多 ... 
- 快速搭建一个Spring Boot + MyBatis的开发框架
		前言:Spring Boot的自动化配置确实非常强大,为了方便大家把项目迁移到Spring Boot,特意总结了一下如何快速搭建一个Spring Boot + MyBatis的简易文档,下面是简单的步 ... 
- 搭建第一个spring boot项目
		一.开发工具建议使用Spring Tool Suite 下载地址:http://spring.io/tools/sts/all/ 点击versions选择相应的版本下载,解压后直接运行即可. 二.创建 ... 
随机推荐
- node.js ffmpeg-concat 命令行形式处理多个视频的过度效果
			ffmpeg-concat 是利用 gl-transitions 处理多个视频的过度效果.详细说明参见 https://github.com/transitive-bullshit/ffmpeg-co ... 
- Flink组件及特性
			Flink 是一个针对流数据和批数据的分布式处理引擎.它主要是由 Java 代码实现.目前主要还是依靠开源社区的贡献而发展.对 Flink 而言,其所要处理的主要场景就是流数据,批数据只是流数据的一个 ... 
- oracle-不完全数据库恢复-被动恢复-ORA-00313/ORA-00366
			继上一篇不完全恢复 oracle-不完全数据库恢复-被动恢复-ORA-00313/ORA-00366 场景2:数据库拥有备份,CURRENT状态日志组中所有的在线日志头损坏,在发生日志切换时实例被自动 ... 
- QA的工作职责是什么?
			目前不知道,后续一点一点查资料补充吧 QA不管做什么的类型的测试,最基础的功能测试,需要搭建测试环境:进阶部分的性能压力测试,对搭建环境的要求更高:接口功能测试,搭建测试环境,和功能测试的差不多: 测 ... 
- django连接数据库的类型
			字段类型 django的models里面字段类型除了上面的常用的 models.CharField和models.IntegerField,还有更多的类型 1.models.AutoField 自增列 ... 
- shell脚本每隔几秒执行
			while true do cmd(shell 命令) sleep x(x为秒数) done ————————————————版权声明:本文为CSDN博主「这年头起名真难3232」的原创文章,遵循 C ... 
- JAVA日期时间相关库
			Java的日期时间库比较乱,同样一个Date在java.sql下定义,同时也在java.util下也定义了一遍,真不知道SUN是怎么想的. java8以后,java通过jsr310标准引入了一套符合I ... 
- C++中的函数重载分析(一)
			1,重载是 C 语言到 C++ 语言的一个飞跃,C 语言中没有重载的概念,所有的函数 名是不允许有重复的,在 C++ 中因为引进了重载,所以函数名可以重复: 2,自然语言中的上下文: 1,你知道上面词 ... 
- [BZOJ 3992] [SDOI 2015] 序列统计(DP+原根+NTT)
			[BZOJ 3992] [SDOI 2015] 序列统计(DP+原根+NTT) 题面 小C有一个集合S,里面的元素都是小于质数M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数 ... 
- hdu 2586  How far away ? ( 离线 LCA , tarjan )
			How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ... 
