侧边栏壁纸
  • 累计撰写 71 篇文章
  • 累计创建 59 个标签
  • 累计收到 110 条评论

目 录CONTENT

文章目录

SpringBoot相关配置

MinChess
2022-04-15 / 0 评论 / 0 点赞 / 350 阅读 / 686 字 / 正在检测是否收录...

主要针对yml格式的配置文件application.yml进行展示与记录。

常见配置

server:
  port: 8090 #端口号
  servlet:
    context-path: /libmanage  #访问路径localhost:8090/libmanage

spring:
  servlet:
    multipart:
      max-file-size: 3MB #改变上传文件限制
      max-request-size: 100MB
  thymeleaf:
    cache: false  #关闭缓存
    suffix: .html

  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/simplelibrary?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    username: root
    password: root

mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.jiumozhai.pojo

logging:
  level: info
  com.jiumozhai: debug

端口服务配置

server:
  port: 8080   #端口号
  servlet:
    context-path: /main    #项目访问路径

数据库配置

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/ems-thymeleaf?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    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

配置多个不同的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
在配置文件中指定 spring.profiles.active=dev
虚拟机参数
-Dspring.profiles.active=dev

指定静态资源目录

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

时间配置

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

模板配置

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.##'   #数字格式化,无小数点

redis和shiro配置

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:
            - /**

更多内容还得根据实际的需求来,没有找到文档,就是用一点查一点。

0

评论区