springboot - 应用实践(1)认识springboot
1、为什么要推出springboot
springboot设计的目的是用来简化新spring应用的初始搭建以及开发过程。springboot遵循“约定优于配置”原则。
2、springboot默认的配置文件application.properties
3、日志依赖模块spring-boot-starter-logging,自动使用的是logback作为项目的日志框架
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<!--使用log4j2,还需要一些配置,参考logback.xml在application.properties中的应用-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
4、Web开发依赖模块spring-boot-starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
一些约定:
1》项目结构层面的约定
静态文件和页面统一放在src/main/resources对应的子目录下。src/main/resources/static用于放置静态资源文件,如css、js、images等;src/main/resources/templates
目录用于放置页面模板文件,如html、jsp等。
2》springMVC框架层面的约定
spring-boot-starter-web依赖模块默认自动配置一些springMVC必要的组件:
1>将ViewResolver自动注册到spring容器
2>将Converter和Formatter等bean自动注册到spring容器。
3>将对Web请求的支持和相应的类型转换的HttpMessageConverter自动注册到spring容器。
4>将MessageCodesResolver自动注册到spring容器。
3》嵌入式Web容器层面的约定
spring-boot-starter-web依赖模块默认使用嵌入式Tomcat作为Web容器对外提供服务,默认使用8080端口对外监听和提供服务。如果不想使用默认的嵌入式Tomcat,可以引入jetty
或者undertow作为替代方案。
如果不想使用默认的8080端口,可以通过application.properties配置文件中的server.port使用自己制定的端口。如:server.port=8088
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
或者
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
5、修改 maven项目默认创建的项目jre不是用户环境变量中配置的jre
<!--修改maven的settings.xml文件,找到profiles节点-->
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
6、构建springboot应用,设置<parent.../>。
pom.xml必须设置<parent.../>元素设置为springboot的spring-boot-starter-parent,spring-boot-starter-parent是springboot的核心启动器,包含了自动配置(如starter-web的版本选择等)、日志和YAML等大量默认的配置,大大简化了开发工作。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>
springboot - 应用实践(1)认识springboot的更多相关文章
- springboot - 应用实践(3)springboot的核心
1.springboot的启动类与核心注解@SpringBootApplication 2.springboot基本配置 3.springboot自动配置原理
- springboot(十一)-为什么要用springboot
前言 学习了一段时间springboot,一般都可以在项目中使用springboot开发了.因为springboot的东西并不多,或者说,springboot根本就没有新东西. 好了,现在问一句,我们 ...
- SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问
SpringBoot学习(3)-SpringBoot添加支持CORS跨域访问 https://blog.csdn.net/yft_android/article/details/80307672
- SpringBoot自定义错误信息,SpringBoot适配Ajax请求
SpringBoot自定义错误信息,SpringBoot自定义异常处理类, SpringBoot异常结果处理适配页面及Ajax请求, SpringBoot适配Ajax请求 ============== ...
- SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面
SpringBoot自定义错误页面,SpringBoot 404.500错误提示页面 SpringBoot 4xx.html.5xx.html错误提示页面 ====================== ...
- SpringBoot切换Tomcat容器,SpringBoot使用Jetty容器
SpringBoot切换Tomcat容器, SpringBoot修改为Jetty容器, SpringBoot使用undertow容器, SpringBoot使用Jetty容器 ============ ...
- SpringBoot源码分析之SpringBoot的启动过程
SpringBoot源码分析之SpringBoot的启动过程 发表于 2017-04-30 | 分类于 springboot | 0 Comments | 阅读次数 SpringB ...
- springboot项目--传入参数校验-----SpringBoot开发详解(五)--Controller接收参数以及参数校验----https://blog.csdn.net/qq_31001665/article/details/71075743
https://blog.csdn.net/qq_31001665/article/details/71075743 springboot项目--传入参数校验-----SpringBoot开发详解(五 ...
- 【spring-boot 源码解析】spring-boot 依赖管理
关键词:spring-boot 依赖管理.spring-boot-dependencies.spring-boot-parent 问题 maven 工程,依赖管理是非常基本又非常重要的功能,现在的工程 ...
- SpringBoot源码分析之---SpringBoot项目启动类SpringApplication浅析
源码版本说明 本文源码采用版本为SpringBoot 2.1.0BUILD,对应的SpringFramework 5.1.0.RC1 注意:本文只是从整体上梳理流程,不做具体深入分析 SpringBo ...
随机推荐
- fiddler https
fiddler 里面的action 点选remove的那个 手机端清理凭据 在重新添加(在手机浏览器先输入代理的地址 下载证书 之后再安装)
- Python内置类属性
__dict__ : 类的属性(包含一个字典,由类的数据属性组成) __doc__ :类的文档字符串 __name__: 类名 __module__: 类定义所在的模块(类的全名是'__main__. ...
- props 父组件给子组件传递参数
话不多说,直接上代码 父组件: <span><humidity-component ref="soilHumidityBot" :title='title2'&g ...
- [CSP-S模拟测试]:点亮(状压DP+树上背包DP)
题目传送门(内部题121) 输入格式 第一行,一个正整数$n$. 第二行,$n-1$个正整数$p_2,p_3,...,p_n$.保证$p_u$是在$1$到$u-1$中等概率随机选取的. 接下来$n$行 ...
- 详讲KMP算法
两个字符串: 模式串:ababcaba 文本串:ababcabcbababcabacaba KMP算法作用:快速在文本串中匹配到模式串 如果是穷举法的方式: 大家有发现,这样比效率很低的. 所以就需要 ...
- LeetCode 22. 括号生成(Generate Parentheses)
题目描述 给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合. 例如,给出 n =3,生成结果为: [ "((()))", "(() ...
- echart 饼图图例legend支持滑动
ps: 以下针对option操作 文章目录 图例过多加上滚动条图例形状图例自定义显示图例过多加上滚动条 legend:{ top:'50', bottom:'50', type:'scroll',} ...
- Python学习笔记:数据的处理
上次的学习中有个split函数,照着head first Python上敲一遍代码: >>> with open('james.txt') as jaf: data=jaf.read ...
- Docker报错: TLS handshake timeout”。
Docker 默认拉取国外镜像,换成国内就搞定. 为了永久性保留更改,您可以修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值. { &quo ...
- shell初级-----处理用户输入
命令行参数 读取参数 位置参数变量是标准的数字:$0是程序名,$1是第一个参数,$2,是第二个参数,直到第九个参数$9. 特殊的变量:$#表示参数个数,$?表示最后运行的命令的结束代码(返回值) 每个 ...