InTheBloodHorse

SpringBoot项目配置

字数统计: 435阅读时长: 2 min
2018/12/16 Share
  1. log日志
    在resources目录下创建 logback-spring.xml文件,内容为
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    <?xml version="1.0" encoding="UTF-8" ?>
    <configuration>
    <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
    <pattern>
    <!--设置输出格式-->
    %d - %msg%n
    </pattern>
    </layout>
    </appender>

    <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
    <level>
    ERROR
    </level>
    <!--如果是ERROR则禁止-->
    <onMatch>DENY</onMatch>
    <!--不是ERROR就接受-->
    <onMismatch>ACCEPT</onMismatch>
    </filter>
    <encoder>
    <pattern>
    %msg%n
    </pattern>
    </encoder>
    <!--滚动策略-->
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <fileNamePattern>
    log/sell/info.%d.log
    </fileNamePattern>
    </rollingPolicy>
    </appender>

    <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    <level>
    ERROR
    </level>
    </filter>
    <encoder>
    <pattern>
    %msg%n
    </pattern>
    </encoder>
    <!--滚动策略-->
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <fileNamePattern>
    log/sell/error.%d.log
    </fileNamePattern>
    </rollingPolicy>
    </appender>
    <!--级别-->
    <root level="info">
    <appender-ref ref="consoleLog"/>
    <appender-ref ref="fileInfoLog"/>
    <appender-ref ref="fileErrorLog"/>
    </root>
    </configuration>

2.Mysql数据库
在application.yml文件添加配置信息

1
2
3
4
5
6
7
8
9
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: xxxx
url: jdbc:mysql://localhost:3306/java_order?characterEncoding=utf-8&useSSL=false
jpa:
show-sql: true
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect

在maven引入响应的jar包

1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

3.lombok(getter,setter)
引入

1
2
3
4
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

原文作者:InTheBloodHorse

原文链接:http://pyking.cn/2018/12/16/SpringBoot项目配置/

发表日期:December 16th 2018, 8:21:23 pm

更新日期:December 16th 2018, 8:30:23 pm

版权声明:Have a fun

CATALOG