把原有的application.properties删掉。然后 maven -X clean install,或者通过Maven Project双击clean和install
(1)端口服务配置

  

#端口,项目上下文根
server:
port: 8080
servlet:
context-path: /hotel

  

其中context-path: /hotel可以不用配置
如果配置,访问路径就是http://ip:port/hotel/
没有配置,访问路径就是http://ip:port/

(2)数据库配置

  

spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: root
jpa:
hibernate:
ddl-auto: update
show-sql: true
redis:
database: 0
host: localhost
port: 6379
password:
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 0

(3)配置多个不同的profile,实现在不同的环境(比如开发、测试和生产环境)使用不同的配置变量。

  

# 默认的profile为dev,其他环境通过指定启动参数使用不同的profile,比如:
# 测试环境:java -jar my-spring-boot.jar --spring.profiles.active=test
# 生产环境:java -jar my-spring-boot.jar --spring.profiles.active=prod
spring:
profiles:
active: dev ---
# 开发环境配置
spring:
profiles: dev
mysql:
ipPort: localhost:3306 ---
# 测试环境配置
spring:
profiles: test
mysql:
ipPort: ip:port ---
# 生产环境配置
spring:
profiles: prod
mysql:
ipPort: ip:port

使用方法:
通过指定启动参数使用不同的profile
测试环境: java -jar my-spring-boot.jar --spring.profiles.active=test
生产环境: java -jar my-spring-boot.jar --spring.profiles.active=prod

(3)指定静态资源路径

 

spring:
resources:
#指定静态资源路径,默认为classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/}

 

(4)热部署
在Springboot+Thymeleaf的开发过程中,默认情况下修改到任何代码都需要重新启动项目才能生效。使用spring.thymeleaf.cache和devtools来解决html热启动的问题
首先在pom.xml中配置

<!--增加maven的devtools依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

注意:true只有设置为true时才会热启动,即当修改了html、css、js等这些静态资源后不用重启项目直接刷新即可。
然后修改application.yml

#热部署--静态资源立即生效
spring:
#热部署--静态资源立即生效
thymeleaf:
cache: false
encoding: UTF-8
mode: LEGACYHTML5
prefix: classpath:/templates/
suffix: .html
check-template-location: true
#热部署生效
devtools:
restart:
enabled: true

  

如果需要在修改java文件后都能自动更新,则需要将原先的maven构建修改。
配置了true后在修改java文件后也就支持了热启动,不过这种方式是属于项目重启(速度比较快的项目重启),会清空session中的值,也就是如果有用户登陆的话,项目重启后需要重新登陆。

<!--maven构建-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!--maven构建-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--如果没有该项配置,devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>

(5)时间配置

spring:
jackson:
#指定日期格式,比如yyyy-MM-dd HH:mm:ss
date-format: yyyy-MM-dd HH:mm:ss
#指定日期格式化时区
time-zone: GMT+8

(6)模板配置
springboot 中自带的页面渲染工具为thymeleaf 还有freemarker 这两种模板引擎 。

<!--freemarker-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

  

spring:
freemarker:
suffix: .html #设定模板的后缀
request-context-attribute: request #request访问request
content-type: text/html
enabled: true
cache: false #缓存配置
template-loader-path: classpath:/templates/ #模板加载路径 按需配置
charset: UTF-8 #编码格式
settings:
number_format: '0.##' #数字格式化,无小数点

(7)redis和shiro配置

