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 ...
随机推荐
- iview响应式布局
我想说,我要被逼成前端了. 之前没接触过响应式,这两天和另一位前端程序媛小小的研究了下.做了一个小例子,记录一下,方便以后使用. <template> <div> <Ro ...
- Nowcoder 练习赛26 D xor序列 ( 线性基 )
题目链接 题意 : 中文题.点链接 分析 : 对于给定的 X 和 Y 假设存在一个 Z 使得 X (xor) Z = Y 做一个变形 X (xor) Z (xor) Y = 0 X (xor) Y = ...
- python中oepen及fileobject初步整理之划水篇
open选项 参考官方文档,很多东西也没有看懂,将自己理解的部分先整理到这里,以后还是要参阅官方文档的. open (file, mode='r', buffering=-1, encoding=No ...
- EasyPrtSc sec[1.2] 发布!
//HOMETAG #include<bits/stdc++.h> namespace EasilyPrtSc{ //this namespace is for you to be mor ...
- vue-cli中route和router的区别
在使用vue-router的时候经常分不清router和route的区别: 在函数式编程中: this.$router.push('/login') 或者Router.push() 在动态获取路由参数 ...
- JavaWeb_(SSH论坛)_二、框架整合
基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 导入Jar包 导 ...
- x-admin
https://blog.csdn.net/u014793102/article/details/80316335
- CyclicBarrier源码阅读
一种允许多个线程全部等待彼此都到达某个屏障的同步机制 使用 多个线程并发执行同一个CyclicBarrier实例的await方法时,每个线程执行这个方法后,都会被暂停,只有当最后一个线程执行完awai ...
- Shell中的条件测试和循环语句
1.条件测试:test或[ 如果测试结果为真,则该命令的Exit Status为0,如果测试结果为假,则命令的Exit Status为0 运行结果: 带与.或.非的测试命令[ ! EXPR ] : E ...
- 191024DjangoORM之单表操作
一.ORM基础 ORM:object relation mapping 对象关系映射表 1.配置连接MySQL settings.py:将默认配置删除,加入以下配置 DATABASES = { 'de ...