xiehuanqun 1 месяц назад
Родитель
Сommit
2acf50362f

+ 34 - 5
pom.xml

@@ -46,6 +46,39 @@
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
+        <!-- Redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson</artifactId>
+            <version>3.23.2</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-simple</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <!--<dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-boot-starter</artifactId>
+            <version>3.5.3.2</version>
+        </dependency>-->
+
+        <dependency>
+            <groupId>com.mysql</groupId>
+            <artifactId>mysql-connector-j</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
     </dependencies>
 
     <profiles>
@@ -110,10 +143,6 @@
             </resource>
         </resources>
         <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
 
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -185,4 +214,4 @@
         </repository>
     </repositories>
 
-</project>
+</project>

+ 39 - 0
src/main/resources/application-local.yml

@@ -0,0 +1,39 @@
+server:
+  port: 8080
+
+# 注意:
+# 1. 修改服务器内网IP:ip addr show dev eth0 (一般是 eth0: 172.19.0.7)
+# 2. 修改内置数据库:mysql库 -> user表 -> root用户的 Host 改为 % (默认有不用改)
+# 3. 修改内置Redis conf:bind 172.19.0.7 (重启)
+
+# 是否开启API日志 (true|false)
+API_LOG: true
+
+spring:
+  application:
+    name: test-local
+  config:
+    name: application-local
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://127.0.0.1:3306/daogucms?useUnicode=true&
+      characterEncoding=UTF-8&
+      useJDBCCompliantTimezoneShift=true&
+      useLegacyDatetimeCode=false&
+      serverTimezone=UTC&
+      allowMultiQueries=true&
+      rewriteBatchedStatements=true&
+      useAffectedRows=true
+    username: root
+    password: 123456
+  data:
+    redis:
+      host: 127.0.0.1
+      port: 6388
+      password: 123456
+#    cache:
+#      type: redis
+#      redis:
+#        time-to-live: 10000 # 缓存的默认过期时间(毫秒)(与 @Cacheable 缓存时间关联)
+
+

+ 32 - 0
src/main/resources/application-prod.yml

@@ -0,0 +1,32 @@
+server:
+  port: 8080
+
+# 是否开启API日志 (true|false)
+API_LOG: true
+
+spring:
+  application:
+    name: test-prod
+  config:
+    name: application-prod
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://172.19.0.16:3306/daogucms?useUnicode=true&
+      characterEncoding=UTF-8&
+      useJDBCCompliantTimezoneShift=true&
+      useLegacyDatetimeCode=false&
+      serverTimezone=UTC&
+      allowMultiQueries=true&
+      rewriteBatchedStatements=true&
+      useAffectedRows=true
+    username: root
+    password: e^mxGHsidcg1
+  data:
+    redis:
+      host: 172.19.0.11
+      port: 6388
+      password: j1aK^4A8qdvr
+#    cache:
+#      type: redis
+#      redis:
+#        time-to-live: 10000 # 缓存的默认过期时间(毫秒)(与 @Cacheable 缓存时间关联)

+ 186 - 4
src/main/resources/application.yml

@@ -1,7 +1,189 @@
+spring:
+  # ??????
+  profiles:
+    active: @profile.active@ # local  # local | dev | prod
+  main:
+    banner-mode: off
+    lazy-initialization: true           # ???Bean
+  jackson:
+    date-format: yyyy-MM-dd HH:mm:ss    # ????????????????
+    time-zone: GMT+8                    # ??????,??????,??+8??
+  servlet:
+    multipart:
+      max-file-size: 5GB               # ????????
+      max-request-size: 5GB
+  messages:
+    basename: i18n/locale
+    encoding: UTF-8
+  mvc:
+    async:
+      request-timeout: 600000           # ????????? 60 ?
+    static-path-pattern: /uploads/**
+
+  #      lettuce:
+  #        pool:
+  #          max-active: 20    # ?????????????????8
+  #          max-wait: -1      # ???????????????????-1
+  #          max-idle: 8       # ?????????8
+  #          min-idle: 0       # ?????????0
+
+
+
+  web:
+    resources:
+      static-locations: classpath:/static/
+      # (false) ????????
+      add-mappings: true
+  #      add-mappings: false
+
+  thymeleaf:
+    # ??????
+    enabled: true
+    #????
+    encoding: UTF-8
+    #????
+    prefix: classpath:/templates/
+    # ????
+    suffix: .html
+    #?????? ??????????
+    cache: false
+    # ??? HTML ??
+    mode: HTML
+    # ????
+    servlet:
+      content-type: text/html
+
+
+
+
+
+
+# MyBatis ORM
+#mybatis:
+mybatis-plus:
+  configuration:
+    map-underscore-to-camel-case: false
+    # ???????sql??
+    # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+  global-config:
+    banner: off
+  mapper-locations:
+    - classpath:com/example/mapper/*.xml
+    - classpath:mapper/**/*.xml
+
+# JVM
 server:
