传统的搭建SpringMVC框架的过程:
1,添加一堆的依赖;
2,在resources目录下添加application.xml配置文件
1,开启注解扫描
2,开启SpringMVC注解驱动支持
3,配置静态资源的处理
4,配置视图解析器
3,在web.xml中配置DispatcherServlet的前端请求分发器。
-------------------------------------------------------
1,创建SpringBoot项目的三种方式:
1,通过IDEA或Eclipse的Spring Initializr创建
2,访问https://start.spring.io创建SpringBoot的骨架
3,自动手动搭建
2,SpringBoot应用的基本结构
pom.xml
src
main
java
DemoApplication
resources
application.properties
templates
static
test
3,创建第一个SpringBoot项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
运行项目在控制台出现图标表示SpringBoot启动成功。
4,关于SpringBoot利用Maven创建项目时,各项目间的引用关系
1,创建父模块,里面只有一个pom.xml,并且打包方式为pom;
parent标签表示继承的父pom文件,在父pom中定义的depedencies标签里的包都直接被子模块自动继承了。
depedencyManagerment标签表示父pom中定义的子模块可引用也可选择不引用的模块,如果子模块需要引用可省略version标签,版本由父模块统一管理。
2,其他的模块采用quickstart方式建立,打包为jar包即可。
5,分析
1,继承spring-boot-stater-parent,引入基本的依赖管理配置(如果是单模块,可以使用SpringBoot自带的parent父模块标签,但是如果实际项目中有公用的父模块依赖,则可以不用此标签模块);
2,引入spring-boot-stater-web,自动引入了springweb(如SpringMVC等)相关的包;
3,@SpringApplication由三个主要的标签构成:@SpringBootConfiguration,@EnableAutoConfiguration,@ComponentScan
1)@SpringBootConfiguration:本质是一个@Configuration,代表这是Spring使用这个标签自动的把内置的符合条件的Configuration类加载进入应用;
2)@EnableAutoConfiguration:开启自动配置,Springboot使用这个标签自动的把内置的符合条件的@Configuration类加载进入应用;
3)@ComponentScan:自动扫描。
4,SpringApplication.run:这个是SpringBoot为我们提供的最大区别,在于springboot不再是一个web应用,不需要我们自己去打包、部署,启动tomcat,Springboot默认
把tomcat打包到应用中,我们可以正常的运行jar的方式来运行SpringBoot应用。
6, SpringBoot中的参数设置
SpringBoot中主要的参数来源及优先级:
1,命令行参数;(在需要传参的地方注入ApplicationArguments,通过applicationArguments.getNonOptionArgs()方法获取到参数,参数值的输入可在项目启动时Edit Configuration-->Program arguments,参数以key-value形式传入)
2,ServletConfig和ServletContext传参;
3,操作系统环境变量;
4,application-{profile}.properties或YAML文件;
5,application.properties或YAML文件;
SpringBoot提供了properties绑定机制,其有如下几种方式来创建properties文件:
1,当前resources目录下的/config子目录;
2,当前resources目录下;
3,classpath项目omp.web根目录下的/config子目录;
4,classpath项目omp.web根目录下;
以上配置文件加载顺序优先级从下至上,如在根目录下直接创建的properties文件设置端口8082,在根目录下config子目录下创建properties文件端口8083,则项目最终端口为8083,因为后者将前者端口覆盖了。
注:相同属性按照优先级覆盖,不同属性则是合并的,比如在根目录下设置了项目跟路径为/crm,则访问时需要输入XXXX:8083/crm/**来进行访问。
7,程序启动时读取banner.txt配置文件:
在resources目录下创建banner.txt文本文件,默认情况下启动程序会直接在控制台输入banner.txt文件内容,控制其不打印出来有两种方式:
1,在application.properties中:spring.main.banner-mode=off
2,在程序启动入口处添加:application.setBannerMode(Banner.Mode.OFF);
8,SpringBoot的热部署:
除了使用JRebel来实现热部署,还可以使用Springboot提供的spring-boot-devtools包来完成SpringBoot应用的热部署
<!--SpringBoot热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>1.5.4.RELEASE</version>
<optional>true</optional>
</dependency>
原理:
SpringBoot热部署采用重启的方式,其中有两个ClassLoader,一个用来监控不变的类(jar)(basicClassLoeader)、一个是监控自己写的类(RestaterClassLoeader)是否有做修改,如果有修改则将之前的废弃掉重新加载,否则不变。
对于static以及templates下面的静态资源在热部署中不会导致服务重启(即控制台不会输出任何日志信息)。
排除资源方式:
spring.devtools.restart.exclude=static/**,templates/**
spring.devtools.restart.additional-exclude=public/**(处理默认配置排除之外的)
spring.devtools.restart.enabled=false(禁用重启策略)
除此之外还可采用triggerfile的重启策略(即只有重新编译+修改trigger.file文件内容两者同时满足时才能重启服务):
spring.devtools.restart.triggerFile=trigger.file(注意:这个文件不要放在default_exclude目录下面)
9,spring-boot-starter-parent简介:
1,包含了常用版本属性;
如果要修改java编译版本,只需要修改pom.xml中<properties>标签里的java.version即可,即:<properties><java.version>1.7</java.version></properties>
2,包含了常用的dependencyManagerment
3,SpringBoot非常优秀的地方在于提供了非常多以spring-boot-starter.*开头的开箱即用的工具包,常见工具包有以下:
spring-boot-starter:核心的工具包,提供了自动配置的支持,日志和YAML配置支持;
spring-boot-starter-activemq:针对快速集成ActiveMQ的工具包;
spring-boot-starter-aop:提供了快速集成SpringAOPen和AspecJ的工具包;
spring-boot-data-redis:提供了快速集成redis与Jedis的工具包;
spring-boot-starter-freemarker:提供了快速集成Freemarker的工具包;
spring-boot-starter-mail:提供了快速集成邮件发送的工具包;
spring-boot-starter-test:提供了对Springboot应用的测试工具包;
spring-boot-starter-web:提供了对web开发的工具包,包括基于springMVC的restful应用开发,内置的tomcat服务器等。
spring-boot-starter-actuator:提供了对生产环境中应用监控的工具包;
spring-boot-starter-logging:提供了对日志的工具包,默认使用Logback;
spring-boot-starter-xxx:SpringBoot中自带的starter(以xxx结尾);xxx-spring-boot-starter:第三方和SpringBoot集成提供的starter;
如:druid-spring-boot-starter(包含druid数据源的原始依赖+自动配置功能的依赖);
10,数据库连接dataSource相关依赖:
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-
没有合适的资源?快使用搜索试试~ 我知道了~
SpringBoot总结升级版
共243个文件
xml:84个
class:71个
java:44个
需积分: 41 13 下载量 69 浏览量
2018-05-01
20:03:39
上传
评论
收藏 275KB RAR 举报
温馨提示
主要为SpringBoot框架内容,包含SpringBoot环境搭建、常用注解、与Mybatis整合创建多数据源的连接+Druid连接池配置、SpringBoot的热部署、SpringBoot整合Freemarker/Servlet组件/文件上传与下载、SpringBoot自定义拦截器以及将拦截器注册到容器中、SpringBoot静态资源加载总结以及统一异常处理方式、SpringBoot自动装配原理、SpringBoot集成PageHelper实现分页功能(完整demo),包含sql插入语句。demo可直接运行
资源推荐
资源详情
资源评论
收起资源包目录
SpringBoot总结升级版 (243个子文件)
CustomerExample$GeneratedCriteria.class 11KB
OrdersExample$GeneratedCriteria.class 9KB
UserExample$GeneratedCriteria.class 9KB
TUserExample$GeneratedCriteria.class 8KB
BookExample$GeneratedCriteria.class 8KB
CustomerExample$Criteria.class 7KB
StudentExample$GeneratedCriteria.class 6KB
CourseExample$GeneratedCriteria.class 6KB
AccountExample$GeneratedCriteria.class 6KB
OrdersExample$Criteria.class 6KB
HelloController.class 6KB
UserExample$Criteria.class 6KB
SCExample$GeneratedCriteria.class 6KB
TUserExample$Criteria.class 5KB
BookExample$Criteria.class 5KB
DataSourceConfig.class 4KB
DataSourceConfig2.class 4KB
App.class 4KB
StudentExample$Criteria.class 3KB
CourseExample$Criteria.class 3KB
AccountExample$Criteria.class 3KB
SCExample$Criteria.class 3KB
FreemarkerController.class 2KB
BookService.class 2KB
CrmApiHttpMessageConverter.class 2KB
AppConfig.class 2KB
CustomerExample$Criterion.class 2KB
StudentExample$Criterion.class 2KB
AccountExample$Criterion.class 2KB
CourseExample$Criterion.class 2KB
OrdersExample$Criterion.class 2KB
TUserExample$Criterion.class 2KB
UserExample$Criterion.class 2KB
BookExample$Criterion.class 2KB
SCExample$Criterion.class 2KB
CustomerExample.class 2KB
StudentExample.class 2KB
AccountExample.class 2KB
CourseExample.class 2KB
OrdersExample.class 2KB
TUserExample.class 2KB
UserExample.class 2KB
BookExample.class 2KB
SCExample.class 2KB
FileUploadController.class 2KB
HelloControllerAdvice.class 2KB
Customer.class 2KB
Orders.class 1KB
User.class 1KB
TestFilter.class 1KB
TUser.class 1KB
Account.class 1KB
Book.class 1KB
UserService.class 1KB
AccountMapper.class 1KB
CustomerMapper.class 992B
StudentMapper.class 982B
UserMapper.class 980B
Student.class 974B
OrdersMapper.class 972B
CourseMapper.class 972B
Course.class 971B
MyInterCepterHandler.class 964B
TUserMapper.class 959B
BookMapper.class 952B
TestServlet.class 869B
TestListener.class 847B
AccountService.class 838B
SCKey.class 797B
SCMapper.class 774B
AppTest.class 475B
trigger.file 0B
trigger.file 0B
index.ftl 1022B
index.ftl 1022B
hello.ftl 155B
hello.ftl 155B
fileUpload.html 303B
fileUpload.html 303B
index4.html 181B
index3.html 181B
index.html 181B
index2.html 181B
404.html 181B
5xx.html 181B
500.html 181B
index4.html 181B
index3.html 181B
index.html 181B
index2.html 181B
404.html 181B
5xx.html 181B
500.html 181B
book.html 152B
test.iml 8KB
CustomerExample.java 16KB
UserExample.java 13KB
OrdersExample.java 13KB
TUserExample.java 12KB
BookExample.java 11KB
共 243 条
- 1
- 2
- 3
资源评论
Loren_云淡风轻
- 粉丝: 1009
- 资源: 46
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功