SpringBoot中常见配置配置,MySQL、Redis、MinIO等

SpringBoot中配置

启动端口号

server:
  port: 8501
spring:
  application:
    name: server-manager
  profiles:
    active: dev # 当前使用的配置文件
  servlet:
    multipart:
      max-file-size: 20MB # 最大文件
      max-request-size: 20MB# # 最大请求

数据库相关

MySQL

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://链接地址:3306/数据库名称?characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true
    username: 账号
    password: "密码"

Redis

spring:
  data:
    redis:
      host: 60.204.230.80
      port: 6379

RabbitMq

spring:
  rabbitmq:
    username: root
    password: 123456
    port: 5672
    host: 192.168.2.156
    listener:
      simple:
        prefetch: 1
        acknowledge-mode: none # 默认机制
        retry:
          enabled: true # 开启重试机制
    connection-timeout: 1s # 连接延迟
    template:
      retry:
        enabled: true # 重试
        multiplier: 2 # 重试次数,发消息不会重试
    publisher-confirm-type: correlated # 不建议开启
    publisher-returns: true # 不建议开启

Mybatis

mybatis:
  mapper-locations: classpath:/mapper/*/*.xml # 映射地址
  config-location: classpath:/mybatis-config.xml # 配置地址

其它

Minio

minio:
    endpointUrl: "http://129.211.31.58:9000"
    accessKey: "bunny"
    secretKey: "02120212"
    bucketName: "spzx-bucket"

日志

logback-spring.xml

自定义日志


<configuration>

    <contextName>logbackcontextName>

    
    <property name="log.path" value="D://logs//spzx-manager//logs" />

    
    
    
    
    
    
    <property name="CONSOLE_LOG_PATTERN" value="%yellow(%date{yyyy-MM-dd HH:mm:ss}) %highlight([%-5level]) %green(%logger) %msg%n"/>

    
    <property name="FILE_LOG_PATTERN" value="%date{yyyy-MM-dd HH:mm:ss} [%-5level] %thread %file:%line %logger %msg%n" />

    
    <property name="ENCODING" value="UTF-8" />

    
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFOlevel>
        filter>
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}pattern>
            <charset>${ENCODING}charset>
        encoder>
    appender>

    
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${log.path}//log.logfile>
        <append>trueappend>
        <encoder>
            <pattern>%date{yyyy-MM-dd HH:mm:ss} %msg%npattern>
            <charset>${ENCODING}charset>
        encoder>
    appender>

    
    <springProfile name="dev">
        
        <logger name="com.atguigu" level="INFO" />
        
        <root level="INFO">
            <appender-ref ref="CONSOLE" />
            <appender-ref ref="FILE" />
        root>
    springProfile>

configuration>

mybatis-config.xml


DOCTYPE configuration PUBLIC
        "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        
        <setting name="mapUnderscoreToCamelCase" value="true"/>
        
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    settings>
    <plugins>
        
        <plugin interceptor="com.github.pagehelper.PageInterceptor"/>
    plugins>
configuration>

你可能感兴趣的:(java,spring,boot,后端,java)