application.yml 3.99 KB
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