一、Spring Boot系列:通过Maven创建第一个项目
1、打开idea选择创建工程
2、创建maven工程,同时选择jdk1.8
注意:不需要勾选其他选项
3、填写项目名称
4、创建好maven项目后,在pom.xml文件中导入Spring Boot需要的jar包
<!-- 指定Spring Boot的版本 2.0.4.RELEASE -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent> <dependencies>
<!-- 导入Spirng Boot web 所需的jar包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
5、创建一个主程序类,用于启动Spring Boot应用
注意:必须注解@SpringBootApplication和一个run方法
/**
* @SpringBootApplication:标注一个主程序类,用来标明这是一个Spring Boot应用
*/
@SpringBootApplication
public class SpringBootApplicationMain {
// Spring应用启动起来
public static void main(String[] args) {
SpringApplication.run(SpringBootApplicationMain.class, args);
}
}
6、编写相关的Controller类
注意:1.相关的类必须和主程序类同一个包下,或者为主程序包的子包下
2. @RestController相当与 @Controller + @ResponseBody 一起使用,表示整个Controller的方法返回值都是json或json对象
@Controller
@ResponseBody
// @RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "HelloController中的hello方法";
}
}
观察源码@RestController实际上就是 @Controller + @ResponseBody
7、运行main方法,在浏览器中访问得到结果
8. Spring Boot 可以简化部署,pom.xml导入一个打包插件
<!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
9、执行打包工程成jar包
10、运行 jar 包
注意:是在jar 包目录下运行 java –jar
注意事项:
1. 选择自动导入(右下角),没由选中,请看下一条
2. 如果没有选中,可以手动自己更新Maven项目(右上角)
3.出现下面错误,上面由提过,Controller存放的路径是需要注意的。
源码
https://files.cnblogs.com/files/jtfr/spring-boot-01-helloworld.zip
一、Spring Boot系列:通过Maven创建第一个项目的更多相关文章
- [Spring Boot 系列] 集成maven和Spring boot的profile功能
由于项目的需要, 今天给spirng boot项目添加了profile功能.再网上搜索了一圈,也没有找到满意的参考资料,其实配置并不难,就是没有一个one stop(一站式)讲解的地方,所以有了写这篇 ...
- [Spring Boot 系列] 集成maven和Spring boot的profile 专题
maven中配置profile节点: <project> .... <profiles> <profile> <!-- 生产环境 --> <id& ...
- 用Maven创建第一个项目
1.在Eclipse左侧的空白处点击鼠标右键,选择:New>Other : 2.选择Maven项目,点击"Next"按钮: 3.保持默认,直接点击“Next”按钮: 4.选择 ...
- Spring Boot系列(三):Spring Boot整合Mybatis源码解析
一.Mybatis回顾 1.MyBatis介绍 Mybatis是一个半ORM框架,它使用简单的 XML 或注解用于配置和原始映射,将接口和Java的POJOs(普通的Java 对象)映射成数据库中的记 ...
- Spring Boot 系列总结
Spring Boot 系列总结 1.SpringBoot自动装配 1.1 Spring装配方式 1.2 Spring @Enable 模块驱动 1.3 Spring 条件装配 2.自动装配正文 2. ...
- spring boot 实战:我们的第一款开源软件
在信息爆炸时代,如何避免持续性信息过剩,使自己变得专注而不是被纷繁的信息所累?每天会看到各种各样的新闻,各种新潮的技术层出不穷,如何筛选出自己所关心的? 各位看官会想,我们是来看开源软件的,你给我扯什 ...
- spring boot系列01--快速构建spring boot项目
最近的项目用spring boot 框架 借此学习了一下 这里做一下总结记录 非常便利的一个框架 它的优缺点我就不在这背书了 想了解的可以自行度娘谷歌 说一下要写什么吧 其实还真不是很清楚,只是想记录 ...
- 国内最全的Spring Boot系列之二
历史文章 <国内最全的Spring Boot系列之一> 视频&交流平台 SpringBoot视频:http://t.cn/R3QepWG Spring Cloud视频:http:/ ...
- Spring Boot系列——Spring Boot如何启动
Spring Boot启动过程 上篇<Spring Boot系列--5分钟构建一个应用>介绍了如何快速创建一个Spring Boot项目并运行.虽然步骤少流程简单,为开发者省去了很多重复 ...
随机推荐
- TFrecords读、写图片文件
参考:https://blog.csdn.net/u014802590/article/details/68495238 参考:https://www.2cto.com/kf/201709/68057 ...
- PHP截取字符串函数,根据dede修改而来
dede中,有一个函数function cn_substr_utf8($str, $length, $start=0) 但测试时,并不如我所想的一样,可能是因为个人使用习惯吧.比如,字符串为数字或字母 ...
- Solr添加文档(XML)
在上一章中,我们学习解释了如何向Solr中添加JSON和.CSV文件格式的数据.在本章中,将演示如何使用XML文档格式在Apache Solr索引中添加数据. 示例数据 假设我们需要使用XML文件格式 ...
- C/C++ | 并查集:用于检查一个图上有没有环
没有环的过程分析: #include<stdio.h> #include<stdlib.h> #include<iostream> #define VERTICE ...
- JS求多个数组的重复数据
今天朋友问了我这个问题:JS求多个数组的重复数据 注: 1.更准确的说是只要多个数组中有两个以上的重复数据,那么这个数据就是我需要的 2.单个数组内的数据不存在重复值(当然如果有的话,你可以去重) 3 ...
- potplayer录制视频包含字幕
用potplayer录制视频,只能保存视频,外挂字幕的视频字幕无法录制进去 在字幕设置里将几个选项更改,即 字幕输出方式改为直接, 渲染方式不要选矢量即可. 如图:
- science_action
w import random import pprint import math import matplotlib.pyplot as plt def gen_random(magnify_=10 ...
- MySQL case when then else end用法
链接:https://blog.csdn.net/konglongaa/article/details/80250253 case具有两种格式,简单case函数和case搜索函数. 1.简单case函 ...
- Ubuntu下apt-get 安装apache2、php、mysql后的默认路径
apache: 采用apt-get 在线安装,安装路径应在/etc/apache2目录下 apache配置文件/etc/apache2/apache2.conf Apache模块路径:/usr/sbi ...
- vue事件的绑定
<!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...