-  port: 8080
+  servlet:
+    context-path: /
+    encoding:
+      charset: UTF-8
+  # ?? Gzip ??
+  compression:
+    enabled: true
+    mime-types: text/html,text/xml,text/plain,text/css,application/javascript
+  tomcat:
+    # ?????????
+    relaxed-query-chars: "[,]"
+#    threads:
+#      max: 200
+
+# PageHelper????
+pagehelper:
+  helperDialect: mysql
+  supportMethodsArguments: true
+  params: count=countSql
+  page-size-zero: true
+
+# ??
+logging:
+  #  config: classpath:log4j2.xml
+  level:
+    root: INFO # WARN
+  pattern:
+    console: "%d{yyyy-MM-dd-HH:mm:ss} [%thread] %highlight(%-5level) %logger- %msg%n"
+    file: "%d{yyyy-MM-dd-HH:mm} [%thread] %highlight(%-5level) %logger- %msg%n"
+  logback:
+    rollingpolicy:
+      max-history: 7
+#    name: /Users/mure/MyProject/QuickLaunchSpring/DaoguCms/log/springLog.log
+
+# %d{HH:mm:ss.SSS}????????
+# %thread????????????Web???????????????
+# %-5level????????5????????
+# %logger-??????????
+# %msg??????
+# %n???????
+
+# ??/????? (JWT/OAuth2)
+# com/daogucms/config/Security/filter/JwtAuthenticationFilter.java
+# com/daogucms/config/Security/SecurityConfig.java
+whitelist:
+  static:
+    /,
+    /*.html,
+    /*.ico,
+    /images/**,
+    /uploads/**,
+    /swagger-ui/index.html,
+    /swagger-ui/**,
+    /docs/**,
+    /v3/**
+  jwt:
+    /api/webhook,
+    /api/public/**,
+    /api/v2/public/**,
+    /api/system/auth/**,
+    /api/v2/system/auth/**,
+    /api/b2c/member/auth/**,
+    /api/test/**,
+    /ws/**,
+    /wss/**
+
+
+## ?????? ##
+# HTTP EXCHANGE ????
+# HTTP_EXCHANGE_URI: https://jsonplaceholder.typicode.com
+
+# [??]
+DEFAULT_LANGUAGE: zh
+
+# [??]
+DEFAULT_TIME_ZONE: Asia/Shanghai
+
+# [??] ????? ???? 60 ?
+CAPTCHA_DURATION: 60000
+
+# [??] ?????? Token ???? (86400000?? = 1? = 24??) (?? login.is_remember ??7?)
+#TOKEN_DURATION_SYSTEM: 86400000
+# [??] ?????? Token ???? (604800000?? = 7?)
+TOKEN_DURATION_MEMBER: 604800000
+
+# [??] ????????????????? (??-1???)
+# (????????????????????)
+MAXIMUM_SESSIONS: -1
+
+##??? Actuator
+#management:
+#  # ??????
+#  endpoint:
+#    # ?? shutdown ???????????? false
+#    shutdown:
+#      enabled: true
+#    # ??????
+#    health:
+#      show-details: always
+#  endpoints:
+#    web:
+#      # ????????
+#      exposure:
+#        include: "*"
+#      # ?????? 2.0?????/; 2.0??????/actuator???????????
+#      base-path: /api/system/actuator
 
-spring:
-  application:
-    name: test
 
+## ??????????????
+## (????? GlobalExceptionHandler ?? handleDuplicateKeyException ??)
+#fieldMappings:
+#  username: ???????
+#  nickname: ?????
+#  role_name: ???????

+ 48 - 0
src/main/resources/logback.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<configuration scan="true" scanPeriod="2 seconds">
+
+    <!-- 定义日志文件的存储路径和文件名 -->
+    <property name="LOG_HOME" value="logs"/>
+
+    <!-- 禁止显示初始化调试信息 -->
+    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
+
+    <!-- 文件日志输出 -->
+    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 当前日志文件 -->
+        <file>${LOG_HOME}/daogucms.log</file>
+
+        <!-- 滚动策略:按时间 + 文件大小切分 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!-- 压缩归档文件命名规则 -->
+            <fileNamePattern>${LOG_HOME}/daogucms.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
+            <!-- 单个日志文件大小上限 -->
+            <maxFileSize>5MB</maxFileSize>
+            <!-- 最多保留天数 -->
+            <maxHistory>7</maxHistory>
+            <!-- 限制日志总大小(可选,不写就无限制) -->
+            <totalSizeCap>1GB</totalSizeCap>
+        </rollingPolicy>
+
+        <!-- 日志格式:新版必须用 encoder -->
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>[%d{yyyy-MM-dd HH:mm:ss}][%-5level][%thread] %logger{36} - %msg%n</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+    </appender>
+
+    <!-- 控制台输出 -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+            <pattern>[%green(%d{yyyy-MM-dd HH:mm:ss})][%highlight(%-5level)][%thread] %logger{36} - %msg%n</pattern>
+            <charset>utf-8</charset>
+        </encoder>
+    </appender>
+
+    <!-- 根日志级别 -->
+    <root level="INFO">
+        <appender-ref ref="FILE"/>
+        <appender-ref ref="STDOUT"/>
+    </root>
+
+</configuration>