<!--redis和shiro-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.3.2</version>
</dependency>
spring:
redis:
database: 0
host: localhost
port: 6379
password:
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
timeout: 0
shiro:
conf:
domain:
cookiePath: /
successUrl: /index
loginView: /login
openToken: false
sessionTimeout: 1800000
algorithmName: md5
hashIterations: 5
#不拦截的路径
sysanon:
- /login
- /regist
#跨域配置
allowedOrigins:
- /**

作者:姜猪猪
来源:CSDN
原文:https://blog.csdn.net/zhulan316917864/article/details/84976234
版权声明:本文为博主原创文章,转载请附上博文链接!

SpringBoot中application.yml基本配置详情的更多相关文章

  1. SpringBoot中 application.yml /application.properties常用配置介绍

    # Tomcat server: tomcat: uri-encoding: UTF-8 max-threads: 1000 min-spare-threads: 30 port: 10444 ser ...

  2. SpringBoot(十):读取application.yml下配置参数信息,java -jar启动时项目修改参数

    读取application.yml下配置参数信息 在application.yml文件内容 my: remote-address: 192.168.1.1 yarn: weburl: http://1 ...

  3. SpringBoot中Application开启与关闭

    0.声明 缘由:没有学过或者没有经历SpringBoot的Application运行机制的话,一定会好奇,博主为啥会写一篇关闭开启的博文,是不是好幼稚?(/o(╥﹏╥)o),待我娓娓道来......为 ...

  4. SpringBoot中使用UEditor基本配置(图文详解)

    SpringBoot中使用UEditor基本配置(图文详解) 2018年03月12日 10:52:32 BigPotR 阅读数:4497   最近因工作需要,在自己研究百度的富文本编辑器UEditor ...

  5. springmvc以及springboot中的拦截器配置

    拦截器两种实现   如果不同的controller中都需要拦截器,不能使用相同的拦截器,因为拦截器不能跨controller,这个时候只能为不同的controller配置不同的拦截器,每一个拦截器只能 ...

  6. springboot获取application.yml中的配置信息

    HelloController.java package com.springbootweb.demo.controller; import com.springbootweb.demo.entity ...

  7. docker-compose如何动态配置springboot项目的application.yml的配置

    假如我们再springboot的工程中有配置文件 方式1: application.properties里面存在环境变量: #配置数据库链接 spring.datasource.url = jdbc: ...

  8. SpringBoot 从application.yml中通过@Value读取不到属性值

    package cn.exrick.xboot.mqtt; import org.eclipse.paho.client.mqttv3.*;import org.eclipse.paho.client ...

  9. Spring Boot中application.yml与bootstrap.yml的区别(转)

    说明:其实yml和properties文件是一样的原理,主要是说明application和bootstrap的加载顺序.且一个项目上要么yml或者properties,二选一的存在. Bootstra ...

随机推荐

  1. 使用@ResponseBody输出JSON

    添加jackson依赖 添加@ResponseBody 测试: 原理: 当一个处理请求的方法标记为@ResponseBody时,就说明该方法需要输出其他视图(json.xml),SpringMVC通过 ...

  2. 简单易用的字符串模糊匹配库Fuzzywuzzy

    简单易用的字符串模糊匹配库Fuzzywuzzy 阅读目录 FuzzyWuzzy 简介 安装 用法 已知移植 FuzzyWuzzy 简介 FuzzyWuzzy 是一个简单易用的模糊字符串匹配工具包.它依 ...

  3. mysoft

    @@a8649fbb56349908b5ca6708fb94b3ddabcf6b97381a9797d3dfb139b8749287117@@##74e02e1207e5a0a8996ba89f1d6 ...

  4. shelve:极其强大的序列化模块

    介绍 数据持久化,就是把数据从内存刷到磁盘上.但是要保证在读取的时候还能恢复到原来的状态.像pickle和json之类的持久化模块基本上无需介绍了,这里介绍两个其他很少用但是功能很强大的模块. dbm ...

  5. kernel module insmod错误

    kernel模块配置 Enable loadable module support 打开可加载模块支持,如果打开它则必须通过"make modules_install"把内核模块安 ...

  6. 为Qtcreator 编译的程序添加管理员权限

    (1)创建资源文件 myapp.rc 1 24 uac.manifest (2)创建文件uac.manifest <?xml version="1.0" encoding=& ...

  7. 转(static final 和final的区别)

    学习java的时候常常会被修饰符搞糊涂,这里总结下static final和final的区别. 1.static 强调只有一份,final 说明是一个常量,final定义的基本类型的值是不可改变的,但 ...

  8. mysql细说show slave status参数详解(最全)

    1. Slave_IO_State 这里显示了当前slave I/O线程的状态(slave连接到master的状态).状态信息和使用show processlist | grep "syst ...

  9. 找到并更改启动时间(timeout)

    centos7更改引导项等待时间 centos7已经不用grub,改用grub2. [ root]# vi /boot/grub2/grub.cfg 找到并更改启动时间(timeout) [root] ...

  10. xpath的编写规则

    xpath的编写规则是// 表示从任意一级开始,或间隔任意级.换句话说中间就是可以隔很多层/ 从根目录开始,或从上一层的次层开始,就是需要跟上一层是上下级关系@id=aaa,id=aaa的元素,和元素 ...