Spring Boot环境的搭建

Spring Boot是一款由Pivotal团队打造的框架,旨在简化Spring应用的搭建及开发流程。它提供了预配置的特性,如内嵌Tomcat、无需部署WAR文件等。本文将介绍Spring Boot的特点、优点,并展示如何搭建一个简单的Spring Boot应用,同时分享了博主收集的常用`application.properties`配置信息,涵盖MVC、资源处理、日志等多个方面。
摘要由CSDN通过智能技术生成

什么是Spring Boot?

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

自己的理解就是spring boot其实不是什么新的框架,它只是默认配置了很多框架的使用方式,就像maven整合了所有的jar包,spring boot整合了所有的框架,需要哪个框架的时候,只需要新建项目的时候勾选相应的框架核心,然后不需要引入额外的Jar包,因为spring boot帮我们做了这件事。

spring boot的特点

  • 创建独立的Spring应用程序
  • 嵌入的Tomcat,无需部署WAR文件,能直接运行程序
  • 简化Maven配置,不需要在pom.xml文件引入过多的jar包
  • 自动配置Spring,不需要新建spring的核心配置文件
  • 提供生产就绪型功能,如指标,健康检查和外部配置
  • 绝对没有代码生成并且对XML也没有配置要求

spring boot的优点

使用spring boot搭建项目,其突出优点就是简单、快速、方便!
平时搭建一个spring web项目的时候可能需要以下步骤:

1.配置web.xml,加载spring核心配置文件和spring mvc的配置文件
2.配置数据库连接、配置spring事务
3.配置加载配置文件的读取,开启注解
4.配置日志文件

配置完成之后部署tomcat 调试

等一系列操作,可能一不小心就漏了哪个步骤,又得重新检查一遍。。。
而spring boot可以帮你解决传统的spring web项目构建的繁琐步骤,一步到位。
说了这么多,接下来一起来学习怎样使用吧。(它可以应用在快速搭建web项目和为服务)

搭建一个简单的Spring Boot

  1. 新建一个全新的project
    springboot2.0以上的版本,jdkz最好选择jdk1.8以上在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
因为需要访问其官网下载初始化的程序,镜像在国外,所以初始化第一个project的时候很慢,以后在此project新建Model就不用加载如此慢。
在这里插入图片描述
2.看一下新建的spring boot的project
在这里插入图片描述
3.测试能否不配置繁琐的spring的各种配置文件,能否访问成功
1)在这里插入图片描述
在此目录下新建controller包,包下新建TestController.java

package com.springboot.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 小思
 * @PackageName:com.springboot.springboot.controller
 * @ClassName: TestController
 * @Description:测试spring boot访问控制器
 * @date 2018/11/18 20:07
 */
@Controller
public class TestController {
   
    @RequestMapping("/hello")
    public String sayHello(){
   
        System.out.println("hello spring boot");
        return "index";
    }
}

2)启动服务器,运行项目
在这里插入图片描述
在这里插入图片描述
环境搭建成功!

在这里插入图片描述

下面是博主搜集的常用的application.properties配置信息

搜集地址:https://blog.csdn.net/je_ge/article/details/54783184

SPRING CONFIG (ConfigFileApplicationListener)

spring.config.name
配置文件名称,默认为application
spring.config.location
配置文件存放位置,默认为classpath目录下

mvc

spring.mvc.async.request-timeout
设定async请求的超时时间,以毫秒为单位,如果没有设置的话,以具体实现的超时时间为准,比如tomcat的servlet3的话是10秒.
spring.mvc.date-format
设定日期的格式,比如dd/MM/yyyy.
spring.mvc.favicon.enabled
是否支持favicon.ico,默认为: true
spring.mvc.ignore-default-model-on-redirect
在重定向时是否忽略默认model的内容,默认为true
spring.mvc.locale
指定使用的Locale.
spring.mvc.message-codes-resolver-format
指定message codes的格式化策略(PREFIX_ERROR_CODE,POSTFIX_ERROR_CODE).
spring.mvc.view.prefix
指定mvc视图的前缀.
spring.mvc.view.suffix
指定mvc视图的后缀.

messages

spring.messages.basename
指定message的basename,多个以逗号分隔,如果不加包名的话,默认从classpath路径开始,默认: messages
spring.messages.cache-seconds
设定加载的资源文件缓存失效时间,-1的话为永不过期,默认为-1
spring.messages.encoding
设定Message bundles的编码,默认: UTF-8

mobile

spring.mobile.devicedelegatingviewresolver.enable-fallback
是否支持fallback的解决方案,默认false
spring.mobile.devicedelegatingviewresolver.enabled
是否开始device view resolver,默认为: false
spring.mobile.devicedelegatingviewresolver.mobile-prefix
设定mobile端视图的前缀,默认为:mobile/
spring.mobile.devicedelegatingviewresolver.mobile-suffix
设定mobile视图的后缀
spring.mobile.devicedelegatingviewresolver.normal-prefix
设定普通设备的视图前缀
spring.mobile.devicedelegatingviewresolver.normal-suffix
设定普通设备视图的后缀
spring.mobile.devicedelegatingviewresolver.tablet-prefix
设定平板设备视图前缀,默认:tablet/
spring.mobile.devicedelegatingviewresolver.tablet-suffix
设定平板设备视图后缀.
spring.mobile.sitepreference.enabled
是否启用SitePreferenceHandler,默认为: true

view

spring.view.prefix
设定mvc视图的前缀.
spring.view.suffix
设定mvc视图的后缀.

resource

spring.resources.add-mappings
是否开启默认的资源处理,默认为true
spring.resources.cache-period
设定资源的缓存时效,以秒为单位.
spring.resources.chain.cache
是否开启缓存,默认为: true
spring.resources.chain.enabled
是否开启资源 handling chain,默认为false
spring.resources.chain.html-application-cache
是否开启h5应用的cache manifest重写,默认为: false
spring.resources.chain.strategy.content.enabled
是否开启内容版本策略,默认为false
spring.resources.chain.strategy.content.paths
指定要应用的版本的路径,多个以逗号分隔,默认为:[/**]
spring.resources.chain.strategy.fixed.enabled
是否开启固定的版本策略,默认为false
spring.resources.chain.strategy.fixed.paths
指定要应用版本策略的路径,多个以逗号分隔
spring.resources.chain.strategy.fixed.version
指定版本策略使用的版本号
spring.resources.static-locations
指定静态资源路径,默认为classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/

multipart

multipart.enabled
是否开启文件上传支持,默认为true
multipart.file-size-threshold
设定文件写入磁盘的阈值,单位为MB或KB,默认为0
multipart.location
指定文件上传路径.
multipart.max-file-size
指定文件大小最大值,默认1MB
multipart.max-request-size
指定每次请求的最大值,默认为10MB

freemarker

spring.freemarker.allow-request-override
指定HttpServletRequest的属性是否可以覆盖controller的model的同名项
spring.freemarker.allow-session-override
指定HttpSession的属性是否可以覆盖controller的model的同名项
spring.freemarker.cache
是否开启template caching.
spring.freemarker.charset
设定Template的编码.
spring.freemarker.check-template-location
是否检查templates路径是否存在.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值