application.yml
3.99 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
spring:
  application:
    name: product-service
  profiles:
    active: prod
  datasource:
    url: jdbc:postgresql://postgresql-service:5432/ecommerce
    username: ${DB_USERNAME:postgres}
    password: ${DB_PASSWORD:password}
    driver-class-name: org.postgresql.Driver
    # 添加 HikariCP 连接池配置
    hikari:
      connection-timeout: 30000
      maximum-pool-size: 10
      minimum-idle: 2
      idle-timeout: 600000
      max-lifetime: 1800000
      connection-test-query: SELECT 1
  
  jpa:
    hibernate:
      ddl-auto: validate
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
        show_sql: false
        format_sql: true
        jdbc:
          lob:
            non_contextual_creation: true
        # 移除有问题的配置(这些可能不起作用)
        # javax:
        #   persistence:
        #     schema-generation:
        #       database:
        #         action: validate
        # 禁用部分严格的验证
        check_nullability: false
        # 添加性能优化
        jdbc.batch_size: 20
        order_inserts: true
        order_updates: true
  
  # Flyway 配置优化
  flyway:
    enabled: true
    locations: classpath:db/migration
    baseline-on-migrate: true
    validate-on-migrate: true
    clean-disabled: true
    # 生产环境配置
    out-of-order: false
    # 验证规则
    ignore-missing-migrations: true
    ignore-future-migrations: true
    ignore-ignored-migrations: true
    ignore-pending-migrations: true
    # 修复配置
    repair-on-migrate: true
    validate-migration-naming: true
    placeholder-replacement: false
    # 添加基线配置
    baseline-version: 0
    baseline-description: "Base migration"
  
  # 禁用 Spring Boot 的 SQL 初始化
  sql:
    init:
      mode: never
  
  redis:
    host: redis.ecommerce.svc.cluster.local
    port: 6379
    password: ${REDIS_PASSWORD:password}
    timeout: 2000
    lettuce:
      pool:
        max-active: 8
        max-idle: 2
        min-idle: 2
        max-wait: 5000ms  # 改为具体值,避免 -1ms
server:
  port: 8080
  servlet:
    context-path: /api
  # 添加服务器优化配置
  compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
eureka:
  client:
    service-url:
      defaultZone: http://service-registry:8761/eureka/
    register-with-eureka: true
    fetch-registry: true
    # 添加健康检查配置
    healthcheck:
      enabled: true
management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus,flyway
      # 添加管理端点路径
      base-path: /management
  endpoint:
    health:
      show-details: when_authorized  # 生产环境改为 when_authorized
      show-components: when_authorized
      # 添加健康检查组
      group:
        custom:
          include: db,redis,diskSpace
    # Flyway 端点
    flyway:
      enabled: true
    # 指标端点
    metrics:
      enabled: true
logging:
  level:
    com.ecommerce.product: INFO
    org.hibernate.SQL: WARN
    org.hibernate.type.descriptor.sql: WARN  # 减少SQL参数日志
    org.springframework.cache: TRACE
    org.flywaydb: INFO  # 生产环境改为 INFO,避免过多日志
  pattern:
    console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
  # 添加日志文件配置(生产环境推荐)
  file:
    name: /var/log/product-service/application.log
  logback:
    rollingpolicy:
      max-file-size: 10MB
      max-history: 30
springdoc:
  api-docs:
    path: /v3/api-docs
  swagger-ui:
    path: /swagger-ui.html
    operations-sorter: method
    # 生产环境禁用尝试
    enabled: true
# 应用自定义配置
app:
  database:
    lenient-schema-validation: true
    auto-repair-missing-columns: false
  cache:
    # 缓存配置
    product-ttl: 3600      # 1小时
    category-ttl: 7200     # 2小时
    inventory-ttl: 900     # 15分钟
  api:
    # API配置
    default-page-size: 20
    max-page-size: